Posted on 12-07-2017 02:59 PM
Good Afternoon,
I am working on a PHP web project to help with integrating users with the correct User Group in Jamf. I can't offhand seem to find the api command to add a user to a specific User Group. Does anyone by chance know the API Command? We are currently running Jamf 10.
Posted on 12-08-2017 09:30 AM
Assuming that you're utilizing a static user group, you can pass XML similar to the following to add users to a static user group:
<user_group>
<user_additions>
<user>
<id>1</id>
<username>Username</username>
</user>
<user>
<id>2</id>
<username>Username2</username>
</user>
</user_additions>
</user_group>
In the example, only one of the <id> or <username> attributes is required to identify the user to add to the group. In terms of the actual command, I'd recommend using a tool like Postman, to generate code samples, after you've verified the inputs for your environment.
Posted on 09-24-2018 08:04 AM
@Sam.Fortuna , do you know the command you would use to apply this to the JSS? I'm trying the following and it's not working:
#!/bin/sh
server="jssurl"
username="apiusername" #JSS username with API privileges
password="apipassword"
staticGroup="ClassGroup"
user=username
#Add to class-specific Static Group
groupData="<user_group><user_additions><user><username>$user</username></user></user_additions></user_group>"
groupOutput=`curl -k -u $username:$password -H "Content-Type: text/xml" https://$server:8443/JSSResource/usergroups/name/$staticGroup -d "$groupData" -X POST`
I've tried both "PUT" and "POST" and neither seems to work. I'm using this same type of commands to add accounts to the JSS and it works fine, I just can't figure out how to use them to add the accounts to a static group.
Posted on 09-24-2018 08:19 AM
Nevermind, I managed to get it working. My problem was that the Static Group was in a different Site than the user account, and I also switched from POST to PUT.
Posted on 09-24-2018 08:39 AM
Glad to see you were able to resolve the issue. To provide some additional clarification, the "user_additions" attribute can only be used for PUT operations since the POST operation would be creating a new group, and the concept of adding a user to a group that doesn't yet exist wouldn't make sense.