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: 
Qlik_Administrator_Dude
Partner - Creator
Partner - Creator

Can't get qlik.exe CLI to make a 'PUT' call

I am having some trouble with the qlik.exe cli 

I should be able to make a call like : qlik raw put $pathtoAPI --body-values $hashtable 

I cannot make this call. I get an error every time. I will share my code.

We can use the Data Connections API as an example: Data connections | Qlik Developer Portal

#Variables I use

$APITenant = "https://thenameofmyqliktenant.com"

$APIEndpoint = "/v1/data-connections"

$apikey = "secretkey123"

$TargetDataConnection = $APIEndpoint+"/"+{qID of the targeted Data Connection} 

## Calls (keep in mind my qlik context is already set)

qlik raw get $TargetDataConnection | Convertfrom-json 

## I now build a form as a hashtable for the body call later

$hashtable = @{} 

## End of script for now. 

 

According to the Data-Connections API, I should be to build a hash table (key=value, which that colde '@{}' does) with all of the required data listed in the under the 'request' for the 'put' command on the API web page. I include all of those in the $hashtable, and make the call like this: 

qlik raw put $TargetDataConnection  --body-value $hashtable 

This call doesn't work. 
Before I share the error, I wanted to share the qlik --help for this call

Usage:
qlik raw <get/put/patch/post/delete> v1/url [flags]

Examples:
qlik raw get v1/items --query name=ImportantApp

Flags:
--body string The content of the body as a string
--body-file string A file path pointing to a file
containing the body of the http request
--body-values stringToString A set of key=value pairs that well be
compiled into a json object. A dot
(.) inside the key is used to
traverse into nested objects. The key
suffixes :bool or :number can be
appended to the key to inject the
value into the json structure as
boolean or number respectively.
(default [])

The error I get when using a hashtable is:

C:\QlikCLI\qlik.exe : Error: invalid argument "System.Collections.Hashtable" for "--body-values" flag: System.Collections.Hashtable must be formatted as
key=value
At line:1 char:1
+ C:\QlikCLI\qlik.exe raw PUT $APIDCEndpoint --body-values $hashtable --ver ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Error: invalid ...ed as key=value:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError

 

## I am pretty sure my hashtable is created properly. 

 

 

 

The error I get if I don't use a hashtable is: 

Error: {
"errors": [
{
"code": "DCERROR-0010",
"title": "Bad or invalid request",
"status": 400,
"detail": "Binding body failed: invalid character '@' looking for beginning of value"
}
],
"traceId": "0000000000000000ce63fdcb7bf3d0aa"
}

 

Someone Help!! Thanks

 

Labels (3)
1 Solution

Accepted Solutions
Marc
Employee
Employee

ok... so it looks like the --body should take the Json input but for some reason does not, it is also really picky about the Encoding used if dumping to a file... 

$ObjID = "123456789"
$BaseAPI = "/v1/data-connections"
$API = "$($BaseAPI)/$($ObjID)"
#Get the DataConnection
$QSCDataconnection = .\qlik.exe raw get $API|ConvertFrom-Json

#Make changes to DC here
$QSCDataconnection.qName = "$($QSCDataconnection.qName)_modified"
$QSCDCJson = ConvertTo-Json -InputObject $QSCDataconnection -Depth 5 -Compress

##This Should work, but does not.
#.\qlik.exe raw put $($API) --body $($QSCDCJson)

#Workaround Dump to temp file with UTF8 Encoding (not UTF8BOM)
[system.io.FileInfo]$TempFile = [System.IO.Path]::GetTempFileName()
[System.IO.File]::WriteAllLines($TempFile.FullName, $QSCDCJson, [System.Text.UTF8Encoding]::new($False))
.\qlik.exe raw put $($API) --body-file $TempFile.FullName
$TempFile.delete()

  

View solution in original post

11 Replies
Marc
Employee
Employee

In the Error.

C:\QlikCLI\qlik.exe : Error: invalid argument "System.Collections.Hashtable" for "--body-values" 
Essentially you are trying to pass a Hashtable object to qlik.exe on the commandline. as the commandline only accepts text strings this is not going to work.

you need to convert the Hashtable to json and pass the json to the exe.

## Get the DataConnection
$QSCDataconnection = $(qlik raw get $TargetDataConnection) | Convertfrom-json 

## Make the required changes here
$QSCDataconnection

## Convert the Object to a string and post the changes back
$QSCDCJson = ConvertTo-Json -InputObject $QSCDataconnection -Depth 5
qlik raw put $TargetDataConnection --body-value $QSCDCJson 
Qlik_Administrator_Dude
Partner - Creator
Partner - Creator
Author

Hey thanks for the code Marc. I tried it out and here is the error I received. What do you think? 

 

C:\QlikCLI\qlik.exe : Error: unknown flag: --body-value
At line:1 char:1
+ C:\QlikCLI\qlik.exe raw PUT $APIDCEndpoint --body-value $QSCDCJson
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (Error: unknown flag: --body-value:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError

If this should be an argument and not a flag you can
specify so by using double dash (--), for example:
qlik raw [flags] -- --body-value
Note that in this case all flags must be provided
before the double dash (--).

 

Here are my code modifications

 

 

## Marc's code
$QSCDataconnection = $(C:\QlikCLI\qlik.exe raw GET $TargetDataConnection) | Convertfrom-json

## my edit 1
$QSCDataconnection | Add-Member -MemberType NoteProperty -Name qConnectionSecret -Value 'FooBar'

## Marc's Code 
$QSCDCJson = ConvertTo-Json -InputObject $QSCDataconnection -Depth 5
C:\QlikCLI\qlik.exe raw PUT $TargetDataConnection --body-value $QSCDCJson

 

 

Thanks Marc!!

mow
Employee
Employee

Hello, I believe Marc is correct that the hashtable needs to be converted into JSON before being passed to qlik-cli. The error you are receiving now is due to a typo in the parameter name --body-values.

 

$QSCDCJson = ConvertTo-Json -InputObject $QSCDataconnection -Depth 5
C:\QlikCLI\qlik.exe raw PUT $TargetDataConnection --body-values $QSCDCJson

 

Qlik_Administrator_Dude
Partner - Creator
Partner - Creator
Author

Hello mow,

Thank you for the response. Originally I didn't convertto-json because of this statement in the --body-value help: 
"--body-values stringToString A set of key=value pairs that well be
compiled into a json object. "

 

I compiled the Hash Table into JSON as Markcsuggested. It seems that the 'qConnectionstatement' value is causing an issue. Can you help me understand what the required values are on the form? 

 

In other API calls, I have to 'Convertto-JSON' for any nested lists first, then add the json to the new list, then convert the new list to JSON. I was wondering if some sort of stepped approach might be needed as the connection string looks like a nested list in the array. 

 

I thought it might help if I provided my values. FYI I did try to convert the 'qConnectionstatement' string to json and basically got the same error. Thanks for the help finding the syntax error (I may have changed it a little for privacy): 
created : 2023-02-22T23:46:24.538Z
datasourceID : File_AmazonS3ConnectorV2
id : 123456789
privileges : {change_owner, change_space, delete, list...}
qArchitecture : 0
qConnectStatement : CUSTOM CONNECT TO "provider=QvWebStorageProviderConnectorPackage.exe;sourceType=File_AmazonS3ConnectorV2;region=us-east-1;bucketName=testbucketdontuse230222;"
qCredentialsID : 123-456-78910
qEngineObjectID : 123456789
qID : 123456789
qLogOn : 1
qName : Amazon_S3_V2_Testbucket2302
qSeparateCredentials : False
qType : QvWebStorageProviderConnectorPackage.exe
tenant : mytenantisamazing
updated : 2023-02-22T23:46:24.538Z
user : qlikadministrationdude
version : V1
qConnectionSecret : FooBar

 

 

 

Marc
Employee
Employee

ok... so it looks like the --body should take the Json input but for some reason does not, it is also really picky about the Encoding used if dumping to a file... 

$ObjID = "123456789"
$BaseAPI = "/v1/data-connections"
$API = "$($BaseAPI)/$($ObjID)"
#Get the DataConnection
$QSCDataconnection = .\qlik.exe raw get $API|ConvertFrom-Json

#Make changes to DC here
$QSCDataconnection.qName = "$($QSCDataconnection.qName)_modified"
$QSCDCJson = ConvertTo-Json -InputObject $QSCDataconnection -Depth 5 -Compress

##This Should work, but does not.
#.\qlik.exe raw put $($API) --body $($QSCDCJson)

#Workaround Dump to temp file with UTF8 Encoding (not UTF8BOM)
[system.io.FileInfo]$TempFile = [System.IO.Path]::GetTempFileName()
[System.IO.File]::WriteAllLines($TempFile.FullName, $QSCDCJson, [System.Text.UTF8Encoding]::new($False))
.\qlik.exe raw put $($API) --body-file $TempFile.FullName
$TempFile.delete()

  

Qlik_Administrator_Dude
Partner - Creator
Partner - Creator
Author

Marc,

Your code was very helpful. It seems my PUTs work with the UTF8 modification as you suggested. That was great!

when I update the 'qconnection' key with this code, it does take it, but the connection doesn't work after. It will throw an error in the Web Interface that says the parameter isn't formatted correctly or has a misplaced semicolon. Any additional advice there? Thanks 

DaveChannon
Employee
Employee

Hi @Qlik_Administrator_Dude - a heads up that if if you're trying to create a data connection, or update a credential in a data connection, then this isn't possible via the data-connections API today. It supports updating of some metadata on a connection, and creation of REST connections with no credentials.

We are currently working on a new API to support creation and management of data connections in Qlik Cloud.

Qlik_Administrator_Dude
Partner - Creator
Partner - Creator
Author

@DaveChannon Thanks for the reply. That is a huge bummer. I know this isn't you exactly, but I thought replying here would be most appropriate for my gripe (seriously thank you for the reply, please don't take my gripe personally, you just helped me a ton). 

My Gripes:
1. The following values are exposed to the PUT api Endpoint, and when I call them they update the value but break the connections:

  "qCredentialsName": "string",
  "qConnectStatement": "string",
  "qConnectionSecret": "Any string",

 

2. This is either a typo, or it doesn't work. There isn't an endpoint I can reach "data0connections". Is this the 'new' endpoint you were mentioning?

For GET

qConnectionSecret
optional
string

String that contains connection specific secret (or password). This field will not be included in response of GET /data-connections, will only be included in the response of GET /data0connections/{qID}

For PUT

qConnectionSecret
optional
string

String that contains connection level secret (or password). If this field presents in request, then existing connection secret will be updated to its value. If is an empty string, then eixsting connection secret will be cleared. If this field is missing, existing secret will not be updated.

 

3. Is the UTF8 format thing we found a bug? What formats can we upload our PUTs in? 

 

 

Please feel free to answer any of those you can. I would appreciate it. 

 

@Marc You are the man!! 

DaveChannon
Employee
Employee

@Qlik_Administrator_Dude, unfortunately I think you're suffering from several documentation issues!

We should make it clear that you cannot PUT attributes relating to credentials with this API, and the data0connections is a typo.

With respect to the future API, it'll most likely be on a different path, and should provide a much cleaner way of creating and updating connections. We are currently hoping to start rolling the first parts of this in H1 23, if all goes well, and update the documentation as we go.

On 3, I will defer to the judgement of @Marc!