Adding an additional URL to a Custom URL Category using XML-API

Reply
L1 Bithead

Adding an additional URL to a Custom URL Category using XML-API

How can I add an additional URL to an existing Custom URL Category using XML-API.  I have been trying variations of the following command:


https://00.0.0.00/api/?type=config&action=set&key=authkey&path=/config/devices/entry[@name='localhost.localdomain']/vsys/entry[@name='vsys1']/profiles/custom-url-category/entry[@name='MS_WHITE']&element=<member>www.goodsite.com</member>


When I enter this command it returns this error:

<![CDATA[ unexpected here ]]>


Does anyone know how I can make this work.  Thank you.

SRA
L4 Transporter

Re: Adding an additional URL to a Custom URL Category using XML-API

http(s)://hostname/api/?type=config&action=set&xpath=/config/devices/entry/vsys/entry[@name='vsys1']/profiles/custom-url-category/entry[@name='xmltest urlcat']/list&element=<list><member>www.somesite.com</member></list>

Check the FAQ section in the API guide for this and other examples.

L1 Bithead

Re: Adding an additional URL to a Custom URL Category using XML-API

Hi Savasarala.  Thank you for your help.  I see the examples in the API Guide now.  When I use this command,  I geth the following error:

<![CDATA[ -> list -> list has unexpected text. ]]>


Thoughts?

Not applicable

Re: Adding an additional URL to a Custom URL Category using XML-API

I have also tried and received the same error...

<response status="error" code="12">

<msg>

<line>

<![CDATA[ list -> list has unexpected text. ]]>

</line>

</msg>

</response>

Not applicable

Re: Adding an additional URL to a Custom URL Category using XML-API

I was able to successfully make this work using the following URL (specific to my site...please excuse the personalized / non obfuscated naming)

https://panorama/api/?type=config&action=set&xpath=/config/shared/profiles/custom-url-category/entry...<member>www.apitest.com</member><member>www.apitest2.com</member><member>www.apitest3.com</member>

I got some info about cli debug from the following thread that was very helpful

https://live.paloaltonetworks.com/message/11766#11766

basically, the <list></list> tags seemed to be interfering with the /list in the URI (I think...)

I'm not sure if this would be a supported method, however it did work

Thanks

Cully

L1 Bithead

Re: Adding an additional URL to a Custom URL Category using XML-API

Cully's  method also worked for me!  I simply removed the <list></list> tags from my command and it worked.  Thanks Cully!

-CS

Not applicable

Re: Adding an additional URL to a Custom URL Category using XML-API

Glad I could help...you wouldn't happen to know anything about using curl to make the api calls would you?  I'm struggling with a 'User Not Authorized' error

L3 Networker

Re: Adding an additional URL to a Custom URL Category using XML-API

See the below.  The key is use -d for the key= so it is not URL-encoded and --data-urlencode for other parameters.

panxapi from PAN-perl will handle this for you and is a more friendly way to do configuration management using the API without knowing all the API details.

$ cat element.xml

<ip-netmask>10.16.1.10/32</ip-netmask>

$ KEY='cBwvtXHyrHp9EkOmJ/3PxYV5QG9XiMEsJRoBMhhh1Vw='

$ XPATH="/config/devices/entry/vsys/entry/address/entry[@name='smtp-relay']"

$ ELEMENT=`cat element.xml`

$ curl -k https://172.29.9.253/api/ -d "type=config&action=set&key=$KEY" \

> --data-urlencode "xpath=$XPATH" --data-urlencode "element=$ELEMENT"

<response status="success" code="20"><msg>command succeeded</msg></response>

Not applicable

Re: Adding an additional URL to a Custom URL Category using XML-API

Awesome - thank you!

after successful tests there I came up with a template for doing it in python (my preferred language).  Here's an example of that, this function creates a custom url category and returns the response given by the web server - in case anyone is interested in that.

For debugging / testing it also prints out the URL that would have been passed to the API

import urllib, urllib2

   #cat_desc is a description of the url category

   #cat_name is the name of the custom url category

    def create_url_cat(self, cat_name, cat_desc, action='set'):

        self.parameters = dict()

        self.parameters['key'] = 'Y/Xt9o0IK8ISYNnzTF4oJ8SpTis7cYMKb2NiNniMuPUPutJN4CuDASu5ni79twT6'

        self.parameters['type'] = 'config'

        self.parameters['action'] = 'set'

        self.url = 'https://panorama/api/?'

        self.parameters['action'] = action

        self.parameters['xpath'] = '/config/shared/profiles/custom-url-category/entry[@name=\''+ cat_name + '\']'

        self.parameters['element'] = '<description>' + cat_desc + '</description>'

        params = urllib.urlencode(self.parameters)

        response = urllib2.urlopen(self.url, params)

        print self.url + str(params)

        return response.read()

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!