Last active
April 10, 2018 14:50
-
-
Save gustavoreis/45bc1c4d3498c10f212c6be4a3b54927 to your computer and use it in GitHub Desktop.
Function de Google Spreadsheet que permite listar URLs por SKU.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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