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
Career Survey
First 500 qualified respondents will receive a $20 gift card! Tell us about your professional Splunk journey.

Can’t make it to .conf25? Join us online!

Get Updates on the Splunk Community!

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Are you leveraging automation to its fullest potential in your threat detection strategy?Our upcoming Security ...

Can’t Make It to Boston? Stream .conf25 and Learn with Haya Husain

Boston may be buzzing this September with Splunk University and .conf25, but you don’t have to pack a bag to ...

Splunk Lantern’s Guide to The Most Popular .conf25 Sessions

Splunk Lantern is a Splunk customer success center that provides advice from Splunk experts on valuable data ...