REST API and Powershell

Not applicable

REST API and Powershell

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 status="success">



               <.....generated key.....>




Tags (3)
L5 Sessionator

Re: REST API and Powershell


URL encode for & is %26 I am not why you have that extra "amp" in there, may be that is causing the issue ?

L2 Linker

Re: REST API and Powershell

Try this

$HostPA = "http://hostname"

[xml]$content = Invoke-WebRequest "$HostPA/api/?type=keygen&user=user-name&password=user-password"

$apiKey = $content.response.result.key


Not applicable

Re: REST API and Powershell

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.

Like what you see?

Show your appreciation!

Click Like if a post is helpful to you or if you just want to show your support.

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 Live Community as a whole!

The Live Community thanks you for your participation!