Add groups memberships with API REST2

Hi,

I want to automatize the task to add new staff members as queue manager. I think to use REST2 API for that task.

First, i need to give the privileged right to the new user.
It’s easy, this curl command did the job (change the privileged value to 0 or 1 for give/remove the privileged right):
curl -X PUT -H “Content-Type: application/json” -d ‘{ “Privileged” = “1” }’ -H ‘Authorization: token 123456789’ -d " ‘https://mycorp.com/REST/2.0/users/joe

Now the hard part is to give this same user the memberships to the staff group. I’m stuck to an error about JSON request an ARRAY:

curl -X PUT -H “Content-Type: application/json” -d ‘{ “Memberships”:[{“id”:“3867”,“type”:“group”,“_url”:“https://mycorp.com/REST/2.0/group/3867”}] }’ -H ‘Authorization: token 123456789’ ‘https://mycorp.com/REST/2.0/user/joe/groups/

Error: {“message”:“JSON object must be a ARRAY”}

I dont know what i did wrong. Any advice?

My instance is on RT 5.0.4 with PostgreSQL 13 on Debian 11.

Kind regards,

Self answer, i havent clearly read the documentation :

PUT /group/:id/members add members to a group; provide a JSON array of principal ids
PUT /user/:name/groups add a user to groups; provide a JSON array of groups ids

First give privileged right to a user because i want give them the right to manage a queue:
curl -X PUT -H “Content-Type: application/json” -d ‘{ “Privileged” : “1” }’ -H ‘Authorization: token 123456789’ ‘https://mycorp.org/REST/2.0/user/joe

Then add my user joe to the group. Their is 2 way( I need to know the id of user or id of the group first).
I this exemple my user “joe” id is 898 and my group id is 3867.

First way:
curl -X PUT -H “Content-Type: application/json” -d ‘[“3867”]’ -H ‘Authorization: token 123456789’ ‘https://mycorp.org/REST/2.0/user/joe/groups

Second way:
curl -X PUT -H “Content-Type: application/json” -d ‘[“898”]’ -H ‘Authorization: token 123456789’ ‘https://mycorp.org/REST/2.0/group/3867/members

1 Like