Articles in this section

Use HTTP response headers in a transformation

HTTP response headers often carry values that later steps in a flow need, such as an eTag for a follow-up update request or a Content-Type that identifies a file's format. A Rules 2.0 transformation on an HTTP export or lookup can read these headers and write their values to a field on each record. This article shows how to capture a response header in a transformation and, for lookups, pass it to downstream steps with results mapping.

Prerequisites:

  • Your flow has an HTTP export or HTTP lookup that returns the header you need.
  • You know the header's name, for example etag or content-type. integrator.io stores response header names in lowercase, and paths are case-sensitive, so enter the name in lowercase even if the API documentation capitalizes it.

How it works

The transformation reads a header with a handlebars expression, such as {{{headers.content-type}}}, and writes the value to an output field you name. Every record the step returns gets that field.

  • On an HTTP lookup, the transformed records are returned in the lookup's data array. Add a results mapping that copies the field from data[*].<output field> to the field name downstream steps use. Results mapping applies only to lookups.
  • On an HTTP export, the output field is on each record when it leaves the export. No results mapping is needed.

Write a response header to each record

  1. Open the Define transformation editor on the HTTP export or lookup, and select Rules 2.0. For steps, see Add a transformation to a flow step.
  2. Add an output field, and enter the name you want the header value stored under, for example contentType. Note this name: you'll use it again in results mapping.
  3. Select Settings for the field.
  4. In Field transformation type, select Handlebars expression.
  5. In Handlebars expression, enter {{{headers.<header name>}}}, for example {{{headers.content-type}}}. Use three braces so handlebars doesn't HTML-escape characters such as = and & in the value.
  6. Preview the transformation, confirm the output field contains the header value, and then save. For the steps, see Preview and save.

Pass header values to later steps

  1. On the HTTP lookup, open Results mapping.
  2. Add a mapping.
  3. For the source, enter data[*]. followed by the output field name from the transformation, for example data[*].contentType.
  4. For the destination, enter the field name that downstream steps expect, for example FileType.

The name after data[*]. must exactly match the output field name in the transformation.

Example: Reuse a 3PL Central eTag

3PL Central returns an eTag header when you retrieve a receipt (receiver) by its receiverID, also called transactionID. You need the eTag to update an unconfirmed receiver with a PUT request.

  1. In the lookup's transformation, add the output field eTag with the handlebars expression {{{headers.etag}}}.
  2. In the lookup's results mapping, map data[*].eTag to eTag, or to the field name the PUT request expects.

The eTag is now on each record, ready for the import that sends the PUT request.

Example: Identify SAP Concur attachment file types

When you retrieve expense report images from SAP Concur, the Content-Type header identifies each file's type.

  1. In the lookup's transformation, add the output field contentType with the handlebars expression {{{headers.content-type}}}.
  2. In the lookup's results mapping, map data[*].contentType to FileType.
  3. To confirm the result, inspect the record payload in the next step, for example by reviewing a forced error's retry data. FileType appears on the record with the value of the original Content-Type header.

Common mistakes

If the header value doesn't reach later steps, see Response header values don't reach later steps.