Creating and Populating Values
Begin interacting with extension attributes in a programatic manner
Overview
Now that we understand what extension attributes are and how they function within Jamf Pro, let's take a look at how you can leverage them in your integration. Although extension attributes are supported for both the computer and mobile device platforms, we'll address them separately, as there are different API endpoints for each device type.
Computer Extension Attributes
Extension attributes can be created via the Jamf Pro web interface as well as the Classic API. For more information on the UI workflow, please see the Jamf Pro Administrator's Guide.
The API Reference includes more comprehensive documentation on the supported parameters available, however we'll provide a sample request body here for demonstration purposes. By POSTing the following request body to the /computerextensionattributes/id/0
endpoint, we will create a new extension attribute that can store our data.
<computer_extension_attribute>
<name>Extension Attribute Name</name>
<enabled>true</enabled>
<description>This is a sample extension attribute</description>
<data_type>String</data_type>
<input_type>
<type>Text Field</type>
</input_type>
<inventory_display>General</inventory_display>
<recon_display>Extension Attributes</recon_display>
</computer_extension_attribute>
A successful response will include the id
of the newly created extension attribute, which will be required to populate data within the inventory record of each device.
Now that we've created a place holder for data to reside, we'll input data on a per-device basis. For consistency purposes, we'll use the PUT /computers/id/{id}
endpoint in the Classic API, however the PATCH /v1/computers-inventory-details/{id}
endpoint within the Jamf Pro API also supports the ability to update extension attribute values.
Use a request body similar to the one below with the Classic API to update the extension attribute value for the specified computer. To mass update devices, iterate through the list of computer IDs via the path parameter. Unique values can be provided to each device.
Notice
The
id
included in the request body must match theid
from the response we received when creating the extension attribute.
<computer>
<extension_attributes>
<extension_attribute>
<id>1</id>
<value>Updated Value 1</value>
</extension_attribute>
</extension_attributes>
</computer>
Mobile Device Extension Attributes
The same workflow described in Computer Extension Attributes can be utilized for mobile devices, using different endpoints and request bodies. Begin by creating the extension attribute using a request body similar to the one below and POSTing it to /mobiledeviceextensionattributes/id/0
.
<mobile_device_extension_attribute>
<name>Extension Attribute Name</name>
<description>This is a sample extension attribute</description>
<date_type>String</date_type>
<input_type>
<type>Text Field</type>
</input_type>
<inventory_display>General</inventory_display>
</mobile_device_extension_attribute>
A successful response will include the id
of the newly created extension attribute, which will be required to populate values for each device record.
To populate values on a per-device basis, use the PUT /mobiledevices/id/{id}
endpoint. A request body similar to the one below can be used to update the value on the specified device.
Notice
The
id
included in the request body must match theid
from the response we received when creating the extension attribute.
<mobile_device>
<extension_attributes>
<extension_attribute>
<id>1</id>
<value>Updated Value 1</value>
</extension_attribute>
</extension_attributes>
</mobile_device>
Best Practices
Create an extension attribute for each data point you plan to store. The logic available for parsing data stored within extension attributes is not very extensive and large sets of data are best stored in a 1-to-1 manner similar to key/value pairs.
Use the id
of the extension attribute rather than the name when populating information on a per-device basis. While the use of names is a supported mechanism for identifying the extension attribute value you wish to update, names of extension attributes can be changed, while the id
remains static.
Extension attributes support multiple different input types, however when values are set exclusively via the API, Text Field
is generally the most appropriate.
Updated about 2 months ago