<?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: Unable to create an address object using the API from Powershell in Automation/API Discussions</title>
    <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/unable-to-create-an-address-object-using-the-api-from-powershell/m-p/409824#M2671</link>
    <description>&lt;P data-unlink="true"&gt;Great news&amp;nbsp;&lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/177516"&gt;@jkostic1&lt;/a&gt;, happy to help. There are parameters to control the input/output format too (e.g.&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;&amp;amp;input-format=json&amp;amp;output-format=json&lt;/SPAN&gt;&lt;/FONT&gt;) in case you wanted to use XML.&lt;BR /&gt;&lt;BR /&gt;For future reference, the docs are here (and there's a PDF download button too):&amp;nbsp;&lt;A href="https://docs.paloaltonetworks.com/pan-os/10-0/pan-os-panorama-api/get-started-with-the-pan-os-rest-api.html" target="_blank"&gt;https://docs.paloaltonetworks.com/pan-os/10-0/pan-os-panorama-api/get-started-with-the-pan-os-rest-api.html&lt;/A&gt;. Also the firewall has docs onboard, at https://{{firewall-hostname}}/restapi-doc&lt;/P&gt;</description>
    <pubDate>Fri, 28 May 2021 10:25:21 GMT</pubDate>
    <dc:creator>JimmyHolland</dc:creator>
    <dc:date>2021-05-28T10:25:21Z</dc:date>
    <item>
      <title>Unable to create an address object using the API from Powershell</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/unable-to-create-an-address-object-using-the-api-from-powershell/m-p/409626#M2668</link>
      <description>&lt;P&gt;Hello,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I am attempting to add an address object using the API via PowerShell. I am able to logon, get the key, and pull down the current list of shared objects. When I attempt to add one, I receive a 400 error. Here is my script. If you are able to help I would appreciate it.&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;#Step 1 | set the environment up so that it will ignore the cert error

add-type @"
    using System.Net;
    using System.Security.Cryptography.X509Certificates;
    public class TrustAllCertsPolicy : ICertificatePolicy {
        public bool CheckValidationResult(
            ServicePoint srvPoint, X509Certificate certificate,
            WebRequest request, int certificateProblem) {
            return true;
        }
    }
"@
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy

#Step 2 | acquire Credentials from the user

$username = read-host 'Username: ' 
$password = read-host 'Password: ' 

#Step 3 | exchange credentials for your personal API Key

$Response = Invoke-WebRequest -URI https://&amp;lt;DEVICE_URL&amp;gt;/api/?type=keygen"&amp;amp;"user=$username"&amp;amp;"password=$password 

#Step 4 | Strip chaff and re-format

$Response = $response.content.substring(42) 
$key = $Response.Substring(0,$Response.Length-26) 
$xkey = @{ 'X-PAN-KEY' = $key}

#Step 5 | Clean up variables we no longer need

Remove-Variable username
Remove-Variable password
Remove-Variable key

#TODO / Beyond here is in varying states of broken

Invoke-WebRequest -Method POST -Header $xkey -URI https://&amp;lt;DEVICE_URL&amp;gt;/restapi/9/Objects/Addresses?location=shared"&amp;amp;"name=TutorialEntry -body $body&lt;/LI-CODE&gt;</description>
      <pubDate>Thu, 27 May 2021 15:45:03 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/unable-to-create-an-address-object-using-the-api-from-powershell/m-p/409626#M2668</guid>
      <dc:creator>jkostic1</dc:creator>
      <dc:date>2021-05-27T15:45:03Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to create an address object using the API from Powershell</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/unable-to-create-an-address-object-using-the-api-from-powershell/m-p/409647#M2669</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/177516"&gt;@jkostic1&lt;/a&gt;,&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I can't help much on the PowerShell side, but the final line in your script needs to have a request that looks something like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;https://{{host}}/restapi/v10.0/Objects/Addresses?name={{object-name}}&amp;amp;location=vsys&amp;amp;vsys=vsys1&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Then the body you pass in needs to look something like this (you didn't share what's in the $body variable):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;{
    "entry": {
        "@name": "My-Address",
        "ip-netmask": "8.8.8.8",
        "description": "My test address"
    }
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;POSTing my REST API call above with Postman works fine, so you just need to translate that into your PowerShell script with the variable names you're using.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Maybe it's the &lt;FONT face="courier new,courier"&gt;shared&lt;/FONT&gt; part in your location, are you on single-vsys or multi-vsys firewall?&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Or the version? These are the acceptable versions in the API endpoint URI (obvisouly you can only go up to the version which matches the&amp;nbsp;PAN-OS version your firewall is currently running, you can't target v10.0 on a v9.1 firewall, etc):&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;https://{{host}}/restapi/9.0/...
https://{{host}}/restapi/v9.1/...
https://{{host}}/restapi/v10.0/...&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Hope that helps!&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 16:43:58 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/unable-to-create-an-address-object-using-the-api-from-powershell/m-p/409647#M2669</guid>
      <dc:creator>JimmyHolland</dc:creator>
      <dc:date>2021-05-27T16:43:58Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to create an address object using the API from Powershell</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/unable-to-create-an-address-object-using-the-api-from-powershell/m-p/409690#M2670</link>
      <description>&lt;P&gt;Hey Jimmy,&lt;BR /&gt;&lt;BR /&gt;Thanks for the quick reply! You helped me a great deal just by mentioning using a client instead of Powershell. My original request works now as I had it except I used a client and used your JSON formatting.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Thu, 27 May 2021 18:19:03 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/unable-to-create-an-address-object-using-the-api-from-powershell/m-p/409690#M2670</guid>
      <dc:creator>jkostic1</dc:creator>
      <dc:date>2021-05-27T18:19:03Z</dc:date>
    </item>
    <item>
      <title>Re: Unable to create an address object using the API from Powershell</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/unable-to-create-an-address-object-using-the-api-from-powershell/m-p/409824#M2671</link>
      <description>&lt;P data-unlink="true"&gt;Great news&amp;nbsp;&lt;a href="https://live.paloaltonetworks.com/t5/user/viewprofilepage/user-id/177516"&gt;@jkostic1&lt;/a&gt;, happy to help. There are parameters to control the input/output format too (e.g.&amp;nbsp;&lt;FONT face="courier new,courier"&gt;&lt;SPAN&gt;&amp;amp;input-format=json&amp;amp;output-format=json&lt;/SPAN&gt;&lt;/FONT&gt;) in case you wanted to use XML.&lt;BR /&gt;&lt;BR /&gt;For future reference, the docs are here (and there's a PDF download button too):&amp;nbsp;&lt;A href="https://docs.paloaltonetworks.com/pan-os/10-0/pan-os-panorama-api/get-started-with-the-pan-os-rest-api.html" target="_blank"&gt;https://docs.paloaltonetworks.com/pan-os/10-0/pan-os-panorama-api/get-started-with-the-pan-os-rest-api.html&lt;/A&gt;. Also the firewall has docs onboard, at https://{{firewall-hostname}}/restapi-doc&lt;/P&gt;</description>
      <pubDate>Fri, 28 May 2021 10:25:21 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/unable-to-create-an-address-object-using-the-api-from-powershell/m-p/409824#M2671</guid>
      <dc:creator>JimmyHolland</dc:creator>
      <dc:date>2021-05-28T10:25:21Z</dc:date>
    </item>
  </channel>
</rss>

