HomeGuidesRecipesAPI ReferenceChangelog
Guides

Code Samples

Below are some code samples for common use cases to help get you started integrating with Jamf Pro's Classic API

Replace YOUR_JAMF_PRO_URL with the correct URL of your Jamf Pro instance and YOUR_CREDENTIALS with the Base64 encoded username and password of an appropriate user account. The credentials should be colon delimited (e.g. username:password).

printf "username:password" | iconv -t ISO-8859-1 | base64 -i -

Get Inventory Information from a Single Computer

The following code samples demonstrate how to retrieve inventory information for a single computer using the ID of the computer.

curl -X GET \
    https://YOUR_JAMF_PRO_URL/JSSResource/computers/id/8 \
    --header 'authorization: Basic YOUR_CREDENTIALS'
import http.client

conn = http.client.HTTPSConnection("YOUR_JAMF_PRO_URL")

headers = {
    'authorization': "Basic YOUR_CREDENTIALS"
}

conn.request("GET", "/JSSResource/computers/id/8", headers=headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
require 'net/http'

uri = URI 'YOUR_JAMF_PRO_URL'
conn = Net::HTTP.new uri.host, uri.port
conn.use_ssl = true

res =  conn.get '/JSSResource/computers/id/8', authorization:  'Basic YOUR_CREDENTIALS'

puts res.body

Deploy (Scope) an App to a Mobile Device

The following code samples demonstrate how to deploy (scope) a mobile device application to a single mobile device using the ID of the mobile device.

curl -X PUT \
    https://YOUR_JAMF_PRO_URL/JSSResource/mobiledeviceapplications/id/7 \
    --header 'content-type: application/xml' \
    --header 'authorization: Basic YOUR_CREDENTIALS' \
    --data '<mobile_device_application>
                <scope>
                    <mobile_devices>
                        <mobile_device>
                            <id>2</id>
                        </mobile_device>
                    </mobile_devices>
                </scope>
            </mobile_device_application>'
import http.client

conn = http.client.HTTPSConnection("YOUR_JAMF_PRO_URL")

payload = "<mobile_device_application><scope><mobile_devices><mobile_device><id>2</id></mobile_device></mobile_devices></scope></mobile_device_application>"

headers = {
    'content-type': "application/xml",
    'authorization': "Basic YOUR_CREDENTIALS"
                    }

conn.request("PUT", "/JSSResource/mobiledeviceapplications/id/7", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
require 'net/http'

uri = URI 'YOUR_JAMF_PRO_URL'
conn = Net::HTTP.new uri.host, uri.port
conn.use_ssl = true

req = Net::HTTP::Put.new(uri + '/JSSResource/mobiledeviceapplications/id/7', authorization:  'Basic YOUR_CREDENTIALS')
req.content_type = 'application/xml'

req.body = '<mobile_device_application><scope><mobile_devices><mobile_device><id>2</id></mobile_device></mobile_devices></scope></mobile_device_application>'

res = conn.request req

puts res.body

Deploy (Scope) an App to a Computer

The following code samples demonstrate how to deploy (scope) an app to an individual computer by updating the scope of an existing policy using the ID of the computer.

curl -X PUT \
    https://YOUR_JAMF_PRO_URL/JSSResource/policies/id/15 \
    --header 'authorization: Basic YOUR_CREDENTIALS' \
    --header 'content-type: application/xml' \
    --data '<policy>
                <scope>
                    <computers>
                        <computer>
                            <id>9</id>
                        </computer>
                    </computers>
                </scope>
            </policy>'
import http.client

conn = http.client.HTTPSConnection("YOUR_JAMF_PRO_URL")

payload = "<policy><scope><computers><computer><id>9</id></computer></computers></scope></policy>"

headers = {
    'content-type': "application/xml",
    'authorization': "Basic YOUR_CREDENTIALS"
}

conn.request("PUT", "/JSSResource/policies/id/15", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
require 'net/http'

uri = URI 'YOUR_JAMF_PRO_URL'
conn = Net::HTTP.new uri.host, uri.port
conn.use_ssl = true

req = Net::HTTP::Put.new(uri + '/JSSResource/policies/id/15', authorization:  'Basic YOUR_CREDENTIALS')
req.content_type = 'application/xml'

req.body = '<policy><scope><computers><computer><id>9</id></computer></computers></scope></policy>'

res = conn.request req

puts res.body

Issue Remote Command to a Computer

The following code samples demonstrate how to issue a remote command to a single computer.

curl -X POST \
    https://YOUR_JAMF_PRO_URL/JSSResource/computercommands/command/DeviceLock \
    --header 'authorization: Basic YOUR_CREDENTIALS' \
    --header 'content-type: application/xml' \
    --data '<computer_command>
        <general>
            <command>DeviceLock</command>
            <passcode>123456</passcode>
        </general>
        <computers>
            <computer>
                <id>8</id>
            </computer>
        </computers>
    </computer_command>'
import http.client

conn = http.client.HTTPSConnection("YOUR_JAMF_PRO_URL")

payload = "<computer_command><general><command>DeviceLock</command><passcode>123456</passcode></general><computers><computer><id>8</id></computer></computers></computer_command>"

headers = {
    'content-type': "application/xml",
    'authorization': "Basic YOUR_CREDENTIALS"
    }

conn.request("POST", "/JSSResource/computercommands/command/DeviceLock", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
require 'net/http'

uri = URI 'YOUR_JAMF_PRO_URL'
conn = Net::HTTP.new uri.host, uri.port
conn.use_ssl = true

req = Net::HTTP::Post.new(uri + '/JSSResource/computercommands/command/DeviceLock', authorization:  'Basic YOUR_CREDENTIALS')
req.content_type = 'application/xml'

req.body = '<computer_command><general><command>DeviceLock</command><passcode>123456</passcode></general><computers><computer><id>8</id></computer></computers></computer_command>'

res = conn.request req

puts res.body

Issue Remote Command to a Mobile Device

The following code samples demonstrate how to issue a remote command to a single mobile device.

curl -X POST \
    https://YOUR_JAMF_PRO_URL/JSSResource/mobiledevicecommands/command \
    --header 'authorization: Basic YOUR_CREDENTIALS' \
    --header 'content-type: application/xml' \
    --data '<mobile_device_command>
        <general>
            <command>DeviceLock</command>
        </general>
        <mobile_devices>
            <mobile_device>
                <id>2</id>
            </mobile_device>
        </mobile_devices>
    </mobile_device_command>'
import http.client

conn = http.client.HTTPSConnection("YOUR_JAMF_PRO_URL")

payload = "<mobile_device_command><general><command>DeviceLock</command></general><mobile_devices><mobile_device><id>2</id></mobile_device></mobile_devices></mobile_device_command>"

headers = {
    'content-type': "application/xml",
    'authorization': "Basic YOUR_CREDENTIALS"
}

conn.request("POST", "/JSSResource/mobiledevicecommands/command", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
require 'net/http'

uri = URI 'YOUR_JAMF_PRO_URL'
conn = Net::HTTP.new uri.host, uri.port
conn.use_ssl = true

req = Net::HTTP::Post.new(uri + '/JSSResource/mobiledevicecommands/command', authorization:  'Basic YOUR_CREDENTIALS')
req.content_type = 'application/xml'

req.body = '<mobile_device_command><general><command>DeviceLock</command></general><mobile_devices><mobile_device><id>2</id></mobile_device></mobile_devices></mobile_device_command>'

res = conn.request req

puts res.body

Update the Value of a Computer Extension Attribute on a Single Computer

The following code samples demonstrate how to update the value of a computer extension attribute on a single computer.

curl -X PUT \
https://YOUR_JAMF_PRO_URL/JSSResource/computers/id/8 \
    --header 'authorization: Basic YOUR_CREDENTIALS' \
    --header 'content-type: application/xml' \
    --data '<computer>
        <extension_attributes>
            <extension_attribute>
                <id>1</id>
                <value>TEST2</value>
            </extension_attribute>
        </extension_attributes>
    </computer>'
import http.client

conn = http.client.HTTPSConnection("YOUR_JAMF_PRO_URL")

payload = "<computer><extension_attributes><extension_attribute><id>1</id><value>TEST2</value></extension_attribute></extension_attributes></computer>"

headers = {
    'content-type': "application/xml",
    'authorization': "Basic YOUR_CREDENTIALS"
}

conn.request("PUT", "/JSSResource/computers/id/8", payload, headers)

res = conn.getresponse()
data = res.read()

print(data.decode("utf-8"))
require 'net/http'

uri = URI 'YOUR_JAMF_PRO_URL'
conn = Net::HTTP.new uri.host, uri.port
conn.use_ssl = true

req = Net::HTTP::Put.new(uri + '/JSSResource/computers/id/8', authorization:  'Basic YOUR_CREDENTIALS')
req.content_type = 'application/xml'

req.body = '<computer><extension_attributes><extension_attribute><id>1</id><value>TEST2</value></extension_attribute></extension_attributes></computer>'

res = conn.request req

puts res.body