Skip to main content
Woohoo! Qlik Community has won “Best in Class Community” in the 2024 Khoros Kudos awards!
Announcements
Join us at Qlik Connect for 3 magical days of learning, networking,and inspiration! REGISTER TODAY and save!
cancel
Showing results for 
Search instead for 
Did you mean: 
parviz_asoodehfard
Contributor III
Contributor III

Error 400 - Bad Request for import api call

 

 

I'm new in calling API, 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 (1)
4 Replies
andoryuu
Creator III
Creator III

Before diving too deeply into this, why not just use Qlik-CLI? It's developed by Qlik and GREATLY improves usage and security of PowerShell and Qlik Sense. It will make your life so much easier when building a Qlik Sense & PowerShell ecosystem.
andoryuu
Creator III
Creator III

@parviz_asoodehfard  have you tried this?

parviz_asoodehfard
Contributor III
Contributor III
Author

The usage of power shell was a POC for me. After that, I need to run it by PDI and the base thing is enough for me, so I didn't try Qlik-CLI.

 

I found out I should use qrs/app/update.

I appreciate you @andoryuu 

 
andoryuu
Creator III
Creator III

Gotcha - glad it all worked out!