Computer PreStage and API

RagingKoala
New Contributor

Hi everyone,

Have you ever tried to update a PreStage Enrollment through the v2 API?
I'm trying to create a python script that will update the customPackageIds of said PreStage Enrollment when certain packages have a new version available.

This always gives me error 500, internal server error, I think.

It would be something like this:

import requests
payload = {
  "customPackageIds": "110"
}
headers = {
    'Accept': 'application/json',
    'Authorization': 'Bearer XYZ',
    'Content-Type': 'application/json',
}
response = requests.put('https://XYZ/api/v2/computer-prestages/3', json=payload, headers=headers)

This is my first time doing something like that with python and JSON and I would gladly use python-jss for this but as far as I know it can't handle PreStage Enrollments.

What's your take on this?

1 ACCEPTED SOLUTION

SamF
Contributor II
Contributor II

The payload you're using will need to include all information about your prestage, not just the information you want to update. PUT will replace all existing fields, meaning that any undefined fields will be nullified (if allowed by the server). A sample request body can be found on the Jamf Developer Portal

In addition to requiring additional fields, this endpoint requires the use of optimistic locking, via the versionLock element(s). To successfully perform an update (PUT) for an existing resource, you will need to first obtain the current versionLock value, and include that in the request body for your update request. This prevents multiple requests from being processed simultaneously for the same resource, which is important for prestages, because Jamf Pro also needs to communicate these changes to Apple via a separate API, requiring a longer turnaround time than most API requests.

View solution in original post

9 REPLIES 9

SamF
Contributor II
Contributor II

The payload you're using will need to include all information about your prestage, not just the information you want to update. PUT will replace all existing fields, meaning that any undefined fields will be nullified (if allowed by the server). A sample request body can be found on the Jamf Developer Portal

In addition to requiring additional fields, this endpoint requires the use of optimistic locking, via the versionLock element(s). To successfully perform an update (PUT) for an existing resource, you will need to first obtain the current versionLock value, and include that in the request body for your update request. This prevents multiple requests from being processed simultaneously for the same resource, which is important for prestages, because Jamf Pro also needs to communicate these changes to Apple via a separate API, requiring a longer turnaround time than most API requests.

flyingdutchsys
New Contributor II

hi @SamF can optimistic locking be turned off?

No.

flyingdutchsys
New Contributor II
Can it be better documented? what uses version lock what doesnt?

If there's additional information beyond what's documented here that you're seeking, please clarify what additional information you require.

flyingdutchsys
New Contributor II
That will do it.
on developer.jamf.com <> when i searched for optimistic locking it only gave me back 2 results, none of which was as useful as that.

RagingKoala
New Contributor

Thanks for the reply, I look that over and give it a go tomorrow!

RagingKoala
New Contributor

Huge thanks @Sam.Fortuna !!

In the end I decided that before I try to update anything I make a GET and pull the JSON of the PreStage Enrollment into a variable. I modified what I wanted there and then PUT it back.

It worked that way.

Thanks again!

Hi RagingKoala
We have a big reorganisation of PreStage Enrollments on our hand too. Any chance you could share your code? Would be splendid! Many thanx in advance.