J
J
Jeka S2021-03-12 12:00:34
API
Jeka S, 2021-03-12 12:00:34

Postman how to pass parameters correctly?

There is an API: https://api.nasa.gov
Using: Postman
Need to:
1. Find which cameras were used and how many pictures were taken by the Curiosity rover in sol 1666
2. Find a picture with id 268034 taken by the Opportunity rover with a panoramic camera on the first sol
Prompt How to correctly pass parameters to get the desired result?
In the 1st variant, everything seems to be clear, but I don’t know how to write the parameters to calculate the total number of shots, in sol 1666, they get enough sleep in a list with different id

spoiler
604b2f7ad39f7204424864.jpeg
.
In the 2nd option, I don’t understand how to register the id of a specific image
spoiler
604b2f894f45b943217113.jpeg
.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-03-12
@Amaz1nque

Do you want the number returned directly in the query? I don't think there is such a thing. Can be counted as a script from Tests

https://api.nasa.gov/mars-photos/api/v1/rovers/curiosity/photos?sol=1666&api_key=DEMO_KEY

const responseJson = pm.response.json();
var cameras = [];
responseJson["photos"].forEach(function (photo) {
    var name = photo["camera"]["name"];
    if (!cameras.includes(name)) {
        cameras.push(name);
    }
});

console.log("Total photos:", responseJson["photos"].length);
console.log("Cameras:", cameras);

Console:
604b32b1a9278408619438.jpeg
Or you can take the mission manifest and find the sol of interest there
https://api.nasa.gov/mars-photos/api/v1/manifests/Curiosity?api_key=DEMO_KEY

Script:
const responseJson = pm.response.json();
const sol = 1666;
responseJson["photo_manifest"]["photos"].forEach(function(photo) {
    if (photo["sol"] == sol) {
        console.log(photo);
        return
    }
})

Console:
604b345e598ae154087076.jpeg
Find a picture with id 268034 taken by the Opportunity rover with a panoramic camera on the first sol

The same in essence, Tests:
const responseJson = pm.response.json();
const photoId = 268034;
responseJson["photos"].forEach(function(photo) {
    if (photo["id"] == photoId) {
        console.log(photo);
        return
    }
})

Console:
604b35985dd63750279676.jpeg

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question