<?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 Re: Rest API concurrent sessions usage in PAM Self-Hosted Discussions</title>
    <link>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/rest-api-concurrent-sessions-usage/m-p/1355371#M46000</link>
    <description>&lt;P&gt;So I presume using `-ThrottleLimit 1` also works?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am not sure of your need for a parallel loop to complete a simple query of accounts, but if you just authenticated once outside of the loop, it would likely suffice.&lt;/P&gt;&lt;P&gt;i.e.&lt;/P&gt;&lt;CODE&gt;$lbody = "{`n`"concurrentSessions`": `"true`"`n}"
&amp;nbsp;
$LoginrequestTokens = Invoke-RestMethod https://&amp;lt;hostname&amp;gt;/PasswordVault/API/auth/Windows/Logon -UseDefaultCredentials -Method Post -Body $lbody
&amp;nbsp;
Write-Host $LoginrequestTokens
&amp;nbsp;
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
&amp;nbsp;
$headers.Add("Content-Type", "application/json")
&amp;nbsp;
$headers.Add("Authorization", $LoginrequestTokens)
&amp;nbsp;
1..2 | ForEach-Object -Parallel {
&amp;nbsp;
    $response = Invoke-RestMethod 'https://&amp;lt;hostname&amp;gt;/PasswordVault/api/Accounts?search=&amp;lt;keyword&amp;gt;&amp;amp;searchType=contains&amp;amp;limit=1' -Method 'GET' -Headers $($using:headers)
&amp;nbsp;
    $id=$response.value.id
&amp;nbsp;
    WRITE-HOST $id
&amp;nbsp;
} -ThrottleLimit 2
&amp;nbsp;
$Logoff = Invoke-RestMethod https://&amp;lt;hostname&amp;gt;/PasswordVault/API/auth/Logoff -Method POST -Headers $headers&lt;/CODE&gt;&lt;P&gt; Given the significant processing overhead this type of parallel loop has, and also the potential load this could introduce in terms of vault tasks depending on how your environment is configured, you should keep a close eye on performance - both of the script and the vault.&lt;/P&gt;</description>
    <pubDate>Tue, 15 Jun 2021 23:42:59 GMT</pubDate>
    <dc:creator>CyberArkAlumni</dc:creator>
    <dc:date>2021-06-15T23:42:59Z</dc:date>
    <item>
      <title>Rest API concurrent sessions usage</title>
      <link>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/rest-api-concurrent-sessions-usage/m-p/1355365#M45994</link>
      <description>&lt;P&gt;Hello Community,&lt;/P&gt;&lt;P&gt;I am looking to get help with using concurrent sessions feature of the the Rest API in Powershell 7 . I am able to produce multiple authentication tokens by setting the concurrentSessions parameter to True but I get an error when I pass these auth tokens to account search API URL using the ForEach-Object -Parallel feature in PS7. Here is my PS code:&lt;/P&gt;&lt;P&gt;1..2 | ForEach-Object -Parallel {&lt;/P&gt;&lt;P&gt;$lbody = "{`n`"concurrentSessions`": `"true`"`n}"&lt;/P&gt;&lt;P&gt;$LoginrequestTokens = Invoke-RestMethod https://&amp;lt;hostname&amp;gt;/PasswordVault/API/auth/Windows/Logon -UseDefaultCredentials -Method Post -Body $lbody&lt;/P&gt;&lt;P&gt;Write-Host $LoginrequestTokens&lt;/P&gt;&lt;P&gt;$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"&lt;/P&gt;&lt;P&gt;$headers.Add("Content-Type", "application/json")&lt;/P&gt;&lt;P&gt;$headers.Add("Authorization", $LoginrequestTokens)&lt;/P&gt;&lt;P&gt;$response = Invoke-RestMethod 'https://&amp;lt;hostname&amp;gt;/PasswordVault/api/Accounts?search=&amp;lt;keyword&amp;gt;&amp;amp;searchType=contains&amp;amp;limit=1' -Method 'GET' -Headers $headers&lt;/P&gt;&lt;P&gt;$id=$&lt;A alt="http://response.value.id/" href="http://response.value.id/" target="_blank"&gt;response.value.id&lt;/A&gt;&lt;/P&gt;&lt;P&gt;WRITE-HOST $id&lt;/P&gt;&lt;P&gt;$Logoff = Invoke-RestMethod https://&amp;lt;hostname&amp;gt;/PasswordVault/API/auth/Logoff -Method POST -Headers $headers&lt;/P&gt;&lt;P&gt;Write-Host $Logoff&lt;/P&gt;&lt;P&gt;} -ThrottleLimit 2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is the error:&lt;/P&gt;&lt;P&gt;YWU5NTkwN2UtMTY4OC00ZDlmLTgyZTAtZThkYzljNTM0ZTBhO0ZBMDdBODFCMEM0N0QwMEI7MDAwMDAwMDIxMzA4QUEwNjUyNjZBOUZFREUwMjhCMDU4NTMyM0I0NDc0NDc3NzE0Qzg0RTEzMUZDOEUxODIwRDExOTA3RDZFMDAwMDAwMDA7&lt;/P&gt;&lt;P&gt;ODU2NDA1NTQtYmU4My00NWQyLTlmOTctMzJlZGVlZjA4NzhkOzAxODgyNUNGQzBFQUQ4M0Q7MDAwMDAwMDJGMzc0NENFQjcxNTM2MTJFOEU2NDIwQTIzNTQ3OUVEOTQxQjQ2RDJCRDQ4MDZFRjMxMjU0MjU0QTJDRjM2RkI3MDAwMDAwMDA7&lt;/P&gt;&lt;P&gt;Invoke-RestMethod:&lt;/P&gt;&lt;P&gt;Line |&lt;/P&gt;&lt;P&gt;8 | … $response = Invoke-RestMethod 'https://&amp;lt;host&amp;gt;/PasswordVault/ap …&lt;/P&gt;&lt;P&gt;| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;/P&gt;&lt;P&gt;| {"ErrorCode":"ITACM040S","ErrorMessage":"User was automatically logged off from Vault (Diagnostic information: 540).\n\nLogoff from the Vault and logon again."}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;@{LogoffUrl=}&lt;/P&gt;&lt;P&gt;Invoke-RestMethod:&lt;/P&gt;&lt;P&gt;Line |&lt;/P&gt;&lt;P&gt;8 | … $response = Invoke-RestMethod 'https://&amp;lt;host&amp;gt;/PasswordVault/ap …&lt;/P&gt;&lt;P&gt;| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~&lt;/P&gt;&lt;P&gt;| {"ErrorCode":"ITACM040S","ErrorMessage":"User was automatically logged off from Vault (Diagnostic information: 540).\n\nLogoff from the Vault and logon again."}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;@{LogoffUrl=}&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I think the issue here is usage of incorrect authentication token in subsequent API calls which is ending the session abruptly? Would appreciate some tips on how to handle multiple authentication tokens.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;/P&gt;&lt;P&gt;Pooja&lt;/P&gt;</description>
      <pubDate>Mon, 14 Jun 2021 21:08:17 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/rest-api-concurrent-sessions-usage/m-p/1355365#M45994</guid>
      <dc:creator>CyberArkAlumni</dc:creator>
      <dc:date>2021-06-14T21:08:17Z</dc:date>
    </item>
    <item>
      <title>Re: Rest API concurrent sessions usage</title>
      <link>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/rest-api-concurrent-sessions-usage/m-p/1355366#M45995</link>
      <description>&lt;P&gt;Disregarding the parallel loop for now:&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;do your commands run without issue independently? i.e. can you authenticate, provide the auth token and query accounts successfully?&lt;/LI&gt;&lt;LI&gt;can you use the separate (concurrentSessions) auth tokens to get results successfully?&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Jun 2021 22:30:21 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/rest-api-concurrent-sessions-usage/m-p/1355366#M45995</guid>
      <dc:creator>CyberArkAlumni</dc:creator>
      <dc:date>2021-06-14T22:30:21Z</dc:date>
    </item>
    <item>
      <title>Re: Rest API concurrent sessions usage</title>
      <link>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/rest-api-concurrent-sessions-usage/m-p/1355367#M45996</link>
      <description>&lt;P&gt;Hi Pete - See my answers below&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;do your commands run without issue independently? i.e. can you authenticate, provide the auth token and query accounts successfully?&lt;/LI&gt;&lt;/OL&gt;&lt;UL&gt;&lt;LI&gt;Yes. With no loop, I get the token and able to query accounts with it&lt;/LI&gt;&lt;/UL&gt;&lt;P&gt;$lbody = "{`n`"concurrentSessions`": `"true`"`n}"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$LoginrequestTokens = Invoke-RestMethod &lt;A alt="https://%3Chost%3E/PasswordVault/API/auth/Windows/Logon" href="https://%3Chost%3E/PasswordVault/API/auth/Windows/Logon" target="_blank"&gt;https://&amp;lt;host&amp;gt;/PasswordVault/API/auth/Windows/Logon&lt;/A&gt; -UseDefaultCredentials -Method Post&amp;nbsp;-Body $lbody&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Write-Host $LoginrequestTokens&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$headers.Add("Content-Type", "application/json")&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$headers.Add("Authorization", $LoginrequestTokens)&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$response = Invoke-RestMethod '&lt;A alt="https://%3Chost%3E/PasswordVault/api/Accounts?search=%3Ckeyword%3EsearchType=contains&amp;amp;limit=1" href="https://%3Chost%3E/PasswordVault/api/Accounts?search=%3Ckeyword%3EsearchType=contains&amp;amp;limit=1" target="_blank"&gt;https://&amp;lt;host&amp;gt;/PasswordVault/api/Accounts?search=&amp;lt;keyword&amp;gt;searchType=contains&amp;amp;limit=1&lt;/A&gt;' -Method 'GET' -Headers $headers&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;$id=$&lt;A alt="http://response.value.id" href="http://response.value.id" target="_blank"&gt;response.value.id&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;WRITE-HOST $id&lt;/P&gt;&lt;P&gt; $Logoff = Invoke-RestMethod &lt;A alt="https://swpausexife01/PasswordVault/API/auth/Logoff" href="https://swpausexife01/PasswordVault/API/auth/Logoff" target="_blank"&gt;https://&amp;lt;host&amp;gt;/PasswordVault/API/auth/Logoff&lt;/A&gt; -Method POST -Headers $headers&lt;/P&gt;&lt;P&gt;Write-Host $Logoff&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;OL&gt;&lt;LI&gt;can you use the separate (concurrentSessions) auth tokens to get results successfully?&lt;/LI&gt;&lt;/OL&gt;&lt;P&gt;Sorry I'm not a powershell expert, not sure how to test this quickly. I can try to get back to you tomorrow on this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks for your response!&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 14 Jun 2021 23:00:57 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/rest-api-concurrent-sessions-usage/m-p/1355367#M45996</guid>
      <dc:creator>CyberArkAlumni</dc:creator>
      <dc:date>2021-06-14T23:00:57Z</dc:date>
    </item>
    <item>
      <title>Re: Rest API concurrent sessions usage</title>
      <link>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/rest-api-concurrent-sessions-usage/m-p/1355368#M45997</link>
      <description>&lt;P&gt;Actually, on your 2nd question, do you mean the authentication tokens generated by the parallel loop are valid outside of the loop? Not sure how I would generate concurrent sessions without using parallel loop (or parallel logins)?&lt;/P&gt;</description>
      <pubDate>Mon, 14 Jun 2021 23:20:00 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/rest-api-concurrent-sessions-usage/m-p/1355368#M45997</guid>
      <dc:creator>CyberArkAlumni</dc:creator>
      <dc:date>2021-06-14T23:20:00Z</dc:date>
    </item>
    <item>
      <title>Re: Rest API concurrent sessions usage</title>
      <link>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/rest-api-concurrent-sessions-usage/m-p/1355369#M45998</link>
      <description>&lt;P&gt;well, just run the commands sequentially and set relevant variables:&lt;/P&gt;&lt;P&gt;$LoginrequestToken1&lt;/P&gt;&lt;P&gt;$Header1&lt;/P&gt;&lt;P&gt;$LoginrequestToken2&lt;/P&gt;&lt;P&gt;$Header2&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then you can test commands using both auth tokens and confirm validity.&lt;/P&gt;</description>
      <pubDate>Mon, 14 Jun 2021 23:29:37 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/rest-api-concurrent-sessions-usage/m-p/1355369#M45998</guid>
      <dc:creator>CyberArkAlumni</dc:creator>
      <dc:date>2021-06-14T23:29:37Z</dc:date>
    </item>
    <item>
      <title>Re: Rest API concurrent sessions usage</title>
      <link>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/rest-api-concurrent-sessions-usage/m-p/1355370#M45999</link>
      <description>&lt;P&gt;Hi @Pete Maan​&amp;nbsp; ,&lt;/P&gt;&lt;P&gt;Yes, the tokens in sequential commands work&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jun 2021 21:55:10 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/rest-api-concurrent-sessions-usage/m-p/1355370#M45999</guid>
      <dc:creator>CyberArkAlumni</dc:creator>
      <dc:date>2021-06-15T21:55:10Z</dc:date>
    </item>
    <item>
      <title>Re: Rest API concurrent sessions usage</title>
      <link>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/rest-api-concurrent-sessions-usage/m-p/1355371#M46000</link>
      <description>&lt;P&gt;So I presume using `-ThrottleLimit 1` also works?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Am not sure of your need for a parallel loop to complete a simple query of accounts, but if you just authenticated once outside of the loop, it would likely suffice.&lt;/P&gt;&lt;P&gt;i.e.&lt;/P&gt;&lt;CODE&gt;$lbody = "{`n`"concurrentSessions`": `"true`"`n}"
&amp;nbsp;
$LoginrequestTokens = Invoke-RestMethod https://&amp;lt;hostname&amp;gt;/PasswordVault/API/auth/Windows/Logon -UseDefaultCredentials -Method Post -Body $lbody
&amp;nbsp;
Write-Host $LoginrequestTokens
&amp;nbsp;
$headers = New-Object "System.Collections.Generic.Dictionary[[String],[String]]"
&amp;nbsp;
$headers.Add("Content-Type", "application/json")
&amp;nbsp;
$headers.Add("Authorization", $LoginrequestTokens)
&amp;nbsp;
1..2 | ForEach-Object -Parallel {
&amp;nbsp;
    $response = Invoke-RestMethod 'https://&amp;lt;hostname&amp;gt;/PasswordVault/api/Accounts?search=&amp;lt;keyword&amp;gt;&amp;amp;searchType=contains&amp;amp;limit=1' -Method 'GET' -Headers $($using:headers)
&amp;nbsp;
    $id=$response.value.id
&amp;nbsp;
    WRITE-HOST $id
&amp;nbsp;
} -ThrottleLimit 2
&amp;nbsp;
$Logoff = Invoke-RestMethod https://&amp;lt;hostname&amp;gt;/PasswordVault/API/auth/Logoff -Method POST -Headers $headers&lt;/CODE&gt;&lt;P&gt; Given the significant processing overhead this type of parallel loop has, and also the potential load this could introduce in terms of vault tasks depending on how your environment is configured, you should keep a close eye on performance - both of the script and the vault.&lt;/P&gt;</description>
      <pubDate>Tue, 15 Jun 2021 23:42:59 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/pam-self-hosted-discussions/rest-api-concurrent-sessions-usage/m-p/1355371#M46000</guid>
      <dc:creator>CyberArkAlumni</dc:creator>
      <dc:date>2021-06-15T23:42:59Z</dc:date>
    </item>
  </channel>
</rss>

