- Access exclusive content
- Connect with peers
- Share your expertise
- Find support resources
02-27-2015 02:11 PM
Has anyone used Powershell to interact with REST API on PA500?
When I use the Invoke-RestMethod cmdlet to try and generate a key, I get back an empty response. If I run the keygen through a browser, it successfully returns a key. Running 6.1.1.
PS C:> Invoke-RestMethod -Uri http://<ip-of-PA500>/api/?type=keygen%26ampuser=<adminuser>%26amppassword=<adminpassword>
response
-------------
response
http://<ip-of-PA500>/api/?type-keygen&user=<adminuser>&password=<adminpassword>
<response status="success">
<result>
<key>
<.....generated key.....>
</key>
</result>
</response>
02-27-2015 05:51 PM
Try this
$HostPA = "http://hostname"
[xml]$content = Invoke-WebRequest "$HostPA/api/?type=keygen&user=user-name&password=user-password"
$apiKey = $content.response.result.key
$apiKey
02-27-2015 02:48 PM
URL encode for & is %26 I am not why you have that extra "amp" in there, may be that is causing the issue ?
02-27-2015 05:51 PM
Try this
$HostPA = "http://hostname"
[xml]$content = Invoke-WebRequest "$HostPA/api/?type=keygen&user=user-name&password=user-password"
$apiKey = $content.response.result.key
$apiKey
03-02-2015 11:53 AM
That worked...although I'm puzzled as to why Invoke-RestMethod did not.
I retried the same steps you listed but replaced Invoke-WebRequest with Invoke-RestMethod. It worked as well.
Essentially, applying the xml bracket and assigning the output of the command to a variable, let me pull out the relevant information. However, I wasn't expecting it to work that way. I had hoped the cmdlet would output the entire XML stream to the display and not need me to specify the specific data portions.
Click Accept as Solution to acknowledge that the answer to your question has been provided.
The button appears next to the replies on topics you’ve started. The member who gave the solution and all future visitors to this topic will appreciate it!
These simple actions take just seconds of your time, but go a long way in showing appreciation for community members and the LIVEcommunity as a whole!
The LIVEcommunity thanks you for your participation!