Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

83
Visualizações
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
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda