Situation
I have created a Json file with Google Apps Script.
I have set up a trigger to update new information. The URL changes because it is a new save.
I'm loading a Json file from elsewhere, specifying it by URL. When the URL changes, the file cannot be loaded.
Question
I do not want to rewrite the URL.
I want to overwrite and save the file. It would be helpful if you could tell me how to update the json file without changing the URL.
The way to fix the URL and save the json as a new file is also fine. I checked this one and only found information on web apps.
What I tried
I googled in English and Japanese with no favorable results.
CodePudding user response:
I belive it can be done this way:
function update_json() {
var file_ID = '1JLnR-DSZHjD9_VsOUoo30UhpTqPQA_uN'; // ID of your JSON file
var new_conents = `{'a': 'a', 'b': 'b'}`;
var blob = Utilities.newBlob(new_conents);
Drive.Files.update({}, file_ID, blob);
}
Make sure that 'Drive API' service is enabled in Script Editor: