<?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: Python API: Add Compliance Standard to Policy in Prisma Cloud Discussions</title>
    <link>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/python-api-add-compliance-standard-to-policy/m-p/261532#M142</link>
    <description>&lt;P&gt;&lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/112788"&gt;@JBox&lt;/a&gt;&amp;nbsp;I get error 500s if the format of my JSON is incorrect.&amp;nbsp; Can you try to perform a GET then immediately PUT it back without modifying the payload?&amp;nbsp; If that still gives a 500, it's likely because you need to json.dumps the payload before sending it back.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another thing, the "complianceId" field is very confusing.&amp;nbsp; That refers to the Compliance Section GUID.&amp;nbsp; It is not easy to get this ID number.&amp;nbsp; You will have to do a GET on the compliance standard, to find the requirements GUID, then you can GET the list of sections and section GUIDs.&amp;nbsp; Example, my compliance standard ID is&amp;nbsp;052009c7-7640-436c-bcde-69846acf73e8, so I have to&lt;/P&gt;&lt;P&gt;&lt;EM&gt;GET&amp;nbsp;&lt;A href="https://api.redlock.io/compliance/052009c7-7640-436c-bcde-69846acf73e8/requirement" target="_blank"&gt;https://api.redlock.io/compliance/052009c7-7640-436c-bcde-69846acf73e8/requirement&lt;/A&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Then in the response, I can find the requirements ID, which I can do:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;GET &lt;A href="https://api.redlock.io/compliance/f2cf9fe2-1007-48b7-b5bb-1f24e8535953/section" target="_blank"&gt;https://api.redlock.io/compliance/f2cf9fe2-1007-48b7-b5bb-1f24e8535953/section&lt;/A&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then within that response, I can find the "id" of the section that I want to use, which is the value for the "complianceId" field in the complianceMetadata object.&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Fri, 17 May 2019 17:54:26 GMT</pubDate>
    <dc:creator>kchen</dc:creator>
    <dc:date>2019-05-17T17:54:26Z</dc:date>
    <item>
      <title>Python API: Add Compliance Standard to Policy</title>
      <link>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/python-api-add-compliance-standard-to-policy/m-p/261421#M138</link>
      <description>&lt;P&gt;Hi all,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I'm having trouble adding a Compliance Standard to an existing Policy via the API.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;In essence my code looks like:&lt;/P&gt;&lt;PRE&gt;import requests

url = https://api2.redlock.io/policy/{policy_id}

header = {'Content-Type': 'application/json', 'x-redlock-auth': 'token'}

payload = {
    'name': 'policy_name',
    'policyType': 'policy_type',
    'severity': 'policy_severity',
    'complianceMetadata': [
        {
            'standardName': 'standard_name',
            'requirementId': 'requirement_ID',
            'sectionId': 'section_id'
        }
    ]
}

response = requests.request('PUT', url, json=payload, header=header)&lt;/PRE&gt;&lt;P&gt;However, everytime I send the request, I'm returned with a 500 Server Error (and, unfortunately, the API documentation is super unhelpful with this). I'm not sure if I'm sending the right information to add a compliance standard as the API documentation doesn't show what info needs to be sent. If I leave out required fields (name, policyType, and severity), I'm returned a 400 error (bad request, which makes sense). But I can't figure out why I keep getting the 500 Server Error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any ideas here would be much appreciated! Thanks!&lt;/P&gt;</description>
      <pubDate>Wed, 02 Sep 2020 17:16:02 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/python-api-add-compliance-standard-to-policy/m-p/261421#M138</guid>
      <dc:creator>JBox</dc:creator>
      <dc:date>2020-09-02T17:16:02Z</dc:date>
    </item>
    <item>
      <title>Re: Python API: Add Compliance Standard to Policy</title>
      <link>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/python-api-add-compliance-standard-to-policy/m-p/261425#M139</link>
      <description>&lt;P&gt;At first glance, you are likely missing some required fields that is necessary when PUT-ing a policy.&amp;nbsp; What I would recommend is do a GET on the policy, use the returned payload as base, update the complianceMetadata field with what you want to include, then PUT the entire thing back into Prisma Public Cloud.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I agree that the error message is super unhelpful; you might get more information by checking the response header.&amp;nbsp; The error message is included in there, and it might provide some hints.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hope this helps.&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2019 00:53:13 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/python-api-add-compliance-standard-to-policy/m-p/261425#M139</guid>
      <dc:creator>kchen</dc:creator>
      <dc:date>2019-06-13T00:53:13Z</dc:date>
    </item>
    <item>
      <title>Re: Python API: Add Compliance Standard to Policy</title>
      <link>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/python-api-add-compliance-standard-to-policy/m-p/261428#M140</link>
      <description>&lt;P&gt;Thanks,&amp;nbsp;&lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/86712"&gt;@kchen&lt;/a&gt;.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The response header is this:&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;x-redlock-status →[{"i18nKey":"internal_error","severity":"error","subject":null}]&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Your approach is something that I actually implemented as a workaround, but no bueno. The work around looks like this:&lt;/P&gt;&lt;PRE&gt;req_header = {'Content-Type':'application/json','x-redlock-auth':jwt_token}

# This is a small function to get a policy by ID
policy = get_redlock_policy_by_ID(req_header, 'policy_ID')

    new_std = {
        'standardName': 'standard_name',
        'standardDescription': '',
        'requirementId': 'req_ID',
        'requirementName': 'req_name',
        'sectionId': 'section_ID',
        'sectionDescription': '',
        'policyId': '',
        'complianceId': 'compliance_ID',
        'systemDefault': False,
        'customAssigned': True
        }

    standards = policy['complianceMetadata']

    for standard in standards:
        if not 'standard_name' in standard['standardName']:
            new_std['policyId'] = policy['policyId']
            policy['complianceMetadata'].append(new_std)

            try:
                response = requests.request('PUT', '{}/policy/{}'.format(REDLOCK_API_URL, policy['policyId']), json=policy, headers=req_header)

                if response.status_code == 200:
                    print('Successful push ---- YA BOI DID IT')
                else:
                    logging.error(' HTTPStatus: ' + str(response.status_code) + ' ' + response.reason)
                    sys.exit(1)
            except requests.exceptions.RequestException as e:
                logging.error(' Data Push -- Function: update_redlock_compliance_details: {}'.format(e))
                break&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;And it still returns:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;FONT face="courier new,courier"&gt;&amp;gt;&amp;gt;&amp;nbsp;ERROR:root: HTTPStatus: 500 Server Error&lt;/FONT&gt;&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2019 02:53:48 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/python-api-add-compliance-standard-to-policy/m-p/261428#M140</guid>
      <dc:creator>JBox</dc:creator>
      <dc:date>2019-05-17T02:53:48Z</dc:date>
    </item>
    <item>
      <title>Re: Python API: Add Compliance Standard to Policy</title>
      <link>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/python-api-add-compliance-standard-to-policy/m-p/261518#M141</link>
      <description>&lt;P&gt;The bare minimum needed in compliance metadata is:&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;"complianceMetadata":[ 
      { 
         "standardName":"Eddie",
         "requirementId":"1.1",
         "sectionId":"1.1.1",
         "customAssigned":true,
         "complianceId":"46e6887f-ba66-43f3-aaeb-9af56c1cc546",
         "requirementName":"Eddie req"
      }
   ],&lt;/PRE&gt;&lt;P&gt;You shouldn't need to include anything else in the metadata...&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2019 15:46:37 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/python-api-add-compliance-standard-to-policy/m-p/261518#M141</guid>
      <dc:creator>ebeuerlein</dc:creator>
      <dc:date>2019-05-17T15:46:37Z</dc:date>
    </item>
    <item>
      <title>Re: Python API: Add Compliance Standard to Policy</title>
      <link>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/python-api-add-compliance-standard-to-policy/m-p/261532#M142</link>
      <description>&lt;P&gt;&lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/112788"&gt;@JBox&lt;/a&gt;&amp;nbsp;I get error 500s if the format of my JSON is incorrect.&amp;nbsp; Can you try to perform a GET then immediately PUT it back without modifying the payload?&amp;nbsp; If that still gives a 500, it's likely because you need to json.dumps the payload before sending it back.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Another thing, the "complianceId" field is very confusing.&amp;nbsp; That refers to the Compliance Section GUID.&amp;nbsp; It is not easy to get this ID number.&amp;nbsp; You will have to do a GET on the compliance standard, to find the requirements GUID, then you can GET the list of sections and section GUIDs.&amp;nbsp; Example, my compliance standard ID is&amp;nbsp;052009c7-7640-436c-bcde-69846acf73e8, so I have to&lt;/P&gt;&lt;P&gt;&lt;EM&gt;GET&amp;nbsp;&lt;A href="https://api.redlock.io/compliance/052009c7-7640-436c-bcde-69846acf73e8/requirement" target="_blank"&gt;https://api.redlock.io/compliance/052009c7-7640-436c-bcde-69846acf73e8/requirement&lt;/A&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Then in the response, I can find the requirements ID, which I can do:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;EM&gt;GET &lt;A href="https://api.redlock.io/compliance/f2cf9fe2-1007-48b7-b5bb-1f24e8535953/section" target="_blank"&gt;https://api.redlock.io/compliance/f2cf9fe2-1007-48b7-b5bb-1f24e8535953/section&lt;/A&gt;&lt;/EM&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then within that response, I can find the "id" of the section that I want to use, which is the value for the "complianceId" field in the complianceMetadata object.&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;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Fri, 17 May 2019 17:54:26 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/python-api-add-compliance-standard-to-policy/m-p/261532#M142</guid>
      <dc:creator>kchen</dc:creator>
      <dc:date>2019-05-17T17:54:26Z</dc:date>
    </item>
    <item>
      <title>Re: Python API: Add Compliance Standard to Policy</title>
      <link>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/python-api-add-compliance-standard-to-policy/m-p/261593#M143</link>
      <description>&lt;P&gt;Thanks,&amp;nbsp;&lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/86712"&gt;@kchen&lt;/a&gt;. and&amp;nbsp;&lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/111137"&gt;@ebeuerlein&lt;/a&gt;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;It ended up working for all but 2 policies with the work-around on GET-requesting the entire policy, appending the "complianceMetadata" array and PUT-requesting the whole policy back.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The issue now is the two that it didn't update for (Prisma Public Cloud default policies). The first one is a known bug that the internal engineering team are working on. However, the second that didn't work is returning another 500 error. It is an old policy that hasn't been converted to RQL yet. If 500 errors are usually bad JSON, is there a difference in a RQL Policy JSON vs Non-RQL Policy JSON? Pulling the data from the server and having a look at it, it doesn't seem so but I can't get this one to update via the API. Otherwise, I can't figure out why it would work on all RQL policies and not this one non-RQL policy.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Any further suggestions would be awesome!&lt;/P&gt;</description>
      <pubDate>Thu, 13 Jun 2019 00:52:17 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/python-api-add-compliance-standard-to-policy/m-p/261593#M143</guid>
      <dc:creator>JBox</dc:creator>
      <dc:date>2019-06-13T00:52:17Z</dc:date>
    </item>
    <item>
      <title>Re: Python API: Add Compliance Standard to Policy</title>
      <link>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/python-api-add-compliance-standard-to-policy/m-p/261686#M144</link>
      <description>&lt;P&gt;Got it to work.&amp;nbsp; For these policies without RQL, you need to include this field within the "rule" field:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="sObjectK"&gt;"parameters"&lt;/SPAN&gt;&lt;SPAN class="sColon"&gt;:&lt;/SPAN&gt;&lt;SPAN class="sBrace structure-3"&gt;{&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&lt;/SPAN&gt;&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="sObjectK"&gt;"savedSearch"&lt;/SPAN&gt;&lt;SPAN class="sColon"&gt;:&lt;/SPAN&gt;&lt;SPAN class="sObjectV"&gt;"false"&lt;/SPAN&gt;&lt;BR /&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/SPAN&gt;&lt;SPAN class="sBrace structure-3"&gt;}&lt;/SPAN&gt;&lt;SPAN class="sComma"&gt;,&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;One way to find out if you need the above is to check for the rule -&amp;gt; parameters -&amp;gt; savedSearch field after you GET the policy.&amp;nbsp; I think all default policies with RQL will have "savedSearch" = "true", so if that field/value combo isn't in the returned JSON, you know you need to add "savedSearch": "false" to the payload before returning.&lt;/P&gt;</description>
      <pubDate>Mon, 20 May 2019 18:40:36 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/python-api-add-compliance-standard-to-policy/m-p/261686#M144</guid>
      <dc:creator>kchen</dc:creator>
      <dc:date>2019-05-20T18:40:36Z</dc:date>
    </item>
    <item>
      <title>Re: Python API: Add Compliance Standard to Policy</title>
      <link>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/python-api-add-compliance-standard-to-policy/m-p/261880#M145</link>
      <description>&lt;P&gt;Worked perfectly, thanks&amp;nbsp;&lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/86712"&gt;@kchen&lt;/a&gt;!&lt;/P&gt;</description>
      <pubDate>Wed, 22 May 2019 04:29:01 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/prisma-cloud-discussions/python-api-add-compliance-standard-to-policy/m-p/261880#M145</guid>
      <dc:creator>JBox</dc:creator>
      <dc:date>2019-05-22T04:29:01Z</dc:date>
    </item>
  </channel>
</rss>

