Outbound Webhook Transormations

Availability

Please contact support@solanolabs.com regarding availability of this feature.

Usage Scenarios

The most common use-case for transforming Solano’s outbound webhook payloads into an alternate form is to integrate with third party services without the need for an intermediate service. Transformer functions allow you to customize the outbound HTTP headers and payload to suit your specific use case.

Usage

By default, Solano CI outbound web hooks use a standard format that is sufficient for most use cases. Individual web hooks may be annotated with a payload transformation function implemented in JavaScript. It must be pure javascript (no libraries, etc.), must be named transform_payload, must take a single argument that is the default payload represented as a hash, and must return a hash with three keys, each of which is a string: “status”, “headers”, and “body”. If the status maps to any value other than the string “ok”, the default payload will be posted. If the status is “ok”, then the system will POST to the configured web hook URL with the HTTP headers in the “headers” hash (both keys and values must be strings and only strings) and the body will be the JSONified version of the value associated with “body”.

A simple example with headers and body suitable for New Relic Insights is found below:

function transform_payload(payload) {
  var headers = {"content-type": "application/json",
                 "X-Insert-Key": "newrelic-insights-insert-api-key"};

  var body = [{"eventType": payload["event"],
              "timestamp": Date.parse(payload["timestamp"]),
              "session_id": payload["session"]}];

  return {"status": "ok", "headers": headers, "body": body};
}