How I get data from an API and convert to an file.XLSX?

Joined
Aug 27, 2022
Messages
1
Reaction score
0
Thats it, I have to do that but I'm new programing and I'm quite of lost

const xl = require("excel4node");
const wb = new xl.Workbook();
const axios = require("axios");
const fs = require('fs');
// set url as constant
const URL = "https://restcountries.com/v3.1/all";

axios
.get(URL)
.then((response) => {
// const data = JSON.parse(response);
console.log(response);
fs.writeFileSync('countries.json', response);

})

.catch((error) => {
console.log(error);
});
 
Joined
Mar 11, 2022
Messages
227
Reaction score
32
Not with pure JS.
You need something like PHP for that. I don't know what Api ur using (see the documentation of the developers if available) but usually you should be able to read from most apis by PHP call "curl". Google it.

Than you can use PHP to convert the data into a XLS. But you are as far away from what you are trying to do as the sun from our galaxy center. I don't know where to start to help you. I mean the data your API is returning is formated JSON already. But you can't write somethimg with javascript. Read yes, but not write. So you can't create an XLS File with JS. Not possible. PERIOD.

So PHP is your choice. Read a little bit about PHP and curl, try around with it and then come back to the forum (section PHP that time)
 
Joined
Nov 13, 2020
Messages
302
Reaction score
38
"(snip)...as far away (snip)....... as the sun from our galaxy center.
I just love that MeMate!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top