I need a quick help with (REST) API integration. I am trying to GET data from SWAPI (Star Wars API) which is an open API and put those data into the system. This is code that I have written so far.
(async () => {
try {
const PlanetDetails = await api.makeRequest({
method: 'GET',
url: 'https://swapi.dev/api/people/1',
});
var Name = PlanetDetails.data.name;
var Vehicle = PlanetDetails.data.vehicle;
var Species = PlanetDetails.data.species;
var EyeColorr = PlanetDetails.data.eye_color;
api.setVariable('Name', Name);
api.setVariable('Vehicle', Vehicle);
api.setVariable('Species', Species);
api.setVariable('EyeColor', EyeColorr);
} catch (error) {
console.log(error)
}
})();
The problem is that I can get only specific person's data using the ID as you can see in the URL. But I want all the planets name into a list. So I wrote the following code:
const PlanetDetails = await api.makeRequest({
method: 'GET',
url: 'https://swapi.dev/api/planets',
});
But I am not sure how do I get the Name (attribute) and put it into a list/array.
Any help will be highly appreciated!
Thanks