Qlik Community

Qlik Sense Integration, Extensions, & APIs

Discussion board where members can learn more about Integration, Extensions and API’s for Qlik Sense.

Announcements
Coming your way, the Qlik Data Revolution Virtual Summit. October 27-29. REGISTER
cancel
Showing results for 
Search instead for 
Did you mean: 
Highlighted
Contributor III
Contributor III

Error 400 - Bad Request for import api call

I can't find the reason this command in powershell raise an error

$hdrs = @{}
$hdrs.Add("X-Qlik-xrfkey","1234567890123456")
$hdrs.Add("X-Qlik-User","UserDirectory=XXXXX;UserId=XXXXXXXXXXXXXX")

$cert = Get-ChildItem -Path "Cert:\CurrentUser\My" | Where {$_.Subject -like '*QlikClient*'}

$Body = @{
filename="test_import.qvf"
} | ConvertTo-Json

$url = "https://XXXXX.XXXXXX.XXX:4242/qrs/app/import?name=test_import&xrfkey=1234567890123456"
$response = Invoke-RestMethod -Uri $url -Method POST -Headers $hdrs -Certificate $cert -Body $Body -ContentType 'application/json'
$response

 

Error:

 

Invoke-RestMethod : The remote server returned an error: (400) Bad Request.
At line:15 char:13
+ $response = Invoke-RestMethod -Uri $url -Method POST -Headers $hdrs - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException
+ FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

PS: I can run other POST or Get command

Labels (2)
1 Solution

Accepted Solutions
Highlighted
Employee
Employee

This works for me:

$hdrs = @{}
$hdrs.Add("X-Qlik-Xrfkey","examplexrfkey123")
$hdrs.Add("X-Qlik-User", "UserDirectory=INTERNAL; UserId=sa_api")
$cert = Get-ChildItem -Path "Cert:\CurrentUser\My" | Where {$_.Subject -like '*QlikClient*'}
$Data = Get-Content C:\ProgramData\Qlik\Sense\Host.cfg
$FQDN = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($($Data)))
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12' 
Invoke-RestMethod -Uri "https://$($FQDN):4242/qrs/app/upload?keepData=true&name=Some+Name&xrfkey=examplexrfkey123" -Method Post  -Headers $hdrs -ContentType 'application/vnd.qlik.sense.app' -Certificate $cert -InFile 'C:\Temp\Random Data.qvf'

View solution in original post

1 Reply
Highlighted
Employee
Employee

This works for me:

$hdrs = @{}
$hdrs.Add("X-Qlik-Xrfkey","examplexrfkey123")
$hdrs.Add("X-Qlik-User", "UserDirectory=INTERNAL; UserId=sa_api")
$cert = Get-ChildItem -Path "Cert:\CurrentUser\My" | Where {$_.Subject -like '*QlikClient*'}
$Data = Get-Content C:\ProgramData\Qlik\Sense\Host.cfg
$FQDN = [System.Text.Encoding]::UTF8.GetString([System.Convert]::FromBase64String($($Data)))
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12' 
Invoke-RestMethod -Uri "https://$($FQDN):4242/qrs/app/upload?keepData=true&name=Some+Name&xrfkey=examplexrfkey123" -Method Post  -Headers $hdrs -ContentType 'application/vnd.qlik.sense.app' -Certificate $cert -InFile 'C:\Temp\Random Data.qvf'

View solution in original post