Variables Cheat Sheet

List of all defined variables and their usage.

Note that JSONPath can only be used with request payload.

Variable Contains
input Request payload as XML or JSON
XQ: $input//*:id
Javascript: input.account.id
JSONPath: $..id
request Alias for input
output Response payload. Only available after the response payload is generated
XQ: $output//*:status
Javascript: output.status.code
response Alias for output
accounts Array of accounts selected for this response
XQ: for $a in $accounts return $a/*:id
Javascript: accounts[0].id
account Single account selected for this response. If there are multiple matching accounts, a random account from that list
XQ: $account/*:id
Javascript: account.id
http.method Request HTTP method (GET, POST, etc)
XQ: $http//*:method/text()
Javascript: http.method
http.relativeURI Relative URL from the service base
XQ: $http//*:relativeURI/text()
Javascript: http.relativeURI
http.queryString Query string (a part of request after ? symbol)
XQ: $http//*:queryString/text()
Javascript: http.queryString
http.parameters.parameter Query parameters. There are could be multiple entries for a parameter, hence XML may contain multiple parameter nodes and JSON then would contain an array of values
XQ: $http//*:parameter[@name='username']/text()
Javascript: http.parameters.accountid
http.headers.header HTTP request headers. There are could be multiple headers with the same name
XQ: $http//*:header[@name='X-UserName']/text()
Javascript: http.headers.accountid
rest.method Request HTTP method (GET, POST, etc). Same as http.method
XQ: $rest//*:method/text()
Javascript: rest.method
rest.relativeURI Relative URL from the service base. Same as http.relativeURI
XQ: $rest//*:uri/text()
Javascript: rest.uri
rest.parameters.parameter URI variables. E.g. userid in /foo/{userid}/add
XQ: $rest//*:parameter[@name='userid']/text()
Javascript: rest.parameters.userid
mockmeta.randomUUID Random UUID generated per request
XQ: $mockmeta//*:randomUUID/text()
Javascript: mockmeta.randomUUID
mockmeta.random Random value in a rang from 0 to 1 generated per request, e.g. 0.17943574832
XQ: $mockmeta//*:random/text()
Javascript: mockmeta.random
mockmeta.epochMs Number of milliseconds since epoch, i.e. since Jan 1st, 1970
XQ: $mockmeta//*:epochMs/text()
Javascript: mockmeta.epochMs
mockmeta.environment.* Current environment stats: number of calls and errors
XQ: $mockmeta/*:environment/*:calls/text() and $mockmeta/*:environment/*:errors/text()
Javascript: mockmeta.environment.calls and mockmeta.environment.errors
mockmeta.service.* Current service stats: number of calls and errors
XQ: $mockmeta/*:service/*:calls/text() and $mockmeta/*:service/*:errors/text()
Javascript: mockmeta.service.calls and mockmeta.service.errors
mockmeta.reaction.* Current reaction stats: number of calls and errors
XQ: $mockmeta/*:reaction/*:calls/text() and $mockmeta/*:reaction/*:errors/text()
Javascript: mockmeta.reaction.calls and mockmeta.reaction.errors

Examples of Variables

HTTP

XML $http variable for /R22/Account/DeleteMe?id=500100 where environment URL is /R22 and service URL is /Account:

  <http>
      <method>POST</method>
      <relativeURI>DeleteMe</relativeURI>
      <queryString>id=500100</queryString>
      <parameters>
         <parameter name="id">500100</parameter>
      </parameters>
      <headers>
         <header name="Connection">keep-alive</header>
         <header name="User-Agent">Apache-HttpClient/4.1.1 (java 1.5)</header>
         <header name="Host">localhost:7080</header>
         <header name="Accept-Encoding">gzip,deflate</header>
         <header name="Content-Length">11</header>
         <header name="Content-Type">application/xml</header>
      </headers>
   </http>

Same variable http as JSON:

{
   "headers":    {
      "Connection": "keep-alive",
      "User-Agent": "Apache-HttpClient/4.1.1 (java 1.5)",
      "Host": "localhost:7080",
      "Accept-Encoding": "gzip,deflate",
      "Content-Length": "18",
      "Content-Type": "application/json"
   },
   "method": "POST",
   "queryString": "id=500100",
   "parameters": {
	"id":"500100"
   },
   "relativeURI": "DeleteMe"
}

REST

XML $rest variable for /SelfTest/REST/customers/12345/orders, where the environment URL is /SelfTest, service URL is /REST and the relative URL is expected to match customers/{customerId}/orders in the reaction:

   <rest>
      <method>GET</method>
      <relativeURI>customers/12345/orders</relativeURI>
      <parameters>
         <parameter name="customerId">12345</parameter>
      </parameters>
   </rest>

And the same variable rest as JSON:

{
   "method": "GET",
   "relativeURI": "customers/12345/orders",
   "parameters": {
	"customerId": "12345"
   }
}

Meta

Variable $mockmeta in an XML reaction:

   <meta>
      <environment>
         <calls>15</calls>
         <errors>0</errors>
      </environment>
      <service>
         <calls>15</calls>
         <errors>0</errors>
      </service>
      <reaction>
         <calls>14</calls>
         <errors>0</errors>
      </reaction>
      <random>0.8440466800253926</random>
      <randomUUID>cf68d2cc-900e-403b-b98b-c184df7b34c2</randomUUID>
      <epochMs>1494197982826</epochMs>
   </meta>

And variable mockmeta in a JSON reaction:

{
   "reaction":    {
      "errors": 0,
      "calls": 13
   },
   "environment":    {
      "errors": 0,
      "calls": 28
   },
   "randomUUID": "cbccd579-4399-4d2f-b2f7-7581aaa752da",
   "service":    {
      "errors": 0,
      "calls": 28
   },
   "random": 0.5014546023803725,
   "epochMs": 1494198022337
}