Skip to content

Instantly share code, notes, and snippets.

@gustavoreis
Last active April 10, 2018 14:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gustavoreis/45bc1c4d3498c10f212c6be4a3b54927 to your computer and use it in GitHub Desktop.
Save gustavoreis/45bc1c4d3498c10f212c6be4a3b54927 to your computer and use it in GitHub Desktop.
Function de Google Spreadsheet que permite listar URLs por SKU.
function testProductUrl() {
var host = "www.domino.com.br";
var username = "USER_API";
var password = "SENHA_API"
//productUrl('34241', host, username, password);
productUrl('17345', host, username, password);
}
function productUrl(sku, host, username, password) {
var url = "https://" + host + "/api/v2/variants/" + String(sku);
var response = UrlFetchApp.fetch(url, { headers: { "Authorization": "Basic " + Utilities.base64Encode(username + ":" + password) }, muteHttpExceptions: true });
var variant = JSON.parse(response);
if(variant.error) {
return variant.error;
}
else {
return "https://" + host + "/produto/" + variant.slug + "-" + String(variant.product_id);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment