<?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: IOC upload 401 response in Automation/API Discussions</title>
    <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/ioc-upload-401-response/m-p/443905#M2818</link>
    <description>&lt;P&gt;Not sure what I did differently but I managed to get past this but now I'm on a 400 error, here are a few examples:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;b'{"reply": {"err_code": 400, "err_msg": "Bad Request. Got an invalid JSON.", "err_extra": "Invalid control character at: line 1 column 94 (char 93)"}}'

b'{"reply": {"err_code": 400, "err_msg": "Bad Request. Got an invalid JSON.", "err_extra": "Expecting value: line 1 column 1 (char 0)"}}'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is an example of the JSON I'm posting, the IOC's are from XDR's sample file in the upload interface:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
	"request_data": "192.168.2.1,IP,INFO,Never,Comment string,BAD,C,Malware,Vendor string,GOOD,C\nC:\tmp\risky_script.py,PATH,INFO,Never,Comment string,BAD,C,Malware,Vendorstring,GOOD,C\ncrypto_v.exe,FILENAME,INFO,Never,Comment string,BAD,C,Malware,Vendor string,GOOD,C\nwww.lottery4free.biz,DOMAIN_NAME,INFO,Never,Commentstring,BAD,C,Malware,Vendor string,GOOD,C\n900150983cd24fb0d6963f7d28e17f72,HASH,INFO,Never,Commentstring,BAD,C,Malware,Vendor string,GOOD,C\nba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad,HASH,INFO,Never,Comment string,BAD,C,Malware,Vendor string,GOOD,C\n"
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I put this into a JSON validator which said it's good. I've played around with a few variations but haven't had any luck. Does anyone have advice on the JSON formatting expected by the API?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Wed, 27 Oct 2021 21:02:06 GMT</pubDate>
    <dc:creator>John_Easton</dc:creator>
    <dc:date>2021-10-27T21:02:06Z</dc:date>
    <item>
      <title>IOC upload 401 response</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/ioc-upload-401-response/m-p/443529#M2814</link>
      <description>&lt;P&gt;Hello,&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am trying to upload IOC's with this API reference:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;A href="https://docs.paloaltonetworks.com/cortex/cortex-xdr/cortex-xdr-api/cortex-xdr-apis/rule-management/insert-indicator-csv.html#insert-simple-indicators-csv" target="_blank" rel="noopener"&gt;Insert Simple Indicators, CSV (paloaltonetworks.com)&lt;/A&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm posting the data with the requests module in python and always get a 401 response for&amp;nbsp;"Unauthorized access. An issue occurred during authentication. This can indicate an incorrect key, id, or other invalid authentication parameters."&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;headers = {
    'x-xdr-auth-id': '300',
    'authorization': 'APIKEY',
    'content-type': 'application/json',
}

data = '{"request_data": "' + request_data + '"}'

response = requests.post('https://api-xxx.paloaltonetworks.com/public_api/v1/indicators/insert_csv/', headers=headers, data=data)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;We have a&amp;nbsp;Pro per Endpoint licence&amp;nbsp;and I am generating an API key with full permissions for testing. I get the&amp;nbsp;{API_KEY_ID} from the ID column after the key is generated.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas why this is failing?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&amp;nbsp;&lt;/P&gt;&lt;P&gt;John.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Tue, 26 Oct 2021 18:21:36 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/ioc-upload-401-response/m-p/443529#M2814</guid>
      <dc:creator>John_Easton</dc:creator>
      <dc:date>2021-10-26T18:21:36Z</dc:date>
    </item>
    <item>
      <title>Re: IOC upload 401 response</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/ioc-upload-401-response/m-p/443905#M2818</link>
      <description>&lt;P&gt;Not sure what I did differently but I managed to get past this but now I'm on a 400 error, here are a few examples:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;b'{"reply": {"err_code": 400, "err_msg": "Bad Request. Got an invalid JSON.", "err_extra": "Invalid control character at: line 1 column 94 (char 93)"}}'

b'{"reply": {"err_code": 400, "err_msg": "Bad Request. Got an invalid JSON.", "err_extra": "Expecting value: line 1 column 1 (char 0)"}}'&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;This is an example of the JSON I'm posting, the IOC's are from XDR's sample file in the upload interface:&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
	"request_data": "192.168.2.1,IP,INFO,Never,Comment string,BAD,C,Malware,Vendor string,GOOD,C\nC:\tmp\risky_script.py,PATH,INFO,Never,Comment string,BAD,C,Malware,Vendorstring,GOOD,C\ncrypto_v.exe,FILENAME,INFO,Never,Comment string,BAD,C,Malware,Vendor string,GOOD,C\nwww.lottery4free.biz,DOMAIN_NAME,INFO,Never,Commentstring,BAD,C,Malware,Vendor string,GOOD,C\n900150983cd24fb0d6963f7d28e17f72,HASH,INFO,Never,Commentstring,BAD,C,Malware,Vendor string,GOOD,C\nba7816bf8f01cfea414140de5dae2223b00361a396177a9cb410ff61f20015ad,HASH,INFO,Never,Comment string,BAD,C,Malware,Vendor string,GOOD,C\n"
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I put this into a JSON validator which said it's good. I've played around with a few variations but haven't had any luck. Does anyone have advice on the JSON formatting expected by the API?&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 27 Oct 2021 21:02:06 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/ioc-upload-401-response/m-p/443905#M2818</guid>
      <dc:creator>John_Easton</dc:creator>
      <dc:date>2021-10-27T21:02:06Z</dc:date>
    </item>
    <item>
      <title>Re: IOC upload 401 response</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/ioc-upload-401-response/m-p/444326#M2820</link>
      <description>&lt;P&gt;Eventually worked this out with more trial and error.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I had to change the 'data' variable from a string to a dictionary and serialize the JSON in the request.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="python"&gt;data = {"request_data": request_data}

response = requests.post('https://api-xxx.paloaltonetworks.com/public_api/v1/indicators/insert_csv/', headers=headers, json=data)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I was also missing the CSV headers, I believe that is what creates these errors:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;"err_extra": "Invalid control character&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 29 Oct 2021 13:16:18 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/ioc-upload-401-response/m-p/444326#M2820</guid>
      <dc:creator>John_Easton</dc:creator>
      <dc:date>2021-10-29T13:16:18Z</dc:date>
    </item>
  </channel>
</rss>

