Jamf Connect Information through API

Lakshmana
New Contributor II

Hi Team,

 

I am trying to get the JAMF Connect information through Google App Script there is an issue is there to get the information into the Google Sheet.I want the same into the Power Automate to get only the JAMF connect -Display Name.

 

Appscript for your reference

 

function fetchJamfComputersData() {
  var sheetName = "JamfComputers"; 
  var sheet = getOrCreateSheet(sheetName);
  
  if (!sheet) {
    Logger.log("Failed to access or create the sheet.");
    return;
  }

  var jamfProUrl = "https://URL/JSSResource/computers/subset/basic";
  var jamfConnectUrl = "https://URL/JSSResource/jamfConnectDirectoryBindings";
  
  var headers = {
    "Authorization": "Bearer Token_Information",
    "Accept": "application/json"
  };

  try {
    var jamfProData = fetchData(jamfProUrl, headers);
    var jamfConnectData = fetchData(jamfConnectUrl, headers);
    
    var computers = jamfProData.computers;
    if (computers && computers.length > 0) {
      var output = [];
      output.push(["ID", "Name", "Managed", "Username", "Model", "Mac Address", "Serial Number", "Report Date (UTC)", "Report Date (Epoch)", "Jamf Connect Display Name"]);
      
      for (var i = 0; i < computers.length; i++) {
        var computer = computers[i];
        var jamfConnectInfo = findJamfConnectInfo(jamfConnectData, computer.id);
        output.push([
          computer.id, 
          computer.name, 
          computer.managed, 
          computer.username, 
          computer.model, 
          computer.mac_address, 
          computer.serial_number, 
          computer.report_date_utc, 
          computer.report_date_epoch,
          jamfConnectInfo.display_name
        ]);
      }
      sheet.getRange(1, 1, output.length, output[0].length).setValues(output);
    } else {
      Logger.log("No computer data found.");
    }
  } catch (error) {
    Logger.log("Error occurred:", error);
  }
}

function fetchData(url, headers) {
  var options = {
    "method": "GET",
    "headers": headers
  };
  var response = UrlFetchApp.fetch(url, options);
  return JSON.parse(response.getContentText());
}

function findJamfConnectInfo(jamfConnectData, computerId) {
  for (var i = 0; i < jamfConnectData.length; i++) {
    if (jamfConnectData[i].computer.id === computerId) {
      return jamfConnectData[i];
    }
  }
  return { display_name: "No Jamf Connect info found" };
}


function getOrCreateSheet(sheetName) {
  var spreadsheetUrl = "Google_Sheet_ID"; // Replace with the full URL of the desired 
  var spreadsheet;
  
  try {
    spreadsheet = SpreadsheetApp.openByUrl(spreadsheetUrl);
  } catch (error) {
    Logger.log("Error accessing the spreadsheet: " + error);
    return null;
  }
  
  var sheet = spreadsheet.getSheetByName(sheetName);
  if (!sheet) {
    sheet = spreadsheet.insertSheet(sheetName);
  }
  return sheet;
}

 

Error I am getting

6:25:07 PM	Notice	Execution started
6:25:08 PM	Info	Error occurred:
6:25:08 PM	Notice	Execution completed
4 REPLIES 4

stevewood
Honored Contributor II
Honored Contributor II

Not sure where you're getting that API endpoint for Jamf Connect: 

https://URL/JSSResource/jamfConnectDirectoryBindings

There is no API endpoint that I am aware of for Jamf Connect. You can get documentation on the APIs available from developer.jamf.com. That's probably your main problem.

Lakshmana
New Contributor II

Got the link from ChatGPT.Referred the develper.jamf.com but the document does not have one. But i need to extract that information through API how to get that ? 

 

JAMF Connect - Display Name is my requirement to be got for every devices

stevewood
Honored Contributor II
Honored Contributor II

The way that I would tackle this is to get the Jamf Connect Display Name onto the computer record in Jamf Pro as an Extension Attribute. There is an Extension Attribute Template named Jamf Connect Display Name that you can add to Jamf Pro through the Settings -> Computer Management -> Extension Attributes section.

Once you have the EA in place, you could either read the value via the API, or you can setup an Advanced Search to pull back just that EA and the computer name (or serial or whatever you want) and then send that as a CSV file wherever you want. Docs for setting it up are here.

Lakshmana
New Contributor II

I found a workaround to get this information 

udid method and then use that udid to get the Extension Attributes working on it