Skip to main content
Announcements
See why Qlik is a Leader in the 2024 Gartner® Magic Quadrant™ for Analytics & BI Platforms. Download Now
cancel
Showing results for 
Search instead for 
Did you mean: 
AV1
Partner - Contributor II
Partner - Contributor II

Update custom properties of Users in QMC through API

Hi, is there any way to update custom properties of QMC/Users from Qlik script or though any Qlik code using REST connectors. Any help on this, as I need to automate the process of providing user access through script and not manually from QMC.

Thanks!

Labels (2)
3 Replies
Øystein_Kolsrud
Employee
Employee

It might be possible, but I'm not sure it's recommended. Working with REST APIs like that through the Qlik scripts is quite cumbersome. Perhaps you could find a way to do this through the APIs outside of Qlik Sense? There's much better support for doing this if you use something like JavaScript or C#. Or curl for that matter.

But if you want to see if you can build this in a Qlik script then this link might be of interest: https://community.qlik.com/t5/Design/REST-connector-Using-WITH-CONNECTION/ba-p/1523257

stefanstoichev123

As Oystein mentioned it is easier to make such changes outside Qlik script. 

The other issue is that in order to update User (this includes changes in the assigned custom properties) you'll have to make PUT request (API reference). And the native Qlik rest connector supports only GET and POST requests.

For such scenario I had to build small web service that accepts POST requests, "converts" them to PUT requests and then calling Qlik API to update the users. And from Qlik script i was calling the web service.

Stefan

 

 

 

Marc
Employee
Employee

The following code will work, 

The Custom Property must exist in the environment, and the value you are setting must be one of the available choice values.

 

Function Get-ServicePath($Name) {
    # Find the repository service
    $WinService = Get-WmiObject win32_service | Where-Object { $_.Name -eq $Name } | Select-Object Name, DisplayName, State, PathName
    [regex]$EXEPath = '(\\\\|\w:)(.+)(\..{3})'
    if ($WinService.PathName -match $EXEPath) { [System.IO.FileInfo]$WinServicePath = $Matches[0] }
    $WinService | Add-Member -MemberType NoteProperty -Name Path -Value $WinServicePath
    $WinService
}

# Dynamically locate the Install Directory
$RepositoryService = Get-ServicePath -Name 'QlikSenseRepositoryService'
[System.IO.DirectoryInfo]$InstallDIR = $RepositoryService.Path.Directory.Parent.FullName

# Import the Module
Import-Module "$($InstallDIR.FullName)\Tools\QlikSenseCLI"

# Connect to Qlik Sense
Connect-QlikSense -TrustAllCertificates

#Name of the Custom Property
$CPName = 'UserCP'

# Filter always returns an Array, so we need to select the first one
$QSCustomPropertyDefinition = $(Get-QSCustompropertydefinition -Filter "Name eq '$($CPName)'") | Select-Object -First 1

# We need the Full Object to do a update
$SelectedQSUsers = Get-QSUser -Filter "UserID eq 'Marc'" -Full

foreach($user in $SelectedQSUsers){
    
    # Create the New Custom Property Value we are going to add (the value needs to be one of the possible values in the Custom Property Definition)
    $newCPValue = New-QSCustomPropertyValue -Definition $QSCustomPropertyDefinition -Value "Value1"
    $user.CustomProperties.Add($newCPValue)
    Update-QSUser -Id $user.Id -UserObj $user
}