Skip to main content
Announcements
Qlik Connect 2024! Seize endless possibilities! LEARN MORE
cancel
Showing results for 
Search instead for 
Did you mean: 
martinmichalski
Contributor III
Contributor III

QRS Integration with Powershell 2.0

Hello Community,

I am trying to reload a task using QRS API integration. The idea is to call Powershell from a Qlikview Document so it reloads a QlikSense document after it finishes.

I am being able to reload by using Postman. Here is the Request.bin request:

POST https://{host}/qrs/task/{taskid}/start/synchronous?xrfkey=ABCDEFG123456789

QUERYSTRING:

xrfkey: ABCDEFG123456789

HEADERS:

X-Qlik-Xrfkey: ABCDEFG123456789

Cf-Visitor: {"scheme":"http"}

Connection: close

Content-Type: application/x-www-form-urlencoded

However, I am not being able to do this using Powershell v2.

Looking at the documentation in Qlik Branch I saw this code that allows us to communicate using Powershell:

$req = New-Object System.Net.WebClient

$req.Credentials = [System.Net.CredentialCache]::DefaultCredentials

$req.QueryString.Add("xrfkey", "ABCDEFG123456789")

$req.Headers.Add("X-Qlik-xrfkey", "ABCDEFG123456789")

[Net.ServicePointManager]::ServerCertificateValidationCallback = {$true}

$req.Headers.Add("Cf-Visitor", ‘{"scheme":"http"}‘);

$req.DownloadString("https://{host}/qrs/task/{taskid}/start/synchronous"

This is working, but as it is a GET request, it just downloads the URL, without reloading the task. I need to do a POST request.

I tried using the command Invoke-WebRequest, but is not available on this version.

Does anyone no how can I do it without Invoke-WebRequest?

Thank you in advance,

Martin

2 Replies
teiswamsler
Partner - Creator III
Partner - Creator III

Hi Martin

I currently have the same problem, got the POST command working in Postman. But cant get it to work in PS.

Have you found a solution wet?

/Teis

martinmichalski
Contributor III
Contributor III
Author

Hi Teis,

Sorry for the late reply. I discovered that Postman uses Windows Authentication method, so it works if you already had an opened session with the server (I believe it's enough by logging into the hub or the qmc). That's why you need to make a GET call before the POST, so you go through the authentication module.

However, if you use the server credentials by installing the windows client certificate in the machine that is executing the call you should be able to communicate with the API.

Then you can get the certificate with this command:

$cert = Get-Childitem cert:\CurrentUser\My\ | where { $_.subject -eq "CN=YourCertName" }

And include it in the request by ClientCertificates.Add:

$web = [System.Net.WebRequest]::Create($url)

$web.ClientCertificates.Add($cert)

$web.Method = "POST"

Remember you also need to add headers for the x-qlik-xrfkey: ABCDEFG123456789 and the X-Qlik-User: UserDirectory=Internal;UserId=sa_repository

Hope it helped.