<?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: Using XSOAR API Stoplight in Cortex XSOAR Discussions</title>
    <link>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/using-xsoar-api-stoplight/m-p/599694#M3677</link>
    <description>&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;- You need to use the server API URL from the API-keys page.(&lt;A href="https://api-{fqdn}/xsoar/public/v1/{endpoint_path}" target="_blank"&gt;https://api-{fqdn}/xsoar/public/v1/{endpoint_path}&lt;/A&gt;)&lt;BR /&gt;- Mind this from the docs: '&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;Choose the type of API Key you want to generate based on your desired security level:&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG style="font-family: inherit;"&gt;Advanced&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;or&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG style="font-family: inherit;"&gt;Standard&lt;/STRONG&gt;&lt;SPAN&gt;. The Advanced API key hashes the key using a nonce, a random string, and a timestamp to prevent replay attacks. cURL does not support this but is suitable with scripts. Use the example script to create the advanced API authentication token."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;So, test with an std key using curl:&amp;nbsp;curl -X POST &lt;A href="https://api-your-xsoar.us.paloaltonetworks.com/api_keys/validate/" target="_blank"&gt;https://api-your-xsoar.us.paloaltonetworks.com/api_keys/validate/&lt;/A&gt; -H "x-xdr-auth-id:{api_key_id}" -H "Authorization:{api_key}" -H "Content-Type:application/json" -d '{}'&lt;BR /&gt;For an advanced API key:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;from datetime import datetime, timezone
import secrets
import string
import hashlib
import requests

def test_advanced_authentication(api_key_id, api_key):
    # Generate a 64 bytes random string
    nonce = "".join([secrets.choice(string.ascii_letters + string.digits) for _ in range(64)])
    # Get the current timestamp as milliseconds.
    timestamp = int(datetime.now(timezone.utc).timestamp()) * 1000
    # Generate the auth key:
    auth_key = "%s%s%s" % (api_key, nonce, timestamp)
    # Convert to bytes object
    auth_key = auth_key.encode("utf-8")
    # Calculate sha256:
    api_key_hash = hashlib.sha256(auth_key).hexdigest()
    # Generate HTTP call headers
    headers = {
        "x-xdr-timestamp": str(timestamp),
        "x-xdr-nonce": nonce,
        "x-xdr-auth-id": str(api_key_id),
        "Authorization": api_key_hash
    }
    parameters = {}
    res = requests.post(url="https://api-your-xsoar.us.paloaltonetworks.com/api_keys/validate/",
                        headers=headers,
                        json=parameters)
    return res&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 07 Oct 2024 12:12:51 GMT</pubDate>
    <dc:creator>ctopay</dc:creator>
    <dc:date>2024-10-07T12:12:51Z</dc:date>
    <item>
      <title>Using XSOAR API Stoplight</title>
      <link>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/using-xsoar-api-stoplight/m-p/599478#M3668</link>
      <description>&lt;P&gt;Anyone tried with Stoplight XSOAR 8 API.&lt;/P&gt;
&lt;P&gt;I am trying the APIs listed&amp;nbsp;&lt;A href="https://cortex-panw.stoplight.io/docs/cortex-xsoar-8/kjn2q21a7yrbm-get-started-with-cortex-xsoar-8-ap-is" target="_blank"&gt;https://cortex-panw.stoplight.io/docs/cortex-xsoar-8/kjn2q21a7yrbm-get-started-with-cortex-xsoar-8-ap-is&lt;/A&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, I am getting 401 Unauthorized on every call.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I have tried generating new API keys with Instance Admin role as well but no luck.&lt;/P&gt;
&lt;P&gt;Tried with python, terminal and Postman, still the same.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;LI-PRODUCT title="Cortex XSOAR" id="Cortex_XSOAR"&gt;&lt;/LI-PRODUCT&gt;&lt;/P&gt;</description>
      <pubDate>Thu, 03 Oct 2024 20:42:14 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/using-xsoar-api-stoplight/m-p/599478#M3668</guid>
      <dc:creator>pagnihotri</dc:creator>
      <dc:date>2024-10-03T20:42:14Z</dc:date>
    </item>
    <item>
      <title>Re: Using XSOAR API Stoplight</title>
      <link>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/using-xsoar-api-stoplight/m-p/599682#M3673</link>
      <description>&lt;P&gt;&lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/1484114163"&gt;@benstokes&lt;/a&gt;&amp;nbsp;&lt;BR /&gt;Thanks for the response.&amp;nbsp;&lt;BR /&gt;&lt;BR /&gt;&lt;/P&gt;
&lt;P&gt;headers = {&lt;BR /&gt;"x-xdr-auth-id": str(&amp;lt;api_key_id&amp;gt;),&lt;BR /&gt;"Authorization": ApiKey &amp;lt;api_key&amp;gt;,&lt;BR /&gt;"Accept": "application/json"&lt;BR /&gt;}&lt;BR /&gt;&lt;BR /&gt;It still fails. Maybe I missing on something else.&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2024 08:57:25 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/using-xsoar-api-stoplight/m-p/599682#M3673</guid>
      <dc:creator>pagnihotri</dc:creator>
      <dc:date>2024-10-07T08:57:25Z</dc:date>
    </item>
    <item>
      <title>Re: Using XSOAR API Stoplight</title>
      <link>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/using-xsoar-api-stoplight/m-p/599694#M3677</link>
      <description>&lt;P&gt;&lt;SPAN&gt;&lt;SPAN&gt;- You need to use the server API URL from the API-keys page.(&lt;A href="https://api-{fqdn}/xsoar/public/v1/{endpoint_path}" target="_blank"&gt;https://api-{fqdn}/xsoar/public/v1/{endpoint_path}&lt;/A&gt;)&lt;BR /&gt;- Mind this from the docs: '&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;SPAN&gt;Choose the type of API Key you want to generate based on your desired security level:&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG style="font-family: inherit;"&gt;Advanced&lt;/STRONG&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;or&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;STRONG style="font-family: inherit;"&gt;Standard&lt;/STRONG&gt;&lt;SPAN&gt;. The Advanced API key hashes the key using a nonce, a random string, and a timestamp to prevent replay attacks. cURL does not support this but is suitable with scripts. Use the example script to create the advanced API authentication token."&lt;/SPAN&gt;&lt;/P&gt;
&lt;P&gt;So, test with an std key using curl:&amp;nbsp;curl -X POST &lt;A href="https://api-your-xsoar.us.paloaltonetworks.com/api_keys/validate/" target="_blank"&gt;https://api-your-xsoar.us.paloaltonetworks.com/api_keys/validate/&lt;/A&gt; -H "x-xdr-auth-id:{api_key_id}" -H "Authorization:{api_key}" -H "Content-Type:application/json" -d '{}'&lt;BR /&gt;For an advanced API key:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;from datetime import datetime, timezone
import secrets
import string
import hashlib
import requests

def test_advanced_authentication(api_key_id, api_key):
    # Generate a 64 bytes random string
    nonce = "".join([secrets.choice(string.ascii_letters + string.digits) for _ in range(64)])
    # Get the current timestamp as milliseconds.
    timestamp = int(datetime.now(timezone.utc).timestamp()) * 1000
    # Generate the auth key:
    auth_key = "%s%s%s" % (api_key, nonce, timestamp)
    # Convert to bytes object
    auth_key = auth_key.encode("utf-8")
    # Calculate sha256:
    api_key_hash = hashlib.sha256(auth_key).hexdigest()
    # Generate HTTP call headers
    headers = {
        "x-xdr-timestamp": str(timestamp),
        "x-xdr-nonce": nonce,
        "x-xdr-auth-id": str(api_key_id),
        "Authorization": api_key_hash
    }
    parameters = {}
    res = requests.post(url="https://api-your-xsoar.us.paloaltonetworks.com/api_keys/validate/",
                        headers=headers,
                        json=parameters)
    return res&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2024 12:12:51 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/using-xsoar-api-stoplight/m-p/599694#M3677</guid>
      <dc:creator>ctopay</dc:creator>
      <dc:date>2024-10-07T12:12:51Z</dc:date>
    </item>
    <item>
      <title>Re: Using XSOAR API Stoplight</title>
      <link>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/using-xsoar-api-stoplight/m-p/599719#M3679</link>
      <description>&lt;P&gt;&lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/207923"&gt;@ctopay&lt;/a&gt;&amp;nbsp;This works. Thanks&lt;/P&gt;</description>
      <pubDate>Mon, 07 Oct 2024 17:02:40 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/cortex-xsoar-discussions/using-xsoar-api-stoplight/m-p/599719#M3679</guid>
      <dc:creator>pagnihotri</dc:creator>
      <dc:date>2024-10-07T17:02:40Z</dc:date>
    </item>
  </channel>
</rss>

