Sending XML via HTTP Post

I recently had a customer ask if there were any way to submit XML data to a service-now instance for processing. My first response was, “Yes! SOAP Web Services”. For some reason, however, their integrating platform was incapable of sending SOAP messages, but it could perform an HTTP Post of XML data.

I played around with a couple of ideas and got a rudimentary method of getting XML into a ServiceNow instance via an HTTPS Post.

The best idea of the ones I tested was to create a UI Page in the ServiceNow system. That UI page could be written so that it looks for a POST parameter that would contain XML. In this example, I chose a post parameter named “myXML”. The UI Page would not be public, so the client would have to authenticate using Basic Authentication.

Here is my UI Page that I created:

ServiceNow UI Page for receiving XML via a POST parameter

The jelly code (as seen in the screenshot) is:

1
2
3
4
5
6
7
8
<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">

<g:evaluate>
gs.log("SUBMITED XML: " + RP.getParameterValue("myXML"));
</g:evaluate>

</j:jelly>

Essentially, I created a tag in the Jelly script called “<g:evaluate>”. This tag tells the Jelly to execute the following server side javascript when the page is rendered/loaded.

Then, I used a global variable in the UI Pages called “RP”. This is an object that contains the HTTP Request information. It has a function called “getParameterValue” that allows me to specific a POST Parameter and get the value for that parameter. In our case, this will be the “myXML” parameter that we are expecting.

Then, I just log that XML to the log file.

Now to test this UI Page, I wanted to create an HTML form that would send a POST of XML data to my Instance. This was a quick a dirty way of letting me play around without creating a client program that sends XML to the instance via HTTP Post. A browser will do it for you quickly enough, as long as the browser is currently authenticated to the instance. So, for testing purposes, here is the html form that I created and saved on my local disk (eg. c:\delme\test.html) to do my testing with:

1
2
3
4
5
6
7
8
9
10
<html>
<body>
    Place your HTML Here:<br>
<form method="POST" action="https://myinstance.service-now.com/TestXmlPost.do">
<textarea name='myXML' cols='80' rows='10'>
</textarea>
<input type='submit'/>
</form>
</body>
</html>

Notice that the “action” on my html form points to the UI Page that I created on my instance.

So, when I load my test form and enter in XML data it will look like this on my custom webpage:

XML in POST form

When I click “Submit”, the myXML field data will be sent to our UI Page for processing. If you look at the log file after clicking Submit, you will see the following:

Log Results of XML Post

As you can see, the full XML value was captured inside of the instance. You could now manipulate the XML to do what you want it to do. Probably the most popular thing to do would be to process the XML via an Import Set as seen on my blog here:
https://john-james-andersen.com/blog/service-now/converting-xml-to-a-record-in-servicenow.html