Posted on 05-02-2022 05:12 AM
Hi,
I was wondering if anyone else out there has run into this issue. We are trying to automate the management of "classes" in jamf pro. We can create a class via the API, but we cannot add a user group to the teacher group or student group of a class (or even a user account to the class) via the API. The API seems to be incomplete and only supports adding shared iPad devices to a class (according to the documentation).
It is strange, as the functionality is there in the GUI.
if anyone else has had any success with this i'd love to know.
Thanks!
Elliot
Solved! Go to Solution.
Posted on 05-03-2022 07:57 AM
Hey Elliot,
Reading your comment made me check my comment and code again. It looks like I mistyped in my XML example and missed the <id> tag - '<class><student_group_ids><id>443</id></student_group_ids></class>'. I see you are also missing that in your example, which is likely the reason you're having trouble.
When I remove the <id> tag and only have the group ID itself (like both of our initial XML examples), I get a 201 response just like you see, and I also see no changes in the class - which makes sense since the tagging isn't formatted correctly.
-William
Posted on 05-02-2022 06:42 AM
Hey Elliot,
I have had success adding a teacher group ID as <class><teacher_group_ids>$exampleID</teacher_group_ids></class>. To modify a student group, it is similar - you should just need to swap teacher_group_ids for student_group_ids: <class><student_group_ids>$exampleID</student_group_ids><class>.
-William
Posted on 05-03-2022 03:28 AM
Hi William,
i'm not having much luck. The API call appears to work and doesn't throw any errors but when you look in the WebUI nothing has changed.
Here's my code. (i'm using powershell)
xml = "<class><student_group_ids>443</student_group_ids></class>"
$headers=@{}
$headers.Add("Accept", "application/json")
$headers.Add("Content-Type", "application/xml")
$headers.Add("Authorization", $tokenAuth)
Invoke-RestMethod -Uri "https://$JamfTennantId/JSSResource/classes/id/$classID" -Method PUT -Headers $headers -Body $xml
The Terminal Response for an Invoke-RestMethod is:
xml class
--- -----
version="1.0" encoding="UTF-8" class
The Terminal Response for an Invoke-WebRequest is:
StatusCode : 201
StatusDescription : Created
Content : <?xml version="1.0" encoding="UTF-8"?><class><id>441</id></class>
RawContent : HTTP/1.1 201 Created
Date: Tue, 03 May 2022 10:13:39 GMT
Transfer-Encoding: chunked
Connection: keep-alive
Set-Cookie: AWSALB=oJNqvjCX5r0o38lkvMLHbQYby52G6BBj9JU+Fyvq2FA/v0hPkOG253BATYMEs+7zYPeIPgaBCt…
Headers : {[Date, System.String[]], [Transfer-Encoding, System.String[]], [Connection, System.String[]], [Set-Cookie, System.String[]]…}
Images : {}
InputFields : {}
Links : {}
RawContentLength : 65
RelationLink : {}
Would you be willing to share your working code?
Thanks,
Elliot
Posted on 05-03-2022 07:57 AM
Hey Elliot,
Reading your comment made me check my comment and code again. It looks like I mistyped in my XML example and missed the <id> tag - '<class><student_group_ids><id>443</id></student_group_ids></class>'. I see you are also missing that in your example, which is likely the reason you're having trouble.
When I remove the <id> tag and only have the group ID itself (like both of our initial XML examples), I get a 201 response just like you see, and I also see no changes in the class - which makes sense since the tagging isn't formatted correctly.
-William
Posted on 05-03-2022 05:08 PM
Hi William,
Thanks for that, the missing id tag did the trick. Thankyou so much.
Posted on 05-03-2022 03:49 AM
Hi William,
Just in case it matters, I thought i'd just clarify that we're using jamf cloud which is running the latest version 10.37.2.
Thanks,
Elliot