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

143
Views
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 answers
Answer question

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 Report
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!