Qlik Community

Qlik Sense Integration, Extensions, & APIs

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

amien
Valued Contributor

Why do i keep getting the login page with this API call in PS?

$req = New-Object System.Net.WebClient

$req.Method = "GET";

$req.UserAgent = "Windows";

$req.Accept = "application/json";

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

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

$req.DownloadString("https://url:12345/qrs/about?xrfkey=ABCDEFG123456789");


anyone can help with? what i'm missing?


1 Solution

Accepted Solutions
Employee
Employee

Re: Why do i keep getting the login page with this API call in PS?

What is port 12345? Is this the QRS port (4242) or the Proxy HTTPS port (443)? If it's 443, then is the default virtual proxy setup for Forms auth?

Sample .ps1 since I couldn't get your code to run:

$hdrs = @{}

$hdrs.Add("X-Qlik-Xrfkey","12345678qwertyui")

$hdrs.Add("X-Qlik-User", "UserDirectory=INTERNAL; UserId=sa_api")

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

$myFQDN=(Get-WmiObject win32_computersystem).DNSHostName+"."+(Get-WmiObject win32_computersystem).Domain

$myFQDN = $myFQDN.ToLower()

Invoke-RestMethod -Uri "https://$($myFQDN):4242/qrs/about?xrfkey=12345678qwertyui" -Method Get -Headers $hdrs -ContentType 'application/json' -Certificate $cert'



Likewise, what is the response from Powershell?

4 Replies
amien
Valued Contributor

Re: Why do i keep getting the login page with this API call in PS?

i don't need to do something with a certificate right? because i'm executing the PS1 script under the same account as service account of Qlik Sense services.

ABCDEFG123456789 key i create random ofcourse.

Employee
Employee

Re: Why do i keep getting the login page with this API call in PS?

What is port 12345? Is this the QRS port (4242) or the Proxy HTTPS port (443)? If it's 443, then is the default virtual proxy setup for Forms auth?

Sample .ps1 since I couldn't get your code to run:

$hdrs = @{}

$hdrs.Add("X-Qlik-Xrfkey","12345678qwertyui")

$hdrs.Add("X-Qlik-User", "UserDirectory=INTERNAL; UserId=sa_api")

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

$myFQDN=(Get-WmiObject win32_computersystem).DNSHostName+"."+(Get-WmiObject win32_computersystem).Domain

$myFQDN = $myFQDN.ToLower()

Invoke-RestMethod -Uri "https://$($myFQDN):4242/qrs/about?xrfkey=12345678qwertyui" -Method Get -Headers $hdrs -ContentType 'application/json' -Certificate $cert'



Likewise, what is the response from Powershell?

amien
Valued Contributor

Re: Why do i keep getting the login page with this API call in PS?

12345 is my https port which i changed in qmc (instead of 443)

from my code the result is that i get some kind of java/html login page (code).

form is not default. Default is from installation: Central Proxy (Default) Ticket/Windows

your code gives this error:

Invoke-RestMethod : The remote server returned an error: (403) Forbidden.

At line:14 char:1

+ Invoke-RestMethod -Uri "https://$($myFQDN):4242/qrs/about?xrfkey=12345678qwertyu ...

+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-RestMethod], WebException

    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeRestMethodCommand

amien
Valued Contributor

Re: Why do i keep getting the login page with this API call in PS?

works now thanks

Community Browser