Skip to Content

Scripting example in Jitterbit App Builder - Return a field as XML

This Plugin example script will return a field in your data object via the REST endpoint as XML, making it consumable by other applications and platforms. See the Configuration Notes for implementing this Plugin in App Builder.

Example script

#r "Newtonsoft.Json.dll"
using System;
using System.Net.Http;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
/**
 The format of the json produced by App Builder is:
 {
     items: [
       {
           "field1": "value",
           "field2": "value",
           "field3": "value",
           ...
       }
       ...
     ]
 }

 This plugin is grabbing the FIRST item returned (["items"][0])

 We then look for a particular field containing xml - in this case "xmlCode"

 We then return this as the xml content - discarding the rest of the message
**/
// Read the response content
var message = await Response.Content.ReadAsStringAsync();
var jobject = JObject.Parse(message);
// This is likely always the same - the first item returned
var item = jobject["items"][0];
// Change xmlCode to match the name of the field in your object:
var xmlContent = item["xmlCode"].ToString();
// Return just the xmlContent
Response.Content = new StringContent(xmlContent, null, "application/xml");

Configuration notes

  1. When configuring the Plugin in App Builder, use the following values:

    • Name: ReturnXmlFromJson
    • Description: Pick out xml returned from within json and return as just xml
    • Purpose: Rest Response
  2. When configuring the XMP Endpoint in App Builder, click on Edge Case Settings and set the Endpoint Plugin Response value to ReturnXmlFromJson

  3. When configuring the REST API Web Service, set the Request Content Type value to JSON and Response Content Type to XML