NightDev Community Forums

Help with API command

Hello. Can someone help me making a command so Nightbot can post the number of people in space right now? I have this link – http://open-notify.org/Open-Notify-API/People-In-Space/ – but I did not manage to make it work… I also wanted Nightbot to post the current speed and altitude of ISS but I could not find any links for it… if anyone could help me…

@C.A

What you can make a command for is limited to what Open Notify has written in their API documentation. If the documentation does not contain information about the speed and altitude of the ISS, then no such Nightbot command to track that information is possible.


The following command response will output the current number of astronauts in space:

$(eval try{a=JSON.parse(`$(urlfetch json http://api.open-notify.org/astros.json)`);`There are ${a.number} people in space right now.`;}catch(e){`Data fetch error!`;})
1 Like

Do you think it’s possible to add the names of the astronauts like that link shows? The bad part is, it has to fit in 200 caracthers for YouTube…

This command response prints the number of astronauts and their names:

$(eval r=`$(urlfetch json http://api.open-notify.org/astros.json)`;$(urlfetch https://pastebin.com/raw/rixYrDjX))
1 Like

Thank you very much! Another question… do you think it’s possible for Nightbot to post only the current ISS speed and altitude? From this link -> https://wheretheiss.at/w/developer

Satellite info endpoint: https://api.wheretheiss.at/v1/satellites/SATELLITE_ID

The response below posts the ISS velocity and altitude in kilometers/hr

$(eval try{a=JSON.parse(`$(urlfetch json https://api.wheretheiss.at/v1/satellites/25544)`);b=a.units;`ISS velocity: ${a.velocity} ${b}/hr | Altitude: ${a.altitude} ${b}`;}catch(e){`Err`;})

Response in miles/hr

$(eval try{a=JSON.parse(`$(urlfetch json https://api.wheretheiss.at/v1/satellites/25544?units=miles)`);b=a.units;`ISS velocity: ${a.velocity} ${b}/hr | Altitude: ${a.altitude} ${b}`;}catch(e){`Err`;})
1 Like

Thank you!!! You’re the best!!!

Roketto, hi again…so we found this page - https://voyager.jpl.nasa.gov/assets/javascripts/distance_data.js – that shows the Voyager 1 and 2 distance from the sun. Do you think it is possibe for Nightbot to pull the info from there? The lines we need to use from that page is “let dist_1_v1” for Voyager1 and “let dist_1_v2” for Voyager2… The idea is for Nightbot to post the current distance for both Voyager. But we don’t know if it’s possibe for Nightbot…

Run the code in that URL as JS then output both Voyager distances:

$(eval try{$(urlfetch json https://voyager.jpl.nasa.gov/assets/javascripts/distance_data.js);`Voyager 1 distance: ${dist_1_v1} | Voyager 2 distance: ${dist_1_v2}`;}catch(e){`Data fetch error!`;})
1 Like

Thank you!!! Again!!

Now the friend helping me to create this is asking if we can format the numbers using .toFixed? And if we can divide them by a billion, like, (dist_v1/1.0e9).toFixed(1)…

It’s just evaluating JavaScript, so toFixed should work.

1 Like

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