Some problems with API - PUT user in groups
-
Why 2 different ways for the same thing?
- https://my.example.com/api/v1/groups/{groupId}/members
2.https://my.example.com/api/v1/users/{userId}/groups
..but both are not working. I tried all: normal arrays, nested arrays, array with 2 members. Error messages:
- "missing or invalid userIds fields"
- "API call requires a groups array."
Example:
{
"groupIds": [
"gidXXXXXXXXX"
]
}Maybe the API documentation is wrong?
- https://my.example.com/api/v1/groups/{groupId}/members
-
@brainsailer Try something like this:
curl 'https://my.example.com/api/v1/groups/{groupId}/members' -X PUT -H 'Authorization: Bearer xx' -H 'Content-Type: application/json' -d '{"userIds":["uid-19953f08-c020-46a1-84ef-75e0274e6c1e"]}'
Alternately:
curl 'https://my.smartserver.io/api/v1/users/{userId}/groups' -X PUT -H 'Authorization: Bearer xxxx' -H 'Content-Type: application/json' -d '{"groupIds":["gid-3e96c503-d30f-4db8-aa37-ecaf98fa33fa"]}'
-
@brainsailer said in Some problems with API - PUT user in groups:
Why 2 different ways for the same thing?
Initially, there was only a way to assign members to groups. So, we had the simple
/api/v1/groups/{groupId}/members
. Later, people wanted to add a specific user to one or more groups i.e via the groups dropdown in the user edit dialog. Accomplishing this with the/api/v1/groups/{groupId}/members
route is complicated. We have to go into each group, get members of each group and set the members of each group. One has to also do this for the groups in which the user is removed.So, to simplify the frontend (and also for correctness since this has to be done in a single transaction), we added a new route
/api/v1/users/{userId}/groups
. -
@brainsailer said in Some problems with API - PUT user in groups:
"missing or invalid userIds fields"
"API call requires a groups array."BTW, these both seems like you are not setting the content-type as json when sending the request.
-
@girish said in Some problems with API - PUT user in groups:
{"groupIds":["gid-3e96c503-d30f-4db8-aa37-ecaf98fa33fa"]}
Thank you, works fine. It was a spelling-error in the "content-type" .
-
-