Dashboards & Visualizations

Rest API not allowing me to escape ampersands

bruceclarke
Contributor

Hey,

I'm trying to create a dashboard using the rest API. However, I'm running into an issue where it isn't letting me supply an escaped ampersand into the dashboard. Here is an example that fails:

curl -k -u admin:changeme https://localhost:8089/servicesNS/nobody/search/data/ui/views/ -d "name=foobar3&eai:data=<dashboard><label>I want to use the ampersand character (%26 or &amp;amp; or &)</label></dashboard>"

How can I add an ampersand to my XML?

1 Solution

bruceclarke
Contributor

Actually, I was just able to figure out the issue. If you escape the semicolon too, then this will work. So, here is the correct way to create a dashboard that uses an ampersand:

curl -k -u admin:changeme https://localhost:8089/servicesNS/nobody/search/data/ui/views/ -d "name=foobar3&eai:data=To use an ampersand, escape both the ampersand %26amp%3B semicolon."

View solution in original post

bruceclarke
Contributor

Actually, I was just able to figure out the issue. If you escape the semicolon too, then this will work. So, here is the correct way to create a dashboard that uses an ampersand:

curl -k -u admin:changeme https://localhost:8089/servicesNS/nobody/search/data/ui/views/ -d "name=foobar3&eai:data=To use an ampersand, escape both the ampersand %26amp%3B semicolon."

MuS
Legend

Hi bruceclarke,

Nice finding!
It really looks like this is not supported or a bug; as soon as one add's an & inside the label tag it will be used as XML tag opener. Tried using the XML tag opener![CDATA[ as well without any luck.

My Suggestion: file a bug here http://www.splunk.com/r/bugs

cheers, MuS

bruceclarke
Contributor

I was hoping there would be a workaround. I'll file an issue there and ask about any possible workarounds for the time being. Thanks!

0 Karma

woodcock
Esteemed Legend

Why are you using & instead of AND after foobar3? Also, there is no name field for that endpoint's data (although there is a title field). You have to fix those problems first and maybe that is what is causing your search failure. if you really need to escape the &, perhaps you can bypass needing it altogether by using | where match($eai_data$,"RegExHere") and skipping over it with RegEx (wildcards).

0 Karma

bruceclarke
Contributor

Those shouldn't be the issue. I'm able to run the command below just fine. The command below creates a dashboard that's stored as foobar3.xml (on the backend) and the title of the dashboard (on the front end) is "My RESTful dashboard"

curl -k -u admin:changeme https://localhost:8089/servicesNS/nobody/search/data/ui/views/ -d "name=foobar3&eai:data=My RESTful dashboard"

Naturally, the comment field is not showing my dashboard and label XML tags (I guess Splunk Answers assumes it is HTML code), but that's part of the eai:data field as well.

0 Karma
Get Updates on the Splunk Community!

Stay Connected: Your Guide to May Tech Talks, Office Hours, and Webinars!

Take a look below to explore our upcoming Community Office Hours, Tech Talks, and Webinars this month. This ...

They're back! Join the SplunkTrust and MVP at .conf24

With our highly anticipated annual conference, .conf, comes the fez-wearers you can trust! The SplunkTrust, as ...

Enterprise Security Content Update (ESCU) | New Releases

Last month, the Splunk Threat Research Team had two releases of new security content via the Enterprise ...