API to fetch the details of the URL

Dear All,

I am totally new to “Postman” and find it quite interesting to test the API via postman .

I am exploring [SWAPI - The Star Wars API]

I am trying to get at least 5 starship names used in Star War Movie “Revenge of the Sith” on the response body.

The API which I passed

gave the response of Revenge of the sith.

The output has starships as a list and it has URL and if you run the url seperately, it will display the name .

Sharing the screenshot of the starships url

The expected output in the response body is just name of starships like “name”: “CR90 corvette”, “name”: “Droid control ship” and so on… by passing an API. Is it possible?

I wrote the below script in Tests:

let jd=pm.response.json()

let cs= jd.results[0].starships[0];

console.log(cs);

As you know it will display only the URL not the name.

Hope I made it clear.

Your input is highly appreciable.

Regards,
Sasi Preetha

Hey @research-saganist-83 :wave:

You could do something like this in the Test tab, once you received the response from the /films endpoints, use pm.sendRequest() to loop through the starships array and extract the names from the responses to the console.

let starships = pm.response.json().results[0].starships;

starships.forEach(function(starship){
    pm.sendRequest(`${starship}`, function (err, res) {
        if(err) { throw err}
        console.log(res.json().name);
    });
});

There are a number of different ways that you can get the name but as this question is quite vague and seems to be part of an assignment - You’re better off just posting the course question to get a more targeting solution.

I would advise taking a closer look at sites like JavaScript Tutorial to get a better understanding of basic Javascript, which will help you when trying to present the data in different ways.

Thank you so much Danny for your help/input/suggestion. Much Appreciated.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.