How to make multiple HTPPS requests

I’m having trouble making a POST request and then return specific JSON data and then PUT that JSON data to a URL here is my example https://runkit.com/lukejamison/5d376aa340faf600195acce7
also, I would like them to also run every 30 seconds

Hi @lukejamison,

I think you would be greatly benefited from using async/await here. I believe the issue is that since you are using callback form, you can’t sequence these operations. I would use a package like got or node-fetch, which implements the same fetch API as the browser. This way, you can just write something like:

const data = await (await fetch(URL, { method: "POST", ...})).json();

await fetch(URL, { method:"POST", body: JSON.stringify(data) });

You’ll also be able to split those lines into individual cells and have it still work. Hope this helps!

Thanks,

Francisco

Hey @tolmasky

Thanks for the suggestion I will give it a try. any idea on how to have the requests run in the background every 30 seconds? Also how can I return the vale of specific keys in the JSON response

Hey @lukejamison you might consider using an express as a middleware to structure your application code.
You can read more about express here:
https://expressjs.com/

Set up different routes and use a cron job to send HTTP requests to a given route every 30 seconds.
That cron job can exist as a separate service to the main app.

Returning specific keys requires you to know the data structure of the data.
You might need to loop over it, it might be one huge object…read more about how to do this here: https://www.w3schools.com/js/js_json_objects.asp