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

148
Visualizações
Google Sheet, API results add to col 2

I’m trying to use a Google sheet with device Serial numbers in Col A and populate Col B with the device record ID held in our MDM using Google Apps Script and Jamf API.

I’ve got the script getting the ID based of the device Serial in the sheet but can’t figure out how to get it to populate in column B next to the serial number. At the moment it appends the rows below the serial list in Column B (screenshot attached)…feels like I’ve read a 100 websites now and not getting anywhere…any ideas?

function JamfHttpPutRequest() {

    var rows = SpreadsheetApp.openById("MYSHEETID").getSheetByName("Sheet1").getDataRange().getValues(),
      range,
      values_array; 
  
  rows.forEach(function(row, index){

  var serialnumber = rows[index][0];

    var url = "https://MYDOMAIN.jamfcloud.com/JSSResource/computers/serialnumber/" + serialnumber + "";
    var response = UrlFetchApp.fetch(url, {
        "method": "GET",
        "headers": {
            "Authorization": "Basic MYAUTH",
            "Content-Type": "application/xml"
        },
"muteHttpExceptions": true,
        "followRedirects": true,
        "validateHttpsCertificates": true,
        "contentType": "application/xml",

    }).getContentText();

  var document = XmlService.parse(response);
  var entries = document.getRootElement().getChild('general').getChild('id').getValue();

SpreadsheetApp.getActiveSheet().appendRow([null, (entries)]);

// Log items
  Logger.log(serialnumber);
  Logger.log(entries);

})
}

The above does this

Sheet, ID in col B low down

Trying to get it to do this which I copied and pasted in the correct place

Sheets ID next to serial

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

Description

.appendRow() adds a new row after the least row containing data. What you want is getRange() instead as shown below.

Code.gs

function JamfHttpPutRequest() {

  var rows = SpreadsheetApp.openById("MYSHEETID").getSheetByName("Sheet1").getDataRange().getValues(),
      range,
      values_array; 
  
  var entries = [];

  rows.forEach(
    function(row, index){

      var serialnumber = row[0];

      var url = "https://MYDOMAIN.jamfcloud.com/JSSResource/computers/serialnumber/" + serialnumber + "";
      var response = UrlFetchApp.fetch(url, {
          "method": "GET",
          "headers": {
              "Authorization": "Basic MYAUTH",
              "Content-Type": "application/xml"
          },
          "muteHttpExceptions": true,
          "followRedirects": true,
          "validateHttpsCertificates": true,
          "contentType": "application/xml",

        }
      ).getContentText();

      var document = XmlService.parse(response);
      var entry = document.getRootElement().getChild('general').getChild('id').getValue();
      
      // assuming entry is a single value
      entries.push([entry])


      // Log items
      Logger.log(serialnumber);
      Logger.log(entries);

    }
  );

  // put values in row 1 column B
  SpreadsheetApp.getActiveSheet().getRange(1,2,entries.length,1).setValues(entries);

}
about 4 years ago · Juan Pablo Isaza Relatório
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