Skip to content

Instantly share code, notes, and snippets.

@siliconvallaeys
Created November 8, 2018 16:37
Show Gist options
  • Save siliconvallaeys/a0778e13e3c066a9fc9027060dcc25c2 to your computer and use it in GitHub Desktop.
Save siliconvallaeys/a0778e13e3c066a9fc9027060dcc25c2 to your computer and use it in GitHub Desktop.
Write JSON data to a public store for saving state about a Bing Ads Script automation - for example to create virtual 'labels'
function main() {
// Enter your own URL here - get it from http://myjson.com
var MyJsonBin = 'https://api.myjson.com/bins/l46me';
// This is the object you will store for use the next time the script runs
var dataToStore = {};
dataToStore.lastKeywordProcessed = "some keyword";
dataToStore.someOtherThingToTrack = "the other thing's ID is 123456";
var options = {
method:"put",
payload:JSON.stringify(dataToStore),
contentType:"application/json",
};
var response = UrlFetchApp.fetch(MyJsonBin, options);
var responseText = response.getContentText();
var responseCode = response.getResponseCode();
Logger.log(responseText + " (" + responseCode + ")");
return;
var tokens = JSON.parse(response.getContentText());
var uri = tokens['uri'];
for(var key in tokens) {
var val = tokens[key];
Logger.log(key + " " + val);
}
Logger.log(uri);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment