---
schema_version: "1"
id: 841e6931afd41e3c6e9b318fe4cedfc0c5d593447aab229028f87bef3512d878
title: DataWeave Headers Transformation Policy
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/gateway/latest/policies-included-dataweave-headers-transformation.md
canonical_url: https://docs.mulesoft.com/gateway/latest/policies-included-dataweave-headers-transformation
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 35caa500adaa30be8ae302c5e0e0923d6221e178ff6309357037f7ed1cae7c2e
description: MuleSoft Documentation Site
release: "1.14"
latest: true
---
---
product: Omni Gateway
version: 1.14
is-latest-version: true
keywords: dataweave, headers transformation, transformation, api gateway, flex gateway, gateway, policy
---

# DataWeave Headers Transformation Policy

> For the full documentation index, see: https://docs.mulesoft.com/llms.txt

<table><colgroup><col> <col></colgroup><tbody><tr><td><p><strong>Policy name</strong></p></td><td><p>DataWeave Headers Transformation</p></td></tr><tr><td><p><strong>Summary</strong></p></td><td><p>Transforms headers of request or response traffic with a DataWeave script</p></td></tr><tr><td><p><strong>Category</strong></p></td><td><p>Transformation</p></td></tr><tr><td><p><strong>First Omni Gateway version available</strong></p></td><td><p>v1.12.0</p></td></tr><tr><td><p><strong>Release Notes</strong></p></td><td><p><a href="https://docs.mulesoft.com/release-notes/gateway/policies/dataweave-headers-transformation-release-notes">DataWeave Headers Transformation</a></p></td></tr><tr><td><p><strong>Returned Status Codes</strong></p></td><td><p><code>400</code> - The DataWeave script failed to execute or returned an invalid result</p></td></tr></tbody></table>

## Summary

The DataWeave Headers Transformation policy transforms request or response headers with a DataWeave
script. The script receives headers and the message body, and returns a map of header names to
values. In the request or response, the gateway removes existing headers and runs the script with
header bindings. The script output must be a map. Each entry becomes a header. For multi-value
headers, use a list of values.

## Configure Policy Parameters

### Omni Gateway Local Mode

When you apply the policy via declarative configuration files, Refer to the following policy
definition and table of parameters:

\- policyRef: name: dataweave-headers-transformation-flex config: script: <string> // REQUIRED -
DataWeave script requestFlow: <string> // REQUIRED - "onRequest" or "onResponse" requiresPayload:
<boolean> // OPTIONAL, default: false

<table><colgroup><col> <col> <col> <col></colgroup><thead><tr><th>Parameter</th><th>Required</th><th>Default Value</th><th>Description</th></tr></thead><tbody><tr><td><div><div><p><code>script</code></p></div></div></td><td><div><div><p>Required</p></div></div></td><td><div><div><p>—</p></div></div></td><td><div><div><p>A DataWeave script that returns a map of header names to values. The script receives <code>attributes.headers</code>. If <code>requiresPayload</code> is true, the script also receives the message body in the <code>payload</code> binding.</p></div></div></td></tr><tr><td><div><div><p><code>requestFlow</code></p></div></div></td><td><div><div><p>Required</p></div></div></td><td><div><div><p>—</p></div></div></td><td><div><div><p>Whether the policy transforms the request or response body. Supported values: <code>onRequest</code> or <code>onResponse</code>.</p></div></div></td></tr><tr><td><div><div><p><code>requiresPayload</code></p></div></div></td><td><div><div><p>Optional</p></div></div></td><td><div><div><p>false</p></div></div></td><td><div><div><p>If true, the script receives the message body in the <code>payload</code> binding. The gateway buffers the body for the transformation.</p></div></div></td></tr></tbody></table>

### Resource Configuration Example

This example adds custom headers with conditional logic. When the header `custom-client-header` is
set to `fixed_client`, the gateway replaces it with `custom-123123231231231231`. Otherwise, the
gateway uses the header value or `client-id-not-set`:

policies: - policyRef: name: dataweave-headers-transformation-flex config: script: | {
"custom\_client\_secret": "fixed\_secret\_123123231231231231", "custom\_client\_id": if
(attributes.headers.'custom-client-header'?) attributes.headers.'custom-client-header' match { case
literalMatch: "fixed\_client" -> "custom-123123231231231231" else ->
attributes.headers.'custom-client-header' } else "client-id-not-set" }

To append custom headers using payload data, for example to add the payload `id` to a custom header,
set `requiresPayload: true` and include `payload` in the script:

policies: - policyRef: name: dataweave-headers-transformation-flex config: script: |
attributes.headers ++ { "custom\_client\_id\_from\_payload": payload.id,
"custom\_client\_secret\_from\_payload": payload.secret } requiresPayload: true

### Managed Omni Gateway and Omni Gateway Connected Mode

When you apply the policy from the UI, the following parameters are displayed:

<table><colgroup><col> <col></colgroup><thead><tr><th>Parameter</th><th>Description</th></tr></thead><tbody><tr><td><div><div><p>Policy type</p></div></div></td><td><div><div><p>DataWeave Headers Transformation</p></div></div></td></tr><tr><td><div><div><p>Script</p></div></div></td><td><div><div><p>The DataWeave script that returns a map of headers</p></div></div></td></tr><tr><td><div><div><p>Request flow</p></div></div></td><td><div><div><p>The flow where the policy applies: request or response</p></div></div></td></tr><tr><td><div><div><p>Requires payload</p></div></div></td><td><div><div><p>Whether the script requires the message body</p></div></div></td></tr></tbody></table>
