Skip to main content
Announcements
July 15, NEW Customer Portal: Initial launch will improve how you submit Support Cases. IMPORTANT DETAILS
cancel
Showing results for 
Search instead for 
Did you mean: 
jeff007
Partner - Contributor
Partner - Contributor

QRS API : Allocate license access

Hi,

I would like to allocate analyzer (or profesional) access with the QRS API.

I am trying to do it according to that documentation https://help.qlik.com/en-US/sense-developer/February2019/APIs/repositoryserviceapi/index.html?page=1...

(which unfortunately does not contains an example of the request body to send)

 

I am sending a POST request to https://my-qlik-server:4242/qrs/license/analyzeraccesstype?Xrfkey=xbZdef9hijkPxn4P

Body : 

{
"modifiedByUserName": "INTERNAL\\sa_repository",
"modifiedDate": "2019-05-03T17:23:02.316Z",
"user": {
"userDirectory": "AZ-XXX",
"userId": "2db75108-922f-4736-8461-a7ec7c1edda2"
},
"createdDate": "2019-05-03T17:23:02.315Z"
}

 

But, in return, I get a HTTP 400 (bad request)

Could you please provide the body that must be passed to make it work ?

Is there any logs in QlikSense giving more details about what is bad in the request ?

Thanks,

JF

PS : I have other QRS APIs calls working fine, the problem is specific to that API. Certificate authentication is OK and HTTP headers like Xrfkey  are passed correctly...

 

 

 

Labels (2)
11 Replies
makunii
Partner - Contributor III
Partner - Contributor III

Script Powershell:

$hdrs = @{}
$hdrs.Add("X-Qlik-xrfkey","12345678qwertyui")
$hdrs.Add("X-Qlik-User","UserDirectory=xxxx;UserId=xxxxx")
$hdrs.Add("Content-Type","application/json")
$cert = Get-ChildItem -Path "Cert:\CurrentUser\My" | Where {$_.Subject -like '*QlikClient*'}
$body = '{"user":{"id":"244ee0d3-7ee1-42bc-b3ac-f30787dd6d3b"}}'
$url2 = "https://<sense server>:4242/qrs/license/professionalaccesstype?xrfkey=12345678qwertyui"
Invoke-RestMethod -Uri $url2 -Method Post -Headers $hdrs -Certificate $cert -Body $body

Analyzer licenses, replace "professionalaccesstype" to "analyzeraccesstype"

 

 

Marc
Employee
Employee

if you use the PowerShell Module QlikSenseCLI you can easily extend this

by setting the UserID & UserDirectory values the following script will look for the user in Qlik Sense, if the User does not exist it will be create and then you can assign the license. (that way you don't need to know their GUID id)

#Get the QlikClient Certificate
$cert = Get-ChildItem -Path "Cert:\CurrentUser\My" | Where-Object { $_.Subject -eq 'CN=QlikClient' } | Sort-Object -Property NotAfter | Select-Object -First 1

#Connect to Qlik Sense QRS
Connect-QlikSense -Certificate $cert -Username "Internal\sa_api"

$UserID = 'QlikMarc'
$UserDirectory = $env:USERDOMAIN
#Get the User (-Filter Always returns an array)
$user = Get-QSUser -Filter "userid eq '$($UserID)' and userdirectory eq '$($UserDirectory)'"

#If there is no user found create the user 
if ($user.Count -eq 0) { $Null = Add-QSUser -UserObj $(New-QSUser -UserId $UserID -UserDirectory $UserDirectory); $user = Get-QSUser -Filter "userid eq '$($UserID)'" }

#then assign a license
#Analyzer
$AAccessType = $user | ForEach-Object{ New-QSLicenseAnalyzerAccessType -User $_ }
Add-QSLicenseAnalyzeraccesstype -Many -LicenseAnalyzerAccessTypeObjs $AAccessType

#Professional
$PAccessType = $user | ForEach-Object{ New-QSLicenseProfessionalAccessType -User $_ }
Add-QSLicenseProfessionalaccesstype -Many -LicenseProfessionalAccessTypeObjs $PAccessType

 

Alternatively you can set it to Assign a professional license only if the user exists and does not already have a license of the type assigned

#https://github.com/QlikProfessionalServices/QlikSenseCLI
$cert = Get-ChildItem -Path "Cert:\CurrentUser\My" | Where-Object { $_.Subject -eq 'CN=QlikClient' } | Sort-Object -Property NotAfter -Descending | Select-Object -First 1
Connect-QlikSense -Certificate $cert -Username "Internal\sa_api"

$UserID = 'QlikMarc'
$UserDirectory = $env:USERDOMAIN
$user = Get-QSUser -Filter "userid eq '$($UserID)' and userdirectory eq '$($UserDirectory)'"
if ($user.Count -gt 0) {
	$user | ForEach-Object{
		$existing = Get-QSLicenseProfessionalaccesstype -Filter "user.userid eq '$($UserID)' and user.userdirectory eq '$($UserDirectory)'"
		if ($existing.Count -eq 0) {
			$PAccessType = $user | ForEach-Object{ New-QSLicenseProfessionalAccessType -User $_ }
			Add-QSLicenseProfessionalaccesstype -Many -LicenseProfessionalAccessTypeObjs $PAccessType
		}
	}
}