HTTPS rest api download using requestPromise

google-assistant
amazon-alexa
cli

#1

I am trying to build a dynamic song list, everyday users get a fresh song list from the server using REST call, and then that list will get updated to a local file, which will use that data for day’s duration. I am not sure if we can override the file, I tried using the below code, while I am able to get rest data with HTTP, HTTPS doesn’t work. Could you please guide me if its a better approach or not and also how to handle HTTPS calls.

async function getSongsList() {
// Do API call and return data
const options = {
    // uri: 'https://drive.google.com/open?id=1t40Kwlcf2iFJ5vNNFDfrOz8jQ_iriR6x',
    // uri: 'http://padmainterior.co.in/tirthankar/songs/songlist.txt',
    uri: 'http://swquotesapi.digitaljedi.dk/api/SWQuote/RandomStarWarsQuoteFromFaction/4',
    json: true // Automatically parses the JSON string in the response
};
const data = await requestPromise(options);
const songdata = data.starWarsQuote;

// fs.writeFileSync("./input/pravchan.json",songdata,{encoding:'utf8',flag:'w'});
try {
    fs.writeFileSync("./input/pravchan.json", songdata)
  } catch (err) {
    console.error(err)
  }  
}
// return quote;

#2

Here’s a tutorial how to make API calls inside a jovo app: https://www.jovo.tech/tutorials/api-call

Btw. Just in case you use AWS Lambda. Please note that you cannot save files in Lambda.


#3

I thought we can’t create new file but you can update existing files? What would be other way to achieve this?