Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi!
I'm trying to use the QRS API through Qlik-Cli on PowerShell to add a tag to an UserSyncTask, but got a 400 error.
Below, a sequence of commands which I tried to add a tag to an UserSyncTask.
Has someone got this issue?
Thanks!
PS C:\Users\user> $resp = Invoke-QlikGet -path /qrs/usersynctask/full -filter "name eq '99899_usersynctask'"
PS C:\Users\user> $resp
id : e497da37-f7d2-4907-8573-8bd68999dfdf
createdDate : 2022/02/21 14:26
modifiedDate : 2022/02/23 13:18
modifiedByUserName : QLIK-VM\user
customProperties : {}
userDirectory : @{id=47023d8a-71c1-4fc7-9994-aa4b9b0cc692; name=99899;
type=Repository.UserDirectoryConnectors.ODBC.OdbcSql; privileges=}
operational : @{id=d826cdea-29c9-4451-a898-f623f0a3e76b; lastExecutionResult=; nextExecution=2022/02/28 14:31;
privileges=}
name : 99899_usersynctask
taskType : UserSync
enabled : True
taskSessionTimeout : 1440
maxRetries : 0
tags :
privileges :
schemaPath : UserSyncTask
PS C:\Users\user> $tag = Get-QlikTag -filter "name eq '99899'"
PS C:\Users\user> $tag
id name privileges
-- ---- ----------
10cbbf94-9a92-4b5e-b7d5-d762acb43345 99899
PS C:\Users\user> $resp.tags = $tag
PS C:\Users\user> $resp
id : e497da37-f7d2-4907-8573-8bd68999dfdf
createdDate : 2022/02/21 14:26
modifiedDate : 2022/02/23 13:18
modifiedByUserName : QLIK-VM\user
customProperties : {}
userDirectory : @{id=47023d8a-71c1-4fc7-9994-aa4b9b0cc692; name=99899;
type=Repository.UserDirectoryConnectors.ODBC.OdbcSql; privileges=}
operational : @{id=d826cdea-29c9-4451-a898-f623f0a3e76b; lastExecutionResult=; nextExecution=2022/02/28 14:31;
privileges=}
name : 99899_usersynctask
taskType : UserSync
enabled : True
taskSessionTimeout : 1440
maxRetries : 0
tags : @{id=10cbbf94-9a92-4b5e-b7d5-d762acb43345; name=99899; privileges=}
privileges :
schemaPath : UserSyncTask
PS C:\Users\user> $json = $resp | ConvertTo-Json
PS C:\Users\user> Invoke-QlikPut -path "/qrs/usersynctask/$($resp.id)" -body $json
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At C:\Program Files\WindowsPowerShell\Modules\Qlik-CLI\functions\core.ps1:66 char:23
+ ... $result = Invoke-RestMethod @paramInvokeRestMethod @params
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExceptio
n
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
Can you preview the Invoke lines using variables to make sure that your are constructing your requests correctly? A small syntax issue here can go unnoticed unless you inspect all variables throughout the script as it executes. Does the body inside $json object look like it should?
Hi @Mario_Petre!
Thank you for your feedback.
I don't know if that was what you're talking about preview lines, but Qlik-Cli allows the use of -Debug and -Verbose flags. By this way I could inspect the URL and JSON data in request body:
PS C:\Users\user> Invoke-QlikPut -path "/qrs/usersynctask/$($resp.id)" -body $json -Debug -Verbose
VERBOSE: Raw output:
VERBOSE: Adding header x-Qlik-Xrfkey: qzuoyhqnkgseqnaf
VERBOSE: {
"id": "e497da37-f7d2-4907-8573-8bd68999dfdf",
"createdDate": "2022/02/21 14:26",
"modifiedDate": "2022/02/23 13:18",
"modifiedByUserName": "QLIK-VM\user",
"customProperties": [
],
"userDirectory": {
"id": "47023d8a-71c1-4fc7-9994-aa4b9b0cc692",
"name": "99899",
"type": "Repository.UserDirectoryConnectors.ODBC.OdbcSql",
"privileges": null
},
"operational": {
"id": "d826cdea-29c9-4451-a898-f623f0a3e76b",
"lastExecutionResult": {
"id": "11147879-e125-4d0a-b660-82546aebcbc9",
"executingNodeName": "server.company.com.br",
"status": "FinishedSuccess",
"startTime": "2022/02/21 14:31",
"stopTime": "2022/02/21 14:31",
"duration": 10382,
"fileReferenceID": "00000000-0000-0000-0000-000000000000",
"scriptLogAvailable": false,
"details": " ",
"scriptLogLocation": "",
"scriptLogSize": -1,
"privileges": null
},
"nextExecution": "2022/02/28 14:31",
"privileges": null
},
"name": "99899_usersynctask",
"taskType": "UserSync",
"enabled": true,
"taskSessionTimeout": 1440,
"maxRetries": 0,
"tags": {
"id": "10cbbf94-9a92-4b5e-b7d5-d762acb43345",
"name": "99899",
"privileges": null
},
"privileges": null,
"schemaPath": "UserSyncTask"
}
VERBOSE: Calling Put for https://server.company.com.br:4242/qrs/usersynctask/e497da37-f7d2-4907-8573-8bd68999dfdf?xrfke
y=qzuoyhqnkgseqnaf
VERBOSE: PUT https://server.company.com.br:4242/qrs/usersynctask/e497da37-f7d2-4907-8573-8bd68999dfdf?xrfkey=qzuoyhqnkg
seqnaf with -1-byte payload
Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At C:\Program Files\WindowsPowerShell\Modules\Qlik-CLI\functions\core.ps1:66 char:23
+ ... $result = Invoke-RestMethod @paramInvokeRestMethod @params
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebExceptio
n
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand
The JSON displayed above is the same value in the $json variable - as expected.
I validated the JSON generated and it seems to be OK.
While analyzing the model for UserSyncTask endpoint (https://help.qlik.com/en-US/sense-developer/November2021/APIs/RepositoryServiceAPI/index.html?page=1...), I noticed that the property "taskType" should be an Integer and I'm sending a String. However, even changing its "UserSync" by 2, the same error 400 is still getting in place.
Do you know how to get more details besides the HTTP code, in order to get better understanding on what is wrong?
Thanks,
José