Skip to main content
Question

API command to add user to smart group


Forum|alt.badge.img+1

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.

4 replies

Forum|alt.badge.img+20
  • Employee
  • 77 replies
  • December 8, 2017

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.


Forum|alt.badge.img+9
  • Contributor
  • 162 replies
  • September 24, 2018

@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.


Forum|alt.badge.img+9
  • Contributor
  • 162 replies
  • September 24, 2018

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.


Forum|alt.badge.img+20
  • Employee
  • 77 replies
  • September 24, 2018

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.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings