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

# DataWeave Body 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 Body Transformation</p></td></tr><tr><td><p><strong>Summary</strong></p></td><td><p>Transforms the body 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-body-transformation-release-notes">DataWeave Body 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 Body Transformation policy transforms request or response body content with a
DataWeave script. The script receives `attributes.headers` and `payload`. The gateway streams body
processing. If the script declares an output MIME type, such as `output application/json`, the
gateway uses it for the transformed response. Otherwise, the gateway keeps the original
`Content-Type`. In the request or response, the gateway processes the body in streaming mode and
updates `Content-Type` and `Content-Length` after transformation.

## 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-body-transformation-flex config: script: <string> // REQUIRED -
DataWeave script requestFlow: <string> // REQUIRED - "onRequest" or "onResponse"

<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 transforms the body. The script receives <code>attributes.headers</code> and <code>payload</code>. Declare the output MIME type in the script when needed, such as <code>output application/json</code>.</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></tbody></table>

### Resource Configuration Example

This example transforms the request payload to a new structure that includes the value from the
custom header `custom-client-header` and fields from the payload:

policies: - policyRef: name: dataweave-body-transformation-flex config: script: | { "id":
attributes.headers.'custom-client-header', "username": payload.name ++ payload.surname }

To transform the response body and set a custom output format such as XML, declare the output and
use `requestFlow: onResponse`:

policies: - policyRef: name: dataweave-body-transformation-flex config: script: | output
application/xml --- { "trace": payload.headers.'X-Amzn-Trace-Id', "custom-data": "custom-value" }
requestFlow: onResponse

### 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 Body Transformation</p></div></div></td></tr><tr><td><div><div><p>Script</p></div></div></td><td><div><div><p>The DataWeave script that transforms the body</p></div></div></td></tr><tr><td><div><div><p>Request flow</p></div></div></td><td><div><div><p>Whether the policy transforms the request or response body</p></div></div></td></tr></tbody></table>
