Panorama PowerShell RESTAPI Error

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Panorama PowerShell RESTAPI Error

L0 Member

Good morning,

 

  I am attempting to streamline some massive object uploads into the Panorama after PowerShell massages the data first. I am running into an issue getting my GET / POST functions to work correctly when making the calls and was hoping someone would have some advice here.

I am running the below command to attempt the Push to add a test object and am receiving the error pasted after:

 

$response = Invoke-RestMethod -Method Post -Header $xkey -Uri $panoFQDNURL -Body $customObject -ContentType 'application/json'

 

The error received is "Invoke-RestMethod : {"code":3,"message":"Invalid Body","details":[{"@type":"CauseInfo","causes":[{"code":9,"module":"pan_api","description":"Invalid Body"}]}]}"

I have attempted multiple ways of formatting the $customObject data to no avail. I feel I am missing something small and am just overlooking it after digging through a bunch of forum posts here and the documentation.

 

Below is the current method I have utilized for creating the $customObject:

 

$configobject = [pscustomobject]@{
'@location' = $location
'device-group' = $devicegroup
'@name' = $name
'description' = $description
'fqdn' = $fqdn
}

$customObject = ConvertTo-Json $configobject

 

The @location is being defined as 'device-group' and I have verified the device group, fqdn, description and name variables populate correctly. I have attempt using Invoke-WebRequest as well with the same result.

 

The url I have is below:

 

https://x.x.x.x/restapi/vX/Objects/Addresses?location=device-group&device-group=XXX&name=FQDNNAME

 

I have verified the variable produces the correct IP address, version, device-group name, and FQDN Name for the new object.

 

Any API guru's in here have any advice? I am admittedly a novice when it comes to dealing with API calls from PowerShell so I'm hoping this is something simple I'm overlooking.

2 REPLIES 2

Cyber Elite
Cyber Elite

Hi @JonButterfield ,

 

The specific error you are getting is "Invalid Body" which means the URL is correct, but the JSON is not formatted correctly, e.g. bad syntax or parameter.

 

I like to test the URL, header, and body separately from code in order to verify I have the syntax and parameters correct before coding.  A good tool for this testing is Postman.  https://www.postman.com/  It is free and has Windows, Mac, and Linux clients.

 

You could print the JSON body to the CLI to verify the syntax.  I don't know PowerShell hash tables very well.  Is the [pscustomobject] supposed to be [ordered]?

 

At 1st glance, the syntax appears to be correct.  https://docs.paloaltonetworks.com/pan-os/11-1/pan-os-panorama-api/get-started-with-the-pan-os-rest-a...

 

Thanks,

 

Tom

 

 

Help the community: Like helpful comments and mark solutions.

L4 Transporter

Hello @JonButterfield ,

 

Source of info : https://your_panorama/restapi-doc/

 

The body is supposed to contain the entry you want to send.

{
  "entry": {
// here if the object is an ip-netmask type
    "ip-netmask": "string",
    "tag": {
      "member": [
        "string"
      ],
// in the restapi-doc, it seems @name is required too
    "@name": "name"
    }
  }
}

$configobject is mean to be in the query parameter.

 

@TomYoung +1 for the postman option.

 

Olivier

PCSNE - CISSP

Best Effort contributor

Check out our PANCast Channel

Disclaimer : All messages are my personal ones and do not represent my company's view in any way.

  • 316 Views
  • 2 replies
  • 0 Likes
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 LIVEcommunity as a whole!

The LIVEcommunity thanks you for your participation!