<?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: Rest calls from PowerShell failing in Automation/API Discussions</title>
    <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/rest-calls-from-powershell-failing/m-p/197671#M1555</link>
    <description>&lt;P&gt;It would be helpful to see the request/response in that case. Could you get the URI's from a packet capture potentially, sanitize the IP and keys, and paste them over?&lt;/P&gt;</description>
    <pubDate>Tue, 30 Jan 2018 18:36:18 GMT</pubDate>
    <dc:creator>nigelswift</dc:creator>
    <dc:date>2018-01-30T18:36:18Z</dc:date>
    <item>
      <title>Rest calls from PowerShell failing</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/rest-calls-from-powershell-failing/m-p/197184#M1547</link>
      <description>&lt;P&gt;I have a script that I use that reads a copy of my palo's configuration that I manually export. I am looking to create a PowerShell script that can call the rest service instead of having to manually export the XML configuration file. I also want to be able to give the script to co-workers (using their own key). However, when I go to call the service I either the error that the connection was closed or an HTTP error.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I tested the URI that I am using in small python script and received a 200 status code. I do not know Python well enough to be able to write the script in it and Python is widely installed in my office.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have been fighting this for a while I am at my wits end as I cannot figure out what it is that I am doing wrong.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Here is my code:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;$rKey = "&amp;lt;KEY&amp;gt;"
$Headers = "$rKey application"
$type = "config"
$xpath = "/config/devices/entry[@name='localhost.localdomain']/vsys/entry[@name='vsys1']/address"
$strUri ="https://&amp;lt;URL&amp;gt;/api/?type=config&amp;amp;action=get&amp;amp;key=$dKey&amp;amp;xpath=$xpath"


#Tried this after the first failed. Same results.
Invoke-WebRequest -Method Get -Uri "https://&amp;lt;URL&amp;gt;/api/?type=config&amp;amp;action=get&amp;amp;key=$rKey&amp;amp;xpath=/config/devices/entry[@name='localhost.localdomain']/vsys/entry[@name='vsys1']/address"

#started with this, had error message.
Invoke-WebRequest -Method Get -Uri $strUri&lt;/PRE&gt;&lt;P&gt;I am new to using rest and this is my first attempt at something other than using a cmdlet to get my external IP.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Any help would be greatly appreciated.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Thanks,&lt;BR /&gt;Sean&lt;/P&gt;</description>
      <pubDate>Fri, 26 Jan 2018 20:07:54 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/rest-calls-from-powershell-failing/m-p/197184#M1547</guid>
      <dc:creator>seanbarbour</dc:creator>
      <dc:date>2018-01-26T20:07:54Z</dc:date>
    </item>
    <item>
      <title>Re: Rest calls from PowerShell failing</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/rest-calls-from-powershell-failing/m-p/197214#M1548</link>
      <description>&lt;P&gt;Can you share the error? The Invoke-WebRequest looks correct. You can also try your API call in the browser and the error information returned may be a little more verbose.&lt;/P&gt;</description>
      <pubDate>Sat, 27 Jan 2018 00:46:02 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/rest-calls-from-powershell-failing/m-p/197214#M1548</guid>
      <dc:creator>nigelswift</dc:creator>
      <dc:date>2018-01-27T00:46:02Z</dc:date>
    </item>
    <item>
      <title>Re: Rest calls from PowerShell failing</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/rest-calls-from-powershell-failing/m-p/197393#M1549</link>
      <description>&lt;P&gt;I get the following error message when I use a variable that builds the URI:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
At C:\Users\meowz\Documents\Scripts\powershell\palo-search-ps\palo-rest.ps1:20 char:1
+ Invoke-WebRequest -Method Get -Uri $strUri
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I use the URI directly in the call (invoke-webrequest -method...) i get the following error:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;PRE&gt;Invoke-WebRequest : The underlying connection was closed: An unexpected error occurred on a send.
At C:\Users\meowz\Documents\Scripts\powershell\palo-search-ps\palo-rest.ps1:20 char:1
+ Invoke-WebRequest -Method Get -Uri "https://&amp;lt;URL TO PALO&amp;gt;/ap ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (System.Net.HttpWebRequest:HttpWebRequest) [Invoke-WebRequest], WebException
    + FullyQualifiedErrorId : WebCmdletWebResponseException,Microsoft.PowerShell.Commands.InvokeWebRequestCommand&lt;/PRE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;When I copy the URI and use it in the browser I get the list of addresses returned.&lt;/P&gt;&lt;P&gt;If I attempt to use Invoke-ResetMethod I get the same errors.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 29 Jan 2018 14:35:51 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/rest-calls-from-powershell-failing/m-p/197393#M1549</guid>
      <dc:creator>seanbarbour</dc:creator>
      <dc:date>2018-01-29T14:35:51Z</dc:date>
    </item>
    <item>
      <title>Re: Rest calls from PowerShell failing</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/rest-calls-from-powershell-failing/m-p/197671#M1555</link>
      <description>&lt;P&gt;It would be helpful to see the request/response in that case. Could you get the URI's from a packet capture potentially, sanitize the IP and keys, and paste them over?&lt;/P&gt;</description>
      <pubDate>Tue, 30 Jan 2018 18:36:18 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/rest-calls-from-powershell-failing/m-p/197671#M1555</guid>
      <dc:creator>nigelswift</dc:creator>
      <dc:date>2018-01-30T18:36:18Z</dc:date>
    </item>
    <item>
      <title>Re: Rest calls from PowerShell failing</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/rest-calls-from-powershell-failing/m-p/198830#M1576</link>
      <description>&lt;P&gt;I will try, never had to sanatize a packet capture before.&lt;/P&gt;</description>
      <pubDate>Mon, 05 Feb 2018 14:38:14 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/rest-calls-from-powershell-failing/m-p/198830#M1576</guid>
      <dc:creator>seanbarbour</dc:creator>
      <dc:date>2018-02-05T14:38:14Z</dc:date>
    </item>
    <item>
      <title>Re: Rest calls from PowerShell failing</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/rest-calls-from-powershell-failing/m-p/200668#M1592</link>
      <description>&lt;P&gt;It appears the issue is with PS not liking the certificate we used for the management interface. I added the following two lines which resolved the issue:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;PRE&gt;$AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols&lt;/PRE&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;SPAN&gt;The top of my script looks like this:&lt;/SPAN&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;PRE&gt;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;
        }
    }
"@
$AllProtocols = [System.Net.SecurityProtocolType]'Ssl3,Tls,Tls11,Tls12'
[System.Net.ServicePointManager]::SecurityProtocol = $AllProtocols
[System.Net.ServicePointManager]::CertificatePolicy = New-Object TrustAllCertsPolicy&lt;/PRE&gt;&lt;/DIV&gt;&lt;/DIV&gt;&lt;DIV&gt;&amp;nbsp;&lt;/DIV&gt;&lt;DIV&gt;Hopefully this will help someone else.&lt;/DIV&gt;&lt;/DIV&gt;</description>
      <pubDate>Thu, 15 Feb 2018 13:55:59 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/rest-calls-from-powershell-failing/m-p/200668#M1592</guid>
      <dc:creator>seanbarbour</dc:creator>
      <dc:date>2018-02-15T13:55:59Z</dc:date>
    </item>
    <item>
      <title>Re: Rest calls from PowerShell failing</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/rest-calls-from-powershell-failing/m-p/287829#M2030</link>
      <description>&lt;P&gt;Good stuff! Thanx!&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 11 Sep 2019 08:29:47 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/rest-calls-from-powershell-failing/m-p/287829#M2030</guid>
      <dc:creator>santonic</dc:creator>
      <dc:date>2019-09-11T08:29:47Z</dc:date>
    </item>
    <item>
      <title>Re: Rest calls from PowerShell failing</title>
      <link>https://live.paloaltonetworks.com/t5/automation-api-discussions/rest-calls-from-powershell-failing/m-p/289395#M2036</link>
      <description>&lt;P&gt;This.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Powershell does not like the TLS versions used by default on the firewall - also in your "intro" block, I see disabling certificate checking, which is another common error that someone may be able to fix if google leads them to your post.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;I have a "default" i build all my PS scripts from that includes this block and a few calls to obtain the API key because of this.&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Note, sometimes these commands require elevation in PS or a change in executionpolicy, but I have not seen this recently, so an update may have changed that behavior.&lt;/P&gt;</description>
      <pubDate>Fri, 20 Sep 2019 19:28:16 GMT</pubDate>
      <guid>https://live.paloaltonetworks.com/t5/automation-api-discussions/rest-calls-from-powershell-failing/m-p/289395#M2036</guid>
      <dc:creator>jandreini</dc:creator>
      <dc:date>2019-09-20T19:28:16Z</dc:date>
    </item>
  </channel>
</rss>

