I want to make a POST request that returns json data and then i want to get some keys values and then create a json string and then PUT that json sting to a url. And ideally would like this to happen every 30s. I have some code set up here https://runkit.com/lukejamison/5d2dfbf99644eb0013c64a56
var GeoJSON = require("geojson");
const stringify = require("json-stringify-pretty-compact");
var apikey = process.env.xapikey;
var options = {
method: 'POST',
url: 'https://app.detrack.com/api/v1/vehicles/view/all.json',
headers: {
'x-api-key': apikey,
}
};
exports.endpoint = function(httpRequest, response) {
if (!apikey){
return response.end('"xapikey" key is missing.');
}
request(options, function (error, httpResponse, body){
try{
var jsonresponse = JSON.parse(body)
var lat1 = jsonresponse.vehicles[0].lat
var lng1 = jsonresponse.vehicles[0].lng
response.end(stringify({ geometry: { type: "Point", coordinates: [lng1, lat1]}, type: "Feature", properties:{}}));
}catch(ex){
response.end(ex.toString());
}
});
}
Considering you use-case, Perform PUT request synchronously/asynchronously after the successful response from the POST request.