- Access exclusive content
- Connect with peers
- Share your expertise
- Find support resources
09-13-2022 03:00 PM
i'm trying to update a field on an address using the api (switching it from 'ip-netmask' to 'fqdn') i have called this api:
https://10.30.100.31/api/?key=<API_KEY>&type=config&action=edit&xpath=/config/shared/address as a PUT, and passed in the entry. the api response is 200. i then commit the action, and get another 200.
but the changes aren't reflected in the ui when i check.
i looked at this page in the documentation:
and it gives me a completely different api than i have used for anything else ("https://<firewall>/restapi/v10.2/Objects/Addresses" as opposed to "https://<firewall>/api/?key") and that api gives me a 'Not implemented" error when i try it.
i am able (using the top api) to query the firewalls and get all the data that i need, but i cannot update it.
any ideas?
09-15-2022 01:26 AM
Hi @MarketAxess,
That API call looks like a mixture of the XML API and the REST API. I suggest going to the documentation I linked (link) and reading the differences between the two, and then choosing one. An alternative would be to use either pan-python (thin SDK) or pan-os-python (object-oriented SDK) Python SDKs so you don't have to reinvent the API calls in your own Python code.
An XML API call to Panorama to edit an address object from IP to FQDN would look something like this:
https://{{host}}/api/?key={{key}}&type=config&action=edit&xpath=/config/devices/entry[@name='localhost.localdomain']/device-group/entry[@name='{{device-group-name}}']/address/entry[@name='{{object-name-1}}']&element=<entry name="{{object-name-1}}"><fqdn>{{fqdn-1}}</fqdn></entry>
A REST API call to Panorama to edit an address object from IP to FQDN would look something like this, with PUT as the method, X-PAN-KEY in the headers:
https://{{host}}/restapi/v10.0/Objects/Addresses?location=device-group&device-group={{device-group-name}}&name={{object-name}}
and a body like this:
{
"entry": {
"@name": "{{object-name-1}}",
"fqdn": "{{fqdn-1}}"
}
}
Hope that helps!
09-14-2022 02:55 AM - edited 09-15-2022 01:26 AM
Hi @MarketAxess, there are two APIs for PAN-OS; the XML API (broadest coverage) and the REST API (documented on-box at /restapi-doc and has fuller RBAC), ad these two are discussed in the docs: https://docs.paloaltonetworks.com/pan-os/10-2/pan-os-panorama-api/about-the-pan-os-xml-api
On both your first API query (XML API) and your second API query (REST API) we'd need to see the entire API call and all parameters and JSON body to understand why it did not achieve your objective. If you could clarify if this is Panorama or NGFW direct that would also help.
09-14-2022 02:11 PM
Hello, Jimmy. thanks for your response. here's what i have:
change_call: https://10.30.100.31/api/?key=API_KEY&type=config&action=edit&xpath=/config/shared/address
headers: {'X-PAN-KEY': 'API_KEY'}
data: {'entry': [{'@name': 'QA1ASHSQLDB01_10.31.44.61', 'fqdn': 'qa1ashmfdb01.qad.root', 'description': 'CHG0038490'}]}
change response: Response [200]
commit_call: https://10.30.100.31/api/?key=API_KEY&type=commit&cmd=\<commit\>\</commit\>
commit response: Response [200]
i am using python to make the calls, using the request object. the first call is a PUT
the second is a GET
in debugging, i see this error with the 200 response:
'Invalid target object in edit handler'
this is connecting to panorama
09-15-2022 01:26 AM
Hi @MarketAxess,
That API call looks like a mixture of the XML API and the REST API. I suggest going to the documentation I linked (link) and reading the differences between the two, and then choosing one. An alternative would be to use either pan-python (thin SDK) or pan-os-python (object-oriented SDK) Python SDKs so you don't have to reinvent the API calls in your own Python code.
An XML API call to Panorama to edit an address object from IP to FQDN would look something like this:
https://{{host}}/api/?key={{key}}&type=config&action=edit&xpath=/config/devices/entry[@name='localhost.localdomain']/device-group/entry[@name='{{device-group-name}}']/address/entry[@name='{{object-name-1}}']&element=<entry name="{{object-name-1}}"><fqdn>{{fqdn-1}}</fqdn></entry>
A REST API call to Panorama to edit an address object from IP to FQDN would look something like this, with PUT as the method, X-PAN-KEY in the headers:
https://{{host}}/restapi/v10.0/Objects/Addresses?location=device-group&device-group={{device-group-name}}&name={{object-name}}
and a body like this:
{
"entry": {
"@name": "{{object-name-1}}",
"fqdn": "{{fqdn-1}}"
}
}
Hope that helps!
09-15-2022 11:12 AM
thanks so much. that was the problem, i was trying to meld the two. all is working now.
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!