Following is an example of an outboundTransformation. An outbound transformation is applied as a transaction moves from the source system outbound to YOUnite..

It is highly recommended that Inbound & Outbound Transformations is referenced as you walk through this code.

Example Pseudo Code

if action in source system is not a GET nor DELETE (i.e. it is a PUT or POST)
    Make POST request to get access token from external data enriching service
    if access token request succeeds
        if address is not null
            make POST request to enrich address
        if phone is not null
            make POST request to enrich phone
clean leading/trailing whitespace from strings, and clean birthdate
{
  "outboundTransformations": [
    {
      "name": "actionBranch",
      "type": "branch",
      "trueStep": "token",
      "condition": "_action !== 'GET' && _action !== 'DELETE'",
      "falseStep": "finalStep"
    },
    {
      "name": "token",
      "successStep": "addressBranch",
      "url": "https://api.precisely.com/oauth/token",
      "method": "POST",
      "username": "AaAaBbb632lZYWX99999YVs7rvvvvZZZZ",
      "password": "xxaabbccddeeff",
      "formParams": [
        {
          "key": "grant_type",
          "value": "client_credentials"
        }
      ],
      "type": "rest"
    },
    {
      "name": "addressBranch",
      "condition": "isNotNullOrEmpty(_record.address)",
      "trueStep": "address",
      "falseStep": "phoneBranch",
      "type": "branch"
    },
    {
      "name": "address",
      "successStep": "phoneBranch",
      "url": "https://api.precisely.com/addressverification/v1/validatemailingaddress/results.json",
      "method": "POST",
      "headers": [
        {
          "key": "Authorization",
          "value": "Bearer ${_requests['token'].access_token}"
        },
        {
          "key": "Content-Type",
          "value": "application/json"
        }
      ],
      "body": "{\n    \"options\": {\n        \"OutputCasing\": \"M\"\n    },\n    \"Input\": {\n        \"Row\": [\n            {\n                \"AddressLine1\": \"${_record.address}\",\n                \"City\": \"${_record.city}\",\n                \"StateProvince\": \"${_record.state}\",\n                \"PostalCode\": \"${_record.zip}\"\n            }\n        ]\n    }\n}",
      "postScript": "var output = path(_requests, 'address.Output');\nif (Array.isArray(output) && output.length === 1 && output[0].Status !== 'F') {\n  var newAddress = output[0];\n  _record.address = newAddress.AddressLine1;\n  _record.city = newAddress.City;\n  _record.state = newAddress.StateProvince;\n  _record.zip = newAddress['PostalCode.Base'];\n} else {\n  _error = true;\n  _error_message = 'Address validation failed';\n  _next_step = null;\n}\n",
      "type": "rest"
    },
    {
      "name": "phoneBranch",
      "condition": "isNotNullOrEmpty(_record.phone)",
      "trueStep": "phone",
      "falseStep": "finalStep",
      "type": "branch"
    },
    {
      "name": "phone",
      "successStep": "finalStep",
      "url": "https://api.precisely.com/phoneverification/v1/phoneverification",
      "queryParams": [
        {
          "key": "phoneNumber",
          "value": "${_record[\"phone\"]}"
        },
        {
          "key": "includeNetworkInfo",
          "value": "N"
        }
      ],
      "method": "GET",
      "headers": [
        {
          "key": "Authorization",
          "value": "Bearer ${_requests.token['access_token']}"
        }
      ],
      "preScript": "_record.phone = _record.phone.toString().replace(/\\D/g,'')",
      "postScript": "var match = _record.phone.match(/^(\\d{3})(\\d{3})(\\d{4})$/); if (match) _record.phone = '(' + match[1] + ') ' + match[2] + '-' + match[3];",
      "type": "rest"
    },
    {
      "name": "finalStep",
      "script": "_record.firstName = trim(properCase(_record.firstName));\n_record.lastName = trim(properCase(_record.lastName));\nif (isNotNullOrEmpty(_record.birthDate)) {\n  try {\n    var d = new Date(Date.parse(_record.birthDate));\n    _record.birthDate = d.getFullYear() + '-' + ((d.getMonth() < 9 ? '0' : '') + (d.getMonth() + 1)) + '-' + ((d.getDate() < 10 ? '0' : '') + d.getDate());\n  } catch (e) {\n    _error = true;\n    _error_message = 'Birthdate validation failed';\n    _next_step = null;\n  }}",
      "type": "script"
    }
  ]
}