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
etagorcontent-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
dataarray. Add a results mapping that copies the field fromdata[*].<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
- 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.
- 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. - Select Settings for the field.
- In Field transformation type, select Handlebars expression.
- 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. - 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
- On the HTTP lookup, open Results mapping.
- Add a mapping.
- For the source, enter
data[*].followed by the output field name from the transformation, for exampledata[*].contentType. - 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.
- In the lookup's transformation, add the output field
eTagwith the handlebars expression{{{headers.etag}}}. - In the lookup's results mapping, map
data[*].eTagtoeTag, 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.
- In the lookup's transformation, add the output field
contentTypewith the handlebars expression{{{headers.content-type}}}. - In the lookup's results mapping, map
data[*].contentTypetoFileType. - To confirm the result, inspect the record payload in the next step, for example by reviewing a forced error's retry data.
FileTypeappears on the record with the value of the originalContent-Typeheader.
Common mistakes
If the header value doesn't reach later steps, see Response header values don't reach later steps.