Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us in Toronto Sept 9th for Qlik's AI Reality Tour! Register Now
cancel
Showing results for 
Search instead for 
Did you mean: 
mhurley
Partner - Contributor
Partner - Contributor

QRS API: Updating a user's Custom Property values

Hello,

I have been working with the Qlik Sense Repository API and making API calls using Postman. Currently, I am trying to make an API call that will update a user's Custom Property values. For example, if a user has Custom Property "UserAppAccess" which allows them to see an app, and they already have "App 1" as a value assigned to them through UserAppAccess, I need an API call that can add "App 2" and "App 3" to the CP as well, so that they can see all 3 apps.

I have tried different kinds of requests, but the most success I've had was using a PUT call following a GET call, where the GET call gets the existing custom properties and their values based on a user id, and then the PUT call essentially copies the entire body of the GET call, changes the modifiedDate of the assigned CP to the user (in this case, the date when UserAppAccess was assigned to user) to the current time, copies and pastes the body for the CP values (body for App 1) and then changes the value to App 2, or App 3 etc. and lastly, changes the "id" of the body so that its a different random id. Clearly, this process is not ideal as it relies on randomizing the id of the CP value, and may potentially have conflict with other ids in the env (CPs, Users, Apps etc,?). 

Are there any alternative methods, maybe with PATCH or otherwise, which avoids having to deal with ids and can successfully update a user's assigned Custom Property values? Ideally, it could directly access a CP without dealing with dates, ids etc. and can simply add/remove a CP value.

For reference I am using certificate authentication to a Qlik Sense Enterprise server where I'm RootAdmin.

(Example below of the body for a user's CP where one value, App 1, is assigned. Info anonymized.)

{
    "id": "73b349f0-an1b-4f9f-a233-ef14br4361f4",
    "createdDate": "2024-04-15T18:38:41.905Z",
    "modifiedDate": "2024-05-09T15:33:16.282Z",
    "modifiedByUserName": "UserDir\\UserId",
    "customProperties": [
        {
            "id": "579b33b9-f9cd-471l-a9f9-5f51de903855",
            "createdDate": "2024-05-09T15:18:51.308Z",
            "modifiedDate": "2024-05-09T15:31:16.282Z",
            "modifiedByUserName": "UserDir\\UserId",
            "value": "App 1",
            "definition": {
                "id": "a495a6b1-d351-43b6-b995-a524652d63a3",
                "name": "UserAppAccess",
                "valueType": "Text",
                "choiceValues": [
                    "App 1",
                    "App 2",
                    "App 3"
                ],
                "privileges": null
            },
            "schemaPath": "CustomPropertyValue"
        }
    ],
    "userId": "UserId",
    "userDirectory": "UserDir",
    "userDirectoryConnectorName": "",
    "name": "UserId",
    "roles": [
        "RootAdmin"
    ],
    "attributes": [],
    "inactive": false,
    "removedExternally": false,
    "blacklisted": false,
    "deleteProhibited": false,
    "tags": [],
    "favorites": [],
    "privileges": null,
    "schemaPath": "User"
Labels (2)
1 Solution

Accepted Solutions
Marc
Employee
Employee

Get the CustomPropertyDefinition Condensed 

Get the User

Create a New Custom Property Value which requires one of the Custom Property Definitions Choice values, and the Definition.

{
    "value": "App 2",
    "definition": {
        "id": "a495a6b1-d351-43b6-b995-a524652d63a3",
        "name": "UserAppAccess",
        "valueType": "Text",
        "choiceValues": [
            "App 1",
            "App 2",
            "App 3"
        ]
    }
}

 

You need to add new custom property values to the customproperty array on the user.

then pass the updated user to the Update api 

e.g. put: qrs/user/73b349f0-an1b-4f9f-a233-ef14br4361f4 with the body

 
{
    "id": "73b349f0-an1b-4f9f-a233-ef14br4361f4",
    "createdDate": "2024-04-15T18:38:41.905Z",
    "modifiedDate": "2024-05-09T15:33:16.282Z",
    "modifiedByUserName": "UserDir\\UserId",
    "customProperties": [
        {
            "id": "579b33b9-f9cd-471l-a9f9-5f51de903855",
            "createdDate": "2024-05-09T15:18:51.308Z",
            "modifiedDate": "2024-05-09T15:31:16.282Z",
            "modifiedByUserName": "UserDir\\UserId",
            "value": "App 1",
            "definition": {
                "id": "a495a6b1-d351-43b6-b995-a524652d63a3",
                "name": "UserAppAccess",
                "valueType": "Text",
                "choiceValues": [
                    "App 1",
                    "App 2",
                    "App 3"
                ],
                "privileges": null
            },
            "schemaPath": "CustomPropertyValue"
        },
        {
            "value": "App 2",
            "definition": {
                "id": "a495a6b1-d351-43b6-b995-a524652d63a3",
                "name": "UserAppAccess",
                "valueType": "Text",
                "choiceValues": [
                    "App 1",
                    "App 2",
                    "App 3"
                ]
            }
        },
        {
            "value": "App 3",
            "definition": {
                "id": "a495a6b1-d351-43b6-b995-a524652d63a3",
                "name": "UserAppAccess",
                "valueType": "Text",
                "choiceValues": [
                    "App 1",
                    "App 2",
                    "App 3"
                ]
            }
        }
    ],
    "userId": "UserId",
    "userDirectory": "UserDir",
    "userDirectoryConnectorName": "",
    "name": "UserId",
    "roles": [
        "RootAdmin"
    ],
    "attributes": [],
    "inactive": false,
    "removedExternally": false,
    "blacklisted": false,
    "deleteProhibited": false,
    "tags": [],
    "favorites": [],
    "privileges": null,
    "schemaPath": "User"
}

 

As an example you can use QlikSenseCLI to do the same with the following:

Import-Module 'C:\Program Files\Qlik\Sense\Tools\QlikSenseCLI'

Connect-QlikSense -TrustAllCertificates

$QSUser = Get-QSUser -Id '73b349f0-an1b-4f9f-a233-ef14br4361f4'
#-Filter always returns an array so we need the first value from the array
$QSCustomProperty = $(Get-QSCustompropertydefinition -Filter "UserAppAccess")|Select-Object -First 1
$CPV1 = New-QSCustomPropertyValue -Value 'App 1' -Definition $QSCustomProperty 
$CPV2 = New-QSCustomPropertyValue -Value 'App 2' -Definition $QSCustomProperty 
$CPV3 = New-QSCustomPropertyValue -Value 'App 3' -Definition $QSCustomProperty 

$QSUser.CustomProperties.Add($CPV1)
$QSUser.CustomProperties.Add($CPV2)
$QSUser.CustomProperties.Add($CPV3)
#You can view the Json we will be sending to the api by calling 
#$QSUser.ToJson()

Update-QSUser -Id $QSUser.id -UserObj $QSUser

 

View solution in original post

1 Reply
Marc
Employee
Employee

Get the CustomPropertyDefinition Condensed 

Get the User

Create a New Custom Property Value which requires one of the Custom Property Definitions Choice values, and the Definition.

{
    "value": "App 2",
    "definition": {
        "id": "a495a6b1-d351-43b6-b995-a524652d63a3",
        "name": "UserAppAccess",
        "valueType": "Text",
        "choiceValues": [
            "App 1",
            "App 2",
            "App 3"
        ]
    }
}

 

You need to add new custom property values to the customproperty array on the user.

then pass the updated user to the Update api 

e.g. put: qrs/user/73b349f0-an1b-4f9f-a233-ef14br4361f4 with the body

 
{
    "id": "73b349f0-an1b-4f9f-a233-ef14br4361f4",
    "createdDate": "2024-04-15T18:38:41.905Z",
    "modifiedDate": "2024-05-09T15:33:16.282Z",
    "modifiedByUserName": "UserDir\\UserId",
    "customProperties": [
        {
            "id": "579b33b9-f9cd-471l-a9f9-5f51de903855",
            "createdDate": "2024-05-09T15:18:51.308Z",
            "modifiedDate": "2024-05-09T15:31:16.282Z",
            "modifiedByUserName": "UserDir\\UserId",
            "value": "App 1",
            "definition": {
                "id": "a495a6b1-d351-43b6-b995-a524652d63a3",
                "name": "UserAppAccess",
                "valueType": "Text",
                "choiceValues": [
                    "App 1",
                    "App 2",
                    "App 3"
                ],
                "privileges": null
            },
            "schemaPath": "CustomPropertyValue"
        },
        {
            "value": "App 2",
            "definition": {
                "id": "a495a6b1-d351-43b6-b995-a524652d63a3",
                "name": "UserAppAccess",
                "valueType": "Text",
                "choiceValues": [
                    "App 1",
                    "App 2",
                    "App 3"
                ]
            }
        },
        {
            "value": "App 3",
            "definition": {
                "id": "a495a6b1-d351-43b6-b995-a524652d63a3",
                "name": "UserAppAccess",
                "valueType": "Text",
                "choiceValues": [
                    "App 1",
                    "App 2",
                    "App 3"
                ]
            }
        }
    ],
    "userId": "UserId",
    "userDirectory": "UserDir",
    "userDirectoryConnectorName": "",
    "name": "UserId",
    "roles": [
        "RootAdmin"
    ],
    "attributes": [],
    "inactive": false,
    "removedExternally": false,
    "blacklisted": false,
    "deleteProhibited": false,
    "tags": [],
    "favorites": [],
    "privileges": null,
    "schemaPath": "User"
}

 

As an example you can use QlikSenseCLI to do the same with the following:

Import-Module 'C:\Program Files\Qlik\Sense\Tools\QlikSenseCLI'

Connect-QlikSense -TrustAllCertificates

$QSUser = Get-QSUser -Id '73b349f0-an1b-4f9f-a233-ef14br4361f4'
#-Filter always returns an array so we need the first value from the array
$QSCustomProperty = $(Get-QSCustompropertydefinition -Filter "UserAppAccess")|Select-Object -First 1
$CPV1 = New-QSCustomPropertyValue -Value 'App 1' -Definition $QSCustomProperty 
$CPV2 = New-QSCustomPropertyValue -Value 'App 2' -Definition $QSCustomProperty 
$CPV3 = New-QSCustomPropertyValue -Value 'App 3' -Definition $QSCustomProperty 

$QSUser.CustomProperties.Add($CPV1)
$QSUser.CustomProperties.Add($CPV2)
$QSUser.CustomProperties.Add($CPV3)
#You can view the Json we will be sending to the api by calling 
#$QSUser.ToJson()

Update-QSUser -Id $QSUser.id -UserObj $QSUser