Ampersand in API request

cancel
Showing results for 
Search instead for 
Did you mean: 

Ampersand in API request

L1 Bithead

Hi, colleagues!

I have a "Custom URL Category" and I try to add new URL from API request but if URL have ampersand(&) I have a error: <response status="error" code="18"><msg><line>Malformed Request</line></msg></response>

PanOS: 5.0.8

Original URL: example.com/proxy/index.php?hl=1111101001&q=789

My API request: https://HOST-IP/api/?type=config&action=set&key=API-KEY&xpath=/config/devices/entry[@name='localhost...<list><member>example.com/proxy/index.php?hl=1111101001&q=789</member></list>

If I add this URL manual I have't error, all OK, after that I look configuration in XML format and my URL looks like example.com/proxy/index.php?hl=1111101001&amp;q=789 -- in XML if you need use & you must use &amp;

OK! I change my API request: https://HOST-IP/api/?type=config&action=set&key=API-KEY&xpath=/config/devices/entry[@name='localhost...<list><member>example.com/proxy/index.php?hl=1111101001&amp;q=789</member></list>

but no different Smiley Sad
Anybody know how resolve this problem ?

P.S.: sorry for my english.

6 REPLIES 6

L5 Sessionator

Hi,

Have you try something like:

Creating a new custom URL category:

http(s)://hostname/api/?type=config&action=set&xpath=/config/devices/entry/vsys/entry[@name='vsys1']/pro

files/custom-url-category/entry[@name='xmltest urlcat']&element=<description>testing xml

api</description><list><member>www.somesite.com</member></list>

Adding a URL to a custom URL category:

http(s)://hostname/api/?type=config&action=set&xpath=/config/devices/entry/vsys/entry[@name='vsys1']/pro

files/custom-url-category/entry[@name='xmltest

urlcat']/list&element=<list><member>www.somesite.com</member></list>

Adding an address object:

http(s)://hostname/api/?type=config&action=set&xpath=/config/devices/entry/vsys/entry[@name='vsys1']/add

ress/entry[@name='xmltest addr']&element=<ip-netmask>1.2.3.4/32</ip-netmask><description>xml

testing</description>

Hope help.

v.

Hi!

Thank you for answer.

I try this... but I have problem if URL contain &, if I delete this symbol from URL -- all OK.

I try use &amp; instead & of but no results.

Hi,

Have you try to encode the "&" in utf ? use &#38 in your request.

Let us know.

v.

All my trying and results(I am using cURL).

URL: example.com/proxy/index.php?hl=1111101001&#38q=789

> GET /api/?type=config&action=set&key=APIKEY&xpath=/config/devices/entry[@name='localhost.localdomain']/vsys/entry[@name='vsys1']/profiles/custom-url-category/entry[@name='FEDERAL-LOW']&element=<list><member>example.com/proxy/index.php?hl=1111101001& HTTP/1.1

> User-Agent: curl/7.26.0

> Host: 172.16.1.164

> Accept: */*

> Content-Type: application/xml; charset=UTF-8

##########

URL: example.com/proxy/index.php?hl=1111101001&amp;q=789

> GET /api/?type=config&action=set&key=APIKEY&xpath=/config/devices/entry[@name='localhost.localdomain']/vsys/entry[@name='vsys1']/profiles/custom-url-category/entry[@name='FEDERAL-LOW']&element=<list><member>example.com/proxy/index.php?hl=1111101001&amp;q=789</member></list> HTTP/1.1

> User-Agent: curl/7.26.0

> Host: 172.16.1.164

> Accept: */*

> Content-Type: application/xml; charset=UTF-8

##########

URL: example.com/proxy/index.php?hl=1111101001&q=789

> GET /api/?type=config&action=set&key=APIKEY&xpath=/config/devices/entry[@name='localhost.localdomain']/vsys/entry[@name='vsys1']/profiles/custom-url-category/entry[@name='FEDERAL-LOW']&element=<list><member>example.com/proxy/index.php?hl=1111101001&q=789</member></list> HTTP/1.1

> User-Agent: curl/7.26.0

> Host: 172.16.1.164

> Accept: */*

> Content-Type: application/xml; charset=UTF-8

Response from PaloAlto:

<response status="error" code="18"><msg><line>Malformed Request</line></msg></response>

I think this is a current limitation of API as GUI accepts URL which contains "&". But I believe we don't usually include URL parameters (e.g. "?hl=1111101001&q=789") in Custom URL Category setting because the URL parameter value dynamically changes and URL Category should not change depending on the parameter.

If you want to allow / block http request depending on the URL parameters, I guess it would be better if it's done on the server side.

- Yasu

L1 Bithead

If you have & in URL you need replace it for %26amp;

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!