Skip to content

Script Reference

Joe Bellus edited this page Aug 12, 2017 · 2 revisions

Script Objects

$variables

Gives access to get and set configuration variables.

  • $variables.get(name) - Returns a variable from the either the local or global configuration. The local configuration is given priority. These values are always returned as strings.
  • $variables.set(name, value) - Sets a variable and saves it to the local configuration.

$request

Gives access to the information for the request.

  • $request.contentLength - Contains the number of bytes for the request payload. This only applies to POST requests.
  • $request.URL - Contains the full URL for the request. This will include any query parameters.
  • $request.baseURL - Contains the url for the request without any query parameters.
  • $request.setBody(contents) - Sets the request body to a given string. This is only useful for transform scripts.
  • $request.headers.get(name) - Returns the header value for a given name.
  • $request.headers.set(name) - Sets the header value for a given name.

Response

The response given back from the request.

  • $response.body - Contains the response data as a string.
  • $response.contentLength - Contains the length, in bytes, of the response.
  • $response.headers.get(name) - Returns the header value for a given name.

Helper functions

  • $hmac(secret, data) - Returns an HMAC signature for the given data using the given secret key.

Example Scripts

Save a variable from the response

json = JSON.parse($response.body)
$variables.set("name", json.data.name)

Append a value to the request from a variable

json = JSON.parse($request.body)
json.data.key_secret = $variables.get("secret")
$request.setBody(JSON.stringify(json)