Home > Blockchain >  Printing API response to column
Printing API response to column

Time:01-04

I am working on a function that will make an API call then print the response to the next column in the row for each row in the sheet. For example, I have the two variables in columns A and B, the call is made using those variables, and I want the response to that call in column C until no more rows are left.

I am having problems with printing that response to each column for each row. Right now I have it printing the newest response in C2. I need those responses to be in their correct row. Below is the function I have written.

function trust() {
    var rows = SpreadsheetApp.getActiveSheet().getDataRange().getValues();
    rows.forEach(function(rows, index) {
        if (index !== 0) {
            var link = rows[0];
            console.log(link);
            var shard = rows[1];
      //var error = rows[2]
            console.log(shard);
            //Building API Call
            var url = String(link).concat("/api/v1/accounts/self/trust_links")
            console.log(url)
            var data = {
                "trust_link[managing_account_id]":shard,
            };
      console.log(data)
            var options = {
                "method": "post",
        'muteHttpExceptions' : true,
                "headers": {
                    "Authorization": ''
                },
                'payload': data,
            };
            console.log(options);
            //API Call
            var response = UrlFetchApp.fetch(url, options);
            Logger.log(response);
      //Print each API response to Column C
      SpreadsheetApp.getActiveSheet().getRange("C2").setValue(response)
        }
    });
}

Any insight would be greatly appreciated!

CodePudding user response:

Try this:

SpreadsheetApp.getActiveSheet().getRange(index 1, 3).setValue(response)

  •  Tags:  
  • Related