<?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>article Qlik Cloud: Call Qlik APIs using JWT authentication (PowerShell) in Official Support Articles</title>
    <link>https://community.qlik.com/t5/Official-Support-Articles/Qlik-Cloud-Call-Qlik-APIs-using-JWT-authentication-PowerShell/ta-p/2467423</link>
    <description>&lt;P&gt;This is a sample of how to call the Qlik Cloud APIs to assign an Analyzer license to a user with PowerShell/JWT authentication.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H4&gt;&lt;FONT color="#339966"&gt;Environment&lt;/FONT&gt;&lt;/H4&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;LI-PRODUCT title="Qlik Cloud" id="qlikSenseEnterpriseSaaS"&gt;&lt;/LI-PRODUCT&gt;&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3&gt;&lt;FONT color="#339966"&gt;&lt;STRONG&gt;Resolution&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/H3&gt;
&lt;P&gt;In order to call Qlik Cloud API with JWT authentication, the first step is to call &lt;FONT face="courier new,courier"&gt;POST /login/jwt-session&lt;/FONT&gt;&amp;nbsp;to get the necessary cookies. Which API can be called depends on the privileges the JWT user has been assigned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$hdrs = @{}
# Put your JWT token here
$hdrs.Add("Authorization","Bearer eyJhbGciOiJSU...pgacN8QqAjKug")
$url = "https://tenant.ap.qlikcloud.com/login/jwt-session"
$resp = Invoke-WebRequest -Uri $url -Method Post -ContentType 'application/json' -Headers $hdrs

#Fetch all required cookies
$AWSALB= [Regex]::Matches($resp.RawContent, "(?&amp;lt;=AWSALB\=).+?(?=; Expires)")
$AWSALBCORS= [Regex]::Matches($resp.RawContent, "(?&amp;lt;=AWSALBCORS\=).+?(?=; Expires)")
$eassid= [Regex]::Matches($resp.RawContent, "(?&amp;lt;=eas.sid\=).+?(?=; path)")
$eassidsig= [Regex]::Matches($resp.RawContent, "(?&amp;lt;=eas.sid.sig\=).+?(?=; path)")
$csrftoken= [Regex]::Matches($resp.RawContent, "(?&amp;lt;=_csrfToken\=).+?(?=; path)")
$csrftokensig= [Regex]::Matches($resp.RawContent, "(?&amp;lt;=_csrfToken.sig\=).+?(?=; path)")

$allCookies = "AWSALB="+$AWSALB.Value+";AWSALBCORS="+$AWSALBCORS.Value+";eas.sid="+$eassid.Value+";eas.sid.sig="+$eassidsig.Value+";_csrfToken="+$csrftoken.Value+";_csrfToken.sig="+$csrftokensig.Value

$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession

foreach ($cookiePair in $allCookies.Split((";"))) {
  $cookieValues = $cookiePair.Trim().Split("=")
  $cookie = New-Object System.Net.Cookie
  $cookie.Name = $cookieValues[0]
  $cookie.Value = $cookieValues[1]
  $cookie.Domain = "tenant.ap.qlikcloud.com"
  $session.Cookies.Add($cookie);
}

$hdrs = @{}
#Request that modify content such as POST/PATCH requests need the Qlik-Csrf-Token header
$hdrs.Add("Qlik-Csrf-Token",$csrftoken.value)

$body = '{"add":[{"subject":"DOMAIN\\user1","type":"analyzer"}]}'

$url = "https://tenant.ap.qlikcloud.com/api/v1/licenses/assignments/actions/add"
Invoke-RestMethod -Uri $url -Method Post -Headers $hdrs -Body $body -WebSession $session&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 03 Jul 2024 05:38:01 GMT</pubDate>
    <dc:creator>Damien_V</dc:creator>
    <dc:date>2024-07-03T05:38:01Z</dc:date>
    <item>
      <title>Qlik Cloud: Call Qlik APIs using JWT authentication (PowerShell)</title>
      <link>https://community.qlik.com/t5/Official-Support-Articles/Qlik-Cloud-Call-Qlik-APIs-using-JWT-authentication-PowerShell/ta-p/2467423</link>
      <description>&lt;P&gt;This is a sample of how to call the Qlik Cloud APIs to assign an Analyzer license to a user with PowerShell/JWT authentication.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H4&gt;&lt;FONT color="#339966"&gt;Environment&lt;/FONT&gt;&lt;/H4&gt;
&lt;UL&gt;
&lt;LI&gt;&lt;LI-PRODUCT title="Qlik Cloud" id="qlikSenseEnterpriseSaaS"&gt;&lt;/LI-PRODUCT&gt;&amp;nbsp;&lt;/LI&gt;
&lt;/UL&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;H3&gt;&lt;FONT color="#339966"&gt;&lt;STRONG&gt;Resolution&lt;/STRONG&gt;&lt;/FONT&gt;&lt;/H3&gt;
&lt;P&gt;In order to call Qlik Cloud API with JWT authentication, the first step is to call &lt;FONT face="courier new,courier"&gt;POST /login/jwt-session&lt;/FONT&gt;&amp;nbsp;to get the necessary cookies. Which API can be called depends on the privileges the JWT user has been assigned.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="csharp"&gt;[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12

$hdrs = @{}
# Put your JWT token here
$hdrs.Add("Authorization","Bearer eyJhbGciOiJSU...pgacN8QqAjKug")
$url = "https://tenant.ap.qlikcloud.com/login/jwt-session"
$resp = Invoke-WebRequest -Uri $url -Method Post -ContentType 'application/json' -Headers $hdrs

#Fetch all required cookies
$AWSALB= [Regex]::Matches($resp.RawContent, "(?&amp;lt;=AWSALB\=).+?(?=; Expires)")
$AWSALBCORS= [Regex]::Matches($resp.RawContent, "(?&amp;lt;=AWSALBCORS\=).+?(?=; Expires)")
$eassid= [Regex]::Matches($resp.RawContent, "(?&amp;lt;=eas.sid\=).+?(?=; path)")
$eassidsig= [Regex]::Matches($resp.RawContent, "(?&amp;lt;=eas.sid.sig\=).+?(?=; path)")
$csrftoken= [Regex]::Matches($resp.RawContent, "(?&amp;lt;=_csrfToken\=).+?(?=; path)")
$csrftokensig= [Regex]::Matches($resp.RawContent, "(?&amp;lt;=_csrfToken.sig\=).+?(?=; path)")

$allCookies = "AWSALB="+$AWSALB.Value+";AWSALBCORS="+$AWSALBCORS.Value+";eas.sid="+$eassid.Value+";eas.sid.sig="+$eassidsig.Value+";_csrfToken="+$csrftoken.Value+";_csrfToken.sig="+$csrftokensig.Value

$session = New-Object Microsoft.PowerShell.Commands.WebRequestSession

foreach ($cookiePair in $allCookies.Split((";"))) {
  $cookieValues = $cookiePair.Trim().Split("=")
  $cookie = New-Object System.Net.Cookie
  $cookie.Name = $cookieValues[0]
  $cookie.Value = $cookieValues[1]
  $cookie.Domain = "tenant.ap.qlikcloud.com"
  $session.Cookies.Add($cookie);
}

$hdrs = @{}
#Request that modify content such as POST/PATCH requests need the Qlik-Csrf-Token header
$hdrs.Add("Qlik-Csrf-Token",$csrftoken.value)

$body = '{"add":[{"subject":"DOMAIN\\user1","type":"analyzer"}]}'

$url = "https://tenant.ap.qlikcloud.com/api/v1/licenses/assignments/actions/add"
Invoke-RestMethod -Uri $url -Method Post -Headers $hdrs -Body $body -WebSession $session&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Jul 2024 05:38:01 GMT</pubDate>
      <guid>https://community.qlik.com/t5/Official-Support-Articles/Qlik-Cloud-Call-Qlik-APIs-using-JWT-authentication-PowerShell/ta-p/2467423</guid>
      <dc:creator>Damien_V</dc:creator>
      <dc:date>2024-07-03T05:38:01Z</dc:date>
    </item>
  </channel>
</rss>

