<?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 Using the REST API to create a bunch of Address Objects in General Topics</title>
    <link>https://live.paloaltonetworks.com/t5/general-topics/using-the-rest-api-to-create-a-bunch-of-address-objects/m-p/585793#M116919</link>
    <description>&lt;P&gt;I have to create a large number Address Objects and would like to use teh REST API to do so.&amp;nbsp; I've seen a number of examples at adding various things, but I'm running into an issue with these specific shared objects.&amp;nbsp; The all live in a device group called Global.&lt;/P&gt;
&lt;P&gt;If I do a GET, I see that an object will look as follows&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;{"@name":"net-vl730-boise", "@location":"shared", "ip-netmask":"10.21.45.0\/24", "description":"Boise VTC Network"}&lt;/LI-CODE&gt;
&lt;P&gt;Am I correct in assuming that when interacting with an object, a field with a leading&amp;nbsp;@ is a required field?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I basically want to have code that creates ~100 more of these.&amp;nbsp; To that end, I have a code snippet that looks as follows:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;headers = {
  'Content-Type': 'application/json',
  'X-PAN-KEY': api_key
  }
name = "net-vl720-miami"
ip_netmask = "10.22.104.0\/22"
payload = json.dumps({
    "entry":{
        "@location":"shared",
        "@name":"net-vl720-miami",
        "ip-netmask":"10.21.46.0\/24",
        "description":"Miami Voice Network"
        }
    })
url = "https://panorama_ip/restapi/v10.1/Objects/Addresses"
try:
    r1 = requests.request("POST",url, headers=headers, data=payload, verify=False)
except:
    print(r1.text)&lt;/LI-CODE&gt;
&lt;P&gt;When I run the code as is, the response I get is:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;'{"code":3,"message":"Missing Query Parameter: location","details":[{"@type":"CauseInfo","causes":[{"code":7,"module":"pan_api","description":"Missing Query Parameter: location"}]}]}'&lt;/LI-CODE&gt;
&lt;P&gt;If I alter the URL to include the location, as so:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;url = "https://w0t809-pan-mgmt.mitre.org/restapi/v10.1/Objects/Addresses?location=shared"&lt;/LI-CODE&gt;
&lt;P&gt;The description part of the response becomes:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;"description":"Missing Query Parameter: name"&lt;/LI-CODE&gt;
&lt;P&gt;So for starters, I'm not sure what belongs in the URL, and what belongs in the payload, as some of the data seems to be duplicated.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I add the name to the URL:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;url = "https://w0t809-pan-mgmt.mitre.org/restapi/v10.1/Objects/Addresses?location=shared&amp;amp;name=" + name&lt;/LI-CODE&gt;
&lt;P&gt;The response changes to&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;"description":"Invalid Object: Edit breaks config validity."&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;Can anybody share what I'm doing wrong?&amp;nbsp; I'm sure I'm not the first person to attempt this.&lt;/P&gt;</description>
    <pubDate>Fri, 03 May 2024 19:55:54 GMT</pubDate>
    <dc:creator>DaveFitz</dc:creator>
    <dc:date>2024-05-03T19:55:54Z</dc:date>
    <item>
      <title>Using the REST API to create a bunch of Address Objects</title>
      <link>https://live.paloaltonetworks.com/t5/general-topics/using-the-rest-api-to-create-a-bunch-of-address-objects/m-p/585793#M116919</link>
      <description>&lt;P&gt;I have to create a large number Address Objects and would like to use teh REST API to do so.&amp;nbsp; I've seen a number of examples at adding various things, but I'm running into an issue with these specific shared objects.&amp;nbsp; The all live in a device group called Global.&lt;/P&gt;
&lt;P&gt;If I do a GET, I see that an object will look as follows&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;{"@name":"net-vl730-boise", "@location":"shared", "ip-netmask":"10.21.45.0\/24", "description":"Boise VTC Network"}&lt;/LI-CODE&gt;
&lt;P&gt;Am I correct in assuming that when interacting with an object, a field with a leading&amp;nbsp;@ is a required field?&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I basically want to have code that creates ~100 more of these.&amp;nbsp; To that end, I have a code snippet that looks as follows:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;headers = {
  'Content-Type': 'application/json',
  'X-PAN-KEY': api_key
  }
name = "net-vl720-miami"
ip_netmask = "10.22.104.0\/22"
payload = json.dumps({
    "entry":{
        "@location":"shared",
        "@name":"net-vl720-miami",
        "ip-netmask":"10.21.46.0\/24",
        "description":"Miami Voice Network"
        }
    })
url = "https://panorama_ip/restapi/v10.1/Objects/Addresses"
try:
    r1 = requests.request("POST",url, headers=headers, data=payload, verify=False)
except:
    print(r1.text)&lt;/LI-CODE&gt;
&lt;P&gt;When I run the code as is, the response I get is:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;'{"code":3,"message":"Missing Query Parameter: location","details":[{"@type":"CauseInfo","causes":[{"code":7,"module":"pan_api","description":"Missing Query Parameter: location"}]}]}'&lt;/LI-CODE&gt;
&lt;P&gt;If I alter the URL to include the location, as so:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;url = "https://w0t809-pan-mgmt.mitre.org/restapi/v10.1/Objects/Addresses?location=shared"&lt;/LI-CODE&gt;
&lt;P&gt;The description part of the response becomes:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;"description":"Missing Query Parameter: name"&lt;/LI-CODE&gt;
&lt;P&gt;So for starters, I'm not sure what belongs in the URL, and what belongs in the payload, as some of the data seems to be duplicated.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;If I add the name to the URL:&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;url = "https://w0t809-pan-mgmt.mitre.org/restapi/v10.1/Objects/Addresses?location=shared&amp;amp;name=" + name&lt;/LI-CODE&gt;
&lt;P&gt;The response changes to&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;"description":"Invalid Object: Edit breaks config validity."&lt;/LI-CODE&gt;
&lt;P&gt;&lt;BR /&gt;&amp;nbsp;Can anybody share what I'm doing wrong?&amp;nbsp; I'm sure I'm not the first person to attempt this.&lt;/P&gt;</description>
      <pubDate>Fri, 03 May 2024 19:55:54 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/general-topics/using-the-rest-api-to-create-a-bunch-of-address-objects/m-p/585793#M116919</guid>
      <dc:creator>DaveFitz</dc:creator>
      <dc:date>2024-05-03T19:55:54Z</dc:date>
    </item>
    <item>
      <title>Re: Using the REST API to create a bunch of Address Objects</title>
      <link>https://live.paloaltonetworks.com/t5/general-topics/using-the-rest-api-to-create-a-bunch-of-address-objects/m-p/585887#M116939</link>
      <description>&lt;P&gt;Hi &lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/137282"&gt;@DaveFitz&lt;/a&gt; ,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;This is what worked for me in Postman.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="markup"&gt;URL = https://{{hostname}}.{{domain}}.com/restapi/v10.2/Objects/Addresses?location=shared&amp;amp;name=Test-1-2-3&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Body = 
{
    "entry": [
        {
            "@location": "shared",
            "@name": "Test-1-2-3",
            "ip-netmask": "10.21.46.0/24",
            "tag": {
                "member": [
                    "API"
                ]
            },
            "description": "Miami Voice Network"
        }
    ]
}&lt;/LI-CODE&gt;&lt;LI-CODE lang="markup"&gt;Response =
{
    "@status": "success",
    "@code": "20",
    "msg": "command succeeded"
}&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;The name needs to be in the URL according to this example:&amp;nbsp; &lt;A href="https://docs.paloaltonetworks.com/pan-os/9-1/pan-os-panorama-api/get-started-with-the-pan-os-rest-api/work-with-address-objects-rest-api" target="_blank" rel="noopener"&gt;https://docs.paloaltonetworks.com/pan-os/9-1/pan-os-panorama-api/get-started-with-the-pan-os-rest-api/work-with-address-objects-rest-api&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;My "API" tag already existed.&amp;nbsp; Here is the newly created object in the Panorama GUI:&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&lt;span class="lia-inline-image-display-wrapper lia-image-align-inline" image-alt="TomYoung_0-1715017580446.png" style="width: 400px;"&gt;&lt;img src="https://live.paloaltonetworks.com/t5/image/serverpage/image-id/59534iD264750C555B6850/image-size/medium?v=v2&amp;amp;px=400" role="button" title="TomYoung_0-1715017580446.png" alt="TomYoung_0-1715017580446.png" /&gt;&lt;/span&gt;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thanks,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Tom&lt;/P&gt;</description>
      <pubDate>Mon, 06 May 2024 19:40:52 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/general-topics/using-the-rest-api-to-create-a-bunch-of-address-objects/m-p/585887#M116939</guid>
      <dc:creator>TomYoung</dc:creator>
      <dc:date>2024-05-06T19:40:52Z</dc:date>
    </item>
  </channel>
</rss>

