Andrew Barnes

3 minute read

IntegrationHub week is still going strong! The last two new Paris related features I will highlight on the blog will be the Payload Builder API and the JSON Parser action step.

JSON Parser

Building and extending spokes is one of my current favorite things to develop. One of the most common parts of integration is handling the response. Introduced in the New York release was the XML Parser step. With the Paris release, the other main format, JSON, is handled with the JSON parser step. If you are familiar with how the XML Parser step works, the JSON Parser interface works the same way.


Above, you can see an example of using the new step. At dot 1, you add in the data pill for the JSON object to be parsed. Typically this is the response body but can be any JSON object. In the large box at dot 2, is where an example of the JSON should be placed. Run a test of the action to the remote system to get an example payload and then paste that into box 2 and click Generate Target at dot 3. In box 4 you should now see a complex object that has been generated from the source JSON example. You can edit the object as needed before moving on to the next step of your integration setup. Once the step is completed, you will have a complex object with a data pill that is useable from all future steps in the action.

Payload Builder API

The payload builder step currently available in action designer is capable of building simple payloads. Once you get to more advanced setups, scripting must be utilized to craft the payloads for integrations. In order to facilitate the crafting of these payloads, a new plugin has been provided, com.glide.streaming_builder. It introduces two new APIs, one for JSON and one for XML. Documentation for the Streaming Builder, and Streaming API can be found on the Developer Site API reference for sn_ih.

var ttl = new GlideDateTime(b2020-10-10 12:00:00b);b
var builder = new sn_ih.XMLStreamingBuilder()b

var inc = new GlideRecord("incident");
        .writeStringField("short_description", inc.getValue("short_description"))
        .writeStringField("caller"), inc.getValue("caller_id")
        .writeStringField("number"), inc.getValue("number")
outputs.attachment = builder.getAttachmentId();

In the example above, you can see the creation of the builder object. The default return is a string, but in this case, I chose to set the .withAttachment() to get a sys_id of the created attachment as the output to send to the next step in the action. Additionally, I have set a time to live with the ttl variable with the expireAt method. The attachment is stored in a new table streaming_attachment to hold the attachments. A typical GlideRecord object query is set up and performed. Inside the iterator over the resulting inc object uses the XMLStreamingAPI methods, startObject, writeStringField, endObject, and close to populate the data in the XML streaming object.

More changes

There are a few more enhancements that you can explore in IntegrationHub for Paris in the docmentation. Let us in the Developer Program know if we need to cover one of those in more detail in a future blog. Check out this week’s Live Coding Happy Hour to see some of these enhancements in action!