Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi everyone,
I've been trying in vain to get this to work. It seems to be an invalid Patch request so maybe its something to do with my data structure.
I have a custom group I wish to assign to a user or remove it... I'm using an API gen key against my user (who created the custom group)
code to add is
print('The group is NOT assigned to the user so add it')
data = {"op":"add","path":"/assignedGroups","value":{"name":"Qlik Sense API"}}
response = requests.patch(f'{tenant_url}{api_version}users/{user["id"]}', headers=headers, data=data)
Code to remove is:
print('The group is assigned to the user so remove it')
data = {"op":"remove-value","path":"/assignedGroups","value":{"id":"690b6a286b0920b29e3eeb03"}}
response = requests.patch(f'{tenant_url}{api_version}users/{user["id"]}', headers=headers, data=data)
I get a 400 Bad Request error: {"traceId":"3f466c9de279b0e31caab10f0524ab14","errors":[{"code":"IDENTITIES-00017","detail":"invalid request body","status":400,"title":"Bad Request"}]}
I've tried changing the data to be a string, list, string within a list, etc but no luck
Anyone solved this problem?
Let's create a dummy user:
POST /api/v1/users
{
"name": "User Group Adjustment",
"email": "user.group@corp.example",
"subject": "1234asdasa6781231239"
}
From here, we can add a user to a _custom_ group:
PATCH /api/v1/users/692dba4bccd2c3757641e9df
[
{
"op": "add",
"path": "/assignedGroups/-",
"value": "684adfb0adbd8a0c6443bde4"
}
]
As a side note, we can use names as well if we're using custom groups:
PATCH /api/v1/users/692dba4bccd2c3757641e9df
[
{
"op": "replace",
"path": "/assignedGroups",
"value": [
{
"name": "Example2",
"providerType": "custom"
}
]
}
]
We can remove a _custom_ group assignment:
PATCH /api/v1/users/692dba4bccd2c3757641e9df
[
{
"op": "remove-value",
"path": "/assignedGroups",
"value": "684af6cf1c69d94a9e90ef90"
}
]
I reference _custom_ groups very intentionally, if a user is assigned an _idp_ group then you will need to take a different approach. Rather than using the add operator to append, you will need to build the array of _existing_ groups and use the replace operator. Like so:
PATCH /api/v1/users/Rq6ftmNArJRHHyaWnFaCx5U7p8adVdUU
[
{
"op": "replace",
"path": "/assignedGroups",
"value": [
{
"id": "60b0fce6e585231c5e8aa755"
},
{
"id": "60c7c5d74ed18c7b7f6ee173"
},
{
"id": "684adfb0adbd8a0c6443bde4"
}
]
}
]
Let's create a dummy user:
POST /api/v1/users
{
"name": "User Group Adjustment",
"email": "user.group@corp.example",
"subject": "1234asdasa6781231239"
}
From here, we can add a user to a _custom_ group:
PATCH /api/v1/users/692dba4bccd2c3757641e9df
[
{
"op": "add",
"path": "/assignedGroups/-",
"value": "684adfb0adbd8a0c6443bde4"
}
]
As a side note, we can use names as well if we're using custom groups:
PATCH /api/v1/users/692dba4bccd2c3757641e9df
[
{
"op": "replace",
"path": "/assignedGroups",
"value": [
{
"name": "Example2",
"providerType": "custom"
}
]
}
]
We can remove a _custom_ group assignment:
PATCH /api/v1/users/692dba4bccd2c3757641e9df
[
{
"op": "remove-value",
"path": "/assignedGroups",
"value": "684af6cf1c69d94a9e90ef90"
}
]
I reference _custom_ groups very intentionally, if a user is assigned an _idp_ group then you will need to take a different approach. Rather than using the add operator to append, you will need to build the array of _existing_ groups and use the replace operator. Like so:
PATCH /api/v1/users/Rq6ftmNArJRHHyaWnFaCx5U7p8adVdUU
[
{
"op": "replace",
"path": "/assignedGroups",
"value": [
{
"id": "60b0fce6e585231c5e8aa755"
},
{
"id": "60c7c5d74ed18c7b7f6ee173"
},
{
"id": "684adfb0adbd8a0c6443bde4"
}
]
}
]
thanks again @Levi_Turner ! it works.. I see you're a Qlik employee.. Not sure if this is your area although on the documentation (https://qlik.dev/apis/rest/users/#patch-api-v1-users-userId) the data seems to be written in a different format: Is this out of date?
I do not have a say on the docs but can forward to someone who does!
Thanks very much... I think it may help someone having a similar issue.