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

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
Levi_Turner
Employee
Employee

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?

View solution in original post

4 Replies
amien
Specialist
Specialist
Author

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.

Levi_Turner
Employee
Employee

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
Specialist
Specialist
Author

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
Specialist
Specialist
Author

works now thanks