Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

82
Views
Google Apps Script get Sheet row data to create URL API call then loop to next row

I'm trying to use data in a Google Sheet to create API calls. I have a Google Sheet with two columns of data. Computer serial numbers in col 1 and their corresponding asset tag number in col 2.

I'm trying to read both these values to form a URL API call.

I've managed to get this to work with specific cells but I don't know how to make this loop through the whole sheet row by row.

The script gets the sheet by ID and name (Sheet1). Selects data in A2 and B2 and these as the serial and the assettag Then we build the API call adding in the serial and asset tag.

function HttpPutRequest() {

    var sheet = SpreadsheetApp.openById("xxxxxxxxxxxxxxxxxxxx").getSheetByName("Sheet1"),
      range,
      values_array; 

  serial = sheet.getRange('A2:A2');
  serialnumber = serial.getValues();

  asset = sheet.getRange('B2:B2');
  assettag = asset.getValues();

    const url = "https://MyURLAPICall/serialnumber/" + serialnumber + "";
    const response = UrlFetchApp.fetch(url, {
        "method": "PUT",
        "headers": {
            "Authorization": "Basic",
            "Content-Type": "application/xml"
        },
        "contentType": "application/xml",
        "payload": "<computer><general><asset_tag>" + assettag + "</asset_tag></general></computer>"
    });
  
  Logger.log(serialnumber);
  Logger.log(assettag);
  Logger.log(url);
    Logger.log("Response code is %s", response.getResponseCode());
    Logger.log(response.getContentText());
}

This works fine for a single row of data in row 2 col 1 and col 2 but how could it then move down to row 3, col 1 & col 2, then row 4 etc etc.

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!