<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Trouble send direct request to Repository API in Integration, Extension &amp; APIs</title>
    <link>https://community.qlik.com/t5/Integration-Extension-APIs/Trouble-send-direct-request-to-Repository-API/m-p/2036847#M18095</link>
    <description>&lt;P&gt;Hi everyone,&lt;BR /&gt;&lt;BR /&gt;We have a server with Qlik Sense installed (A) and another server (B) from which we want to run a powershell program that performs instructions from server A with the qrs API.&lt;/P&gt;
&lt;P&gt;The problem is that we can't connect using the certificate and sending a direct request to the repository API.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Following the steps described in &lt;A href="https://community.qlik.com/t5/Official-Support-Articles/Qlik-Sense-QRS-API-using-Xrfkey-header-in-PowerShell/ta-p/1716660" target="_blank" rel="noopener"&gt;https://community.qlik.com/t5/Official-Support-Articles/Qlik-Sense-QRS-API-using-Xrfkey-header-in-PowerShell/ta-p/1716660&lt;BR /&gt;&lt;/A&gt;we have to connect using the Method 2, having the certificate exported and installed as indicated in&lt;BR /&gt;&lt;A href="https://community.qlik.com/t5/Official-Support-Articles/Export-client-certificate-and-root-certificate-to-make-API-calls/ta-p/1715515" target="_blank" rel="noopener"&gt;https://community.qlik.com/t5/Official-Support-Articles/Export-client-certificate-and-root-certificate-to-make-API-calls/ta-p/1715515&lt;/A&gt;&lt;BR /&gt;and with port 4242 of server A open (verified by testing the telnet statement on server B indicated at&lt;BR /&gt;&lt;A href="https://superuser.com/questions/339107/how-to-telnet-to-an-ip-address-on-a-specific-port%0b" target="_blank" rel="noopener"&gt;https://superuser.com/questions/339107/how-to-telnet-to-an-ip-address-on-a-specific-port&lt;BR /&gt;&lt;/A&gt;) if we execute the following program through the console in administrator mode:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;$Provider=New-Object Microsoft.CSharp.CSharpCodeProvider
$Compiler=$Provider.CreateCompiler()
$Params=New-Object System.CodeDom.Compiler.CompilerParameters
$Params.GenerateExecutable=$False
$Params.GenerateInMemory=$True
$Params.IncludeDebugInformation=$False
$Params.ReferencedAssemblies.Add("System.DLL") | Out-Null

$TASource=@'
  namespace Local.ToolkitExtensions.Net.CertificatePolicy{
    public class TrustAll : System.Net.ICertificatePolicy {
      public TrustAll() {
      }
      public bool CheckValidationResult(System.Net.ServicePoint sp,
        System.Security.Cryptography.X509Certificates.X509Certificate cert,
        System.Net.WebRequest req, int problem) {
        return true;
      }
    }
  }
'@
$TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource)
$TAAssembly=$TAResults.CompiledAssembly

## We now create an instance of the TrustAll and attach it to the ServicePointManager
$TrustAll=$TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")
[System.Net.ServicePointManager]::CertificatePolicy=$TrustAll

$hdrs=@{}
$hdrs.Add("X-Qlik-xrfkey","12345678qwertyui")
$hdrs.Add("X-Qlik-User","UserDirectory=internal;UserId=sa_repository")
$hdrs.Add("Content-Type","application/json")
$cert = Get-ChildItem -Path "Cert:\LocalMachine\Root"| Where {$_.Subject -like '*Eagle.uvedom*'}
write $cert
$url=https://urlserverA:4242/qrs/license/analyzeraccesstype/full?xrfkey=12345678qwertyui
$response=Invoke-RestMethod -Uri $url -Method Get -Headers $hdrs -UseDefaultCredentials -Certificate $cert
$content=$response
write $ content
       
$url= https:// urlserverA:4242/qrs/task/start/synchronous?name=TaskTest&amp;amp;xrfkey=12345678qwertyui
$response=Invoke-RestMethod -Uri $url -Method Post -Headers $hdrs -UseDefaultCredentials -Certificate $cert
$ content =$response.value

&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;The execution is this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="eric_careta_1-1676140853384.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/100290i1307CF216BFF0849/image-size/medium?v=v2&amp;amp;px=400" role="button" title="eric_careta_1-1676140853384.png" alt="eric_careta_1-1676140853384.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;Invoke-restmethod: The remote server returned an error: (403) Forbidden.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;What could be happening?&lt;/P&gt;</description>
    <pubDate>Sat, 11 Feb 2023 18:42:32 GMT</pubDate>
    <dc:creator>eric_careta</dc:creator>
    <dc:date>2023-02-11T18:42:32Z</dc:date>
    <item>
      <title>Trouble send direct request to Repository API</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Trouble-send-direct-request-to-Repository-API/m-p/2036847#M18095</link>
      <description>&lt;P&gt;Hi everyone,&lt;BR /&gt;&lt;BR /&gt;We have a server with Qlik Sense installed (A) and another server (B) from which we want to run a powershell program that performs instructions from server A with the qrs API.&lt;/P&gt;
&lt;P&gt;The problem is that we can't connect using the certificate and sending a direct request to the repository API.&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;Following the steps described in &lt;A href="https://community.qlik.com/t5/Official-Support-Articles/Qlik-Sense-QRS-API-using-Xrfkey-header-in-PowerShell/ta-p/1716660" target="_blank" rel="noopener"&gt;https://community.qlik.com/t5/Official-Support-Articles/Qlik-Sense-QRS-API-using-Xrfkey-header-in-PowerShell/ta-p/1716660&lt;BR /&gt;&lt;/A&gt;we have to connect using the Method 2, having the certificate exported and installed as indicated in&lt;BR /&gt;&lt;A href="https://community.qlik.com/t5/Official-Support-Articles/Export-client-certificate-and-root-certificate-to-make-API-calls/ta-p/1715515" target="_blank" rel="noopener"&gt;https://community.qlik.com/t5/Official-Support-Articles/Export-client-certificate-and-root-certificate-to-make-API-calls/ta-p/1715515&lt;/A&gt;&lt;BR /&gt;and with port 4242 of server A open (verified by testing the telnet statement on server B indicated at&lt;BR /&gt;&lt;A href="https://superuser.com/questions/339107/how-to-telnet-to-an-ip-address-on-a-specific-port%0b" target="_blank" rel="noopener"&gt;https://superuser.com/questions/339107/how-to-telnet-to-an-ip-address-on-a-specific-port&lt;BR /&gt;&lt;/A&gt;) if we execute the following program through the console in administrator mode:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;$Provider=New-Object Microsoft.CSharp.CSharpCodeProvider
$Compiler=$Provider.CreateCompiler()
$Params=New-Object System.CodeDom.Compiler.CompilerParameters
$Params.GenerateExecutable=$False
$Params.GenerateInMemory=$True
$Params.IncludeDebugInformation=$False
$Params.ReferencedAssemblies.Add("System.DLL") | Out-Null

$TASource=@'
  namespace Local.ToolkitExtensions.Net.CertificatePolicy{
    public class TrustAll : System.Net.ICertificatePolicy {
      public TrustAll() {
      }
      public bool CheckValidationResult(System.Net.ServicePoint sp,
        System.Security.Cryptography.X509Certificates.X509Certificate cert,
        System.Net.WebRequest req, int problem) {
        return true;
      }
    }
  }
'@
$TAResults=$Provider.CompileAssemblyFromSource($Params,$TASource)
$TAAssembly=$TAResults.CompiledAssembly

## We now create an instance of the TrustAll and attach it to the ServicePointManager
$TrustAll=$TAAssembly.CreateInstance("Local.ToolkitExtensions.Net.CertificatePolicy.TrustAll")
[System.Net.ServicePointManager]::CertificatePolicy=$TrustAll

$hdrs=@{}
$hdrs.Add("X-Qlik-xrfkey","12345678qwertyui")
$hdrs.Add("X-Qlik-User","UserDirectory=internal;UserId=sa_repository")
$hdrs.Add("Content-Type","application/json")
$cert = Get-ChildItem -Path "Cert:\LocalMachine\Root"| Where {$_.Subject -like '*Eagle.uvedom*'}
write $cert
$url=https://urlserverA:4242/qrs/license/analyzeraccesstype/full?xrfkey=12345678qwertyui
$response=Invoke-RestMethod -Uri $url -Method Get -Headers $hdrs -UseDefaultCredentials -Certificate $cert
$content=$response
write $ content
       
$url= https:// urlserverA:4242/qrs/task/start/synchronous?name=TaskTest&amp;amp;xrfkey=12345678qwertyui
$response=Invoke-RestMethod -Uri $url -Method Post -Headers $hdrs -UseDefaultCredentials -Certificate $cert
$ content =$response.value

&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;The execution is this:&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="eric_careta_1-1676140853384.png" style="width: 400px;"&gt;&lt;img src="https://community.qlik.com/t5/image/serverpage/image-id/100290i1307CF216BFF0849/image-size/medium?v=v2&amp;amp;px=400" role="button" title="eric_careta_1-1676140853384.png" alt="eric_careta_1-1676140853384.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&lt;FONT color="#FF0000"&gt;Invoke-restmethod: The remote server returned an error: (403) Forbidden.&lt;/FONT&gt;&lt;/P&gt;
&lt;P&gt;What could be happening?&lt;/P&gt;</description>
      <pubDate>Sat, 11 Feb 2023 18:42:32 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Trouble-send-direct-request-to-Repository-API/m-p/2036847#M18095</guid>
      <dc:creator>eric_careta</dc:creator>
      <dc:date>2023-02-11T18:42:32Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble send direct request to Repository API</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Trouble-send-direct-request-to-Repository-API/m-p/2037358#M18103</link>
      <description>&lt;P&gt;The issue with the above is the certificate you are using. The Subject on the certificate indicates that it is the Qlik Sense Root CA Certificate, you need to use the one with the subject "CN=QlikClient" as per the community post you referenced.&lt;/P&gt;
&lt;PRE class="ckeditor_codeblock"&gt;$cert = Get-ChildItem -Path "Cert:\CurrentUser\My" | Where {$_.Subject -like '*QlikClient*'}&lt;/PRE&gt;
&lt;P&gt;&amp;nbsp;then there is a whole lot of code for Provider, Compiler etc that seems overly complex.&lt;/P&gt;
&lt;P&gt;and your "Invoke-RestMethod" calls are trying to use the certificate &amp;amp; provide default credentials (-UseDefaultCredentials)&lt;/P&gt;
&lt;P&gt;&lt;BR /&gt;Have a look at the following, this should do what you are after.&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;if (-not ([System.Management.Automation.PSTypeName]'TrustAllCertsPolicy').Type) {
    Add-Type @"
using System.Net;
using System.Security.Cryptography.X509Certificates;
public class TrustAllCertsPolicy : ICertificatePolicy {
    public bool CheckValidationResult(
    ServicePoint srvPoint, X509Certificate certificate,
    WebRequest request, int certificateProblem) {
    return true;
    }
}
"@
}
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

##Cert should be in a Personal Store (either CurrentUser or LocalMachine)\My
#$cert = Get-ChildItem -Path "Cert:\CurrentUser\My" | Where-Object {$_.Subject -eq 'CN=QlikClient'}
#If you have more that one Sense Environment Certificate
$cert = Get-ChildItem -Path "Cert:\LocalMachine\My" | Where-Object{$_.Subject -eq 'CN=QlikClient' -and $_.Issuer -like '*Eagle.uvedom*'}|Sort-Object -Property NotAfter -Descending|Select-Object -First 1
Write-Output $cert

$XRFKey = '12345678qwertyui'
$hdrs=@{}
$hdrs.Add("X-Qlik-xrfkey","$($XRFKey)")
$hdrs.Add("X-Qlik-User","UserDirectory=internal;UserId=sa_repository")
$hdrs.Add("Content-Type","application/json")

$url="https://urlserverA:4242/qrs/license/analyzeraccesstype/full?xrfkey=$($XRFKey)"
$response=Invoke-RestMethod -Uri $url -Method Get -Headers $hdrs -Certificate $cert
$content=$response
Write-Output $content



&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;As an alternative, you could use one of the existing PowerShell modules designed to communicate with the QRS APIs&lt;/P&gt;
&lt;P&gt;&lt;A href="https://github.com/QlikProfessionalServices/QlikSenseCLI" target="_blank" rel="noopener"&gt;QlikSenseCLI&lt;/A&gt;&amp;nbsp;or&amp;nbsp;&lt;A href="https://github.com/ahaydon/Qlik-Cli-Windows" target="_blank" rel="noopener"&gt;Qlik-Cli-Windows&lt;/A&gt;&amp;nbsp;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;both of which can be installed by simply running the command&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;Install-Module QlikSenseCLI -Scope CurrentUser
#or
Install-Module Qlik-CLI -Scope CurrentUser&lt;/LI-CODE&gt;</description>
      <pubDate>Mon, 13 Feb 2023 22:48:52 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Trouble-send-direct-request-to-Repository-API/m-p/2037358#M18103</guid>
      <dc:creator>Marc</dc:creator>
      <dc:date>2023-02-13T22:48:52Z</dc:date>
    </item>
    <item>
      <title>Re: Trouble send direct request to Repository API</title>
      <link>https://community.qlik.com/t5/Integration-Extension-APIs/Trouble-send-direct-request-to-Repository-API/m-p/2038144#M18113</link>
      <description>&lt;P&gt;I've tried to import certificate with QlikClient subject and it works.&lt;BR /&gt;&lt;BR /&gt;The initial problem it was I have another qlik certificate of another server and it collapse with the new one. I change the installation directory of the new one with the subject of QlikClient and it works!&lt;BR /&gt;&lt;BR /&gt;Thanks a lot&amp;nbsp;&lt;a href="https://community.qlik.com/t5/user/viewprofilepage/user-id/29458"&gt;@Marc&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;Cheers&lt;/P&gt;</description>
      <pubDate>Wed, 15 Feb 2023 10:10:22 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Integration-Extension-APIs/Trouble-send-direct-request-to-Repository-API/m-p/2038144#M18113</guid>
      <dc:creator>eric_careta</dc:creator>
      <dc:date>2023-02-15T10:10:22Z</dc:date>
    </item>
  </channel>
</rss>

