- policyRef:
name: dataweave-body-transformation-flex
config:
script: <string> // REQUIRED - DataWeave script
requestFlow: <string> // REQUIRED - "onRequest" or "onResponse"
DataWeave Body Transformation Policy
Policy name |
DataWeave Body Transformation |
Summary |
Transforms the body of request or response traffic with a DataWeave script |
Category |
Transformation |
First Flex Gateway version available |
v1.12.0 |
Returned Status Codes |
|
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
Flex Gateway Local Mode
When you apply the policy via declarative configuration files, Refer to the following policy definition and table of parameters:
| Parameter | Required | Default Value | Description |
|---|---|---|---|
|
Required |
— |
A DataWeave script that transforms the body. The script receives |
|
Required |
— |
Whether the policy transforms the request or response body. Supported values: |
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 Flex Gateway and Flex Gateway Connected Mode
When you apply the policy from the UI, the following parameters are displayed:
| Parameter | Description |
|---|---|
Policy type |
DataWeave Body Transformation |
Script |
The DataWeave script that transforms the body |
Request flow |
Whether the policy transforms the request or response body |



