I'm fetching data from an external API into a Google Sheet and it's working fine. The problem is that I need to make a kind of "loop" to bring the data I need. To exemplify, I put the OrderId at a row and the script brings the status from an API.
It works fine with the first line but what should I change on my script to make it more dynamic? Bring all the data from every row at column 'A'?
Below the piece of the script that inserts the data in the sheet:
function getOrder() {
var sheet = SpreadsheetApp.getActiveSheet()
var order = sheet.getRange(3,1).getValue()
var url = ("https://myendpoint.com/orders/"+order);
try
{
var response = UrlFetchApp.fetch(
url,
{
"headers":{
"Accept":"application/json"
}
}
);
var fact = response.getContentText();
var data = JSON.parse(fact);
Logger.log(data["status"]);
sheet.getRange(3,2).setValue(data["status"]);
}
catch(error)
{
Logger.log(error);
sheet.getRange(3,2).setValue("Error");
}
I'm not a developer so I am struggling to make it work =) Appreciate the help
range(3,2)
? So each value ofdata["status"]
depends of the value in column A for each row? Also, sharing an example of your Sheet would be very helpful. – Jescanellasdata["status"]
depends of the value in column A for each row. Column A I put the orderId (3,1) and the Colunm B I return the result (OrderStatus) that depends on each row.. I think I need to make a kind of loop in the script or something to make it work for the whole column. Here's the sheet: docs.google.com/spreadsheets/d/… Thanks for the help – Renato França