Retrieve External Data as Variables

One of the handlers available in MEP services, known as the Get External Data handler, can retrieve data from an external source such as your platform or a third party site. The retrieved data is stored as variables that you can then reference in the service. For example, your service could retrieve the latest weather and news and then send the information on in an SMS message.

The handler uses a simple HTTP request to retrieve data, which must use one of the following formats:

  • XML - parsed and turned into a series of variables
  • JSON - parsed and turned into a series of variables
  • plain text - creates the variable scope.text with the text as the value.
    E.g. if you use the handler to retrieve plain text data and set the scope to "session", there is only one variable created: session.text and the value is the returned plain text.

There is no predefined template for the format of XML or JSON responses. MEP will parse XML and JSON into a series of variables and return a success outcome.

The handler ignores any external DTD references in XML responses.

Requirements for retrieving data

To ensure the authenticity of requests, you should only accept requests from the following OpenMarket IP addresses:

  • - (
  • - (
  • - (
  • - (
  • - (

You can optionally specify an HTTPS (SSL) URL.

The external data source should return a 200 OK response, with the body containing data as plain text, or well-formed XML or JSON.

If the external data source is not available or returns an HTTP response code other than 200, the handler will retry until either the request is successful, or the handler times out. If you need the handler to return the failed outcome more quickly, you can manually configure the timeout settings using the "additional information" options when editing the handler.

If the returned XML is not valid then the failed outcome is triggered immediately.

Error conditions at the server should be conveyed using the XML output, not HTTP status codes.

Referencing XML or JSON as variables

The Get External Data handler creates a variable for each XML or JSON element. When retrieved:

  • The scope for all of the variables is set in the handler.
  • Each element name is a variable key.
  • The content of each element is interpreted as the variable's value.

In the following examples, the keys are:

  • date with a value 20120518
  • flight with a value 209
  • mealoptions.meal1 with a value steak
  • mealoptions.meal2 with a value fish

XML example

<?xml version="1.0" ?>

JSON example


To reference the variables, you need to enclose the variable key in square brackets and quote marks (single or double), for example:


XML attribute information

You can also extract attribute information from XML. This is referenced using the format tagname@attribute.


In this XML example:

<?xml version="1.0" ?>
<animal type="dog">
   <name>Mr Woofy</name>
   <breed size="small">dachshund</breed>

you could reference the type attribute ("dog") and the size attribute ("small") using the following expressions:


If the XML contains multiple elements with the same name, for example:

<?xml version="1.0"?>
   <title>Apollo 13</title>
   <actor>Tom Hanks</actor>
   <actor>Bill Paxton</actor>
   <actor>Kevin Bacon</actor>

they are accessible using "xml[n]", where n starts at zero, for example:




Tom Hanks


Bill Paxton


Kevin Bacon

If you have experience with other programming languages, you may notice that the notation used here is similar to that used for arrays. However, it is not possible to iterate through the values using EL. You need to explicitly refer to values by their numbers.