---
schema_version: "1"
id: 3b36e31d96a6a543cb5dd3228d7175e55cc3138753be291466202c74945f2111
title: DataWeave Request Filter Policy
collection: mulesoft
version: current
locale: en-us
portal_url: https://docs.salesforce.com/mulesoft/current/en-us/gateway/latest/policies-included-dataweave-request-filter.md
canonical_url: https://docs.mulesoft.com/gateway/latest/policies-included-dataweave-request-filter
source_site: docs.mulesoft.com
content_type: documentation
content_hash: 728a9c12960be382dec532dc45053aa853d27d924854843d89ea5e45f2efec60
description: MuleSoft Documentation Site
release: "1.14"
latest: true
---
---
product: Omni Gateway
version: 1.14
is-latest-version: true
keywords: dataweave, request filter, transformation, api gateway, flex gateway, gateway, policy
---

# DataWeave Request Filter 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 Request Filter</p></td></tr><tr><td><p><strong>Summary</strong></p></td><td><p>Filters requests by using 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>1.12</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-request-filter-release-notes">DataWeave Request Filter</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 Request Filter policy evaluates a DataWeave script on the request, including headers
and the body, to allow or block the message. The script returns an object with a Boolean `success`
value. If `success` is `false`, the script can return a `response` object with `statusCode`, `body`,
and `headers`. The gateway sends that as the immediate HTTP response to the client and stops
processing. If `success` is `true`, the message continues.

Result format:

- Success: `{ "success": true }`

- Error: `{ "success": false, "response": { "body": "…​", "headers": {}, "statusCode": 400 } }`

## Configure Policy Parameters

### Omni Gateway Local Mode

\- policyRef: name: dataweave-request-filter-flex config: script: <string> // REQUIRED - DataWeave
script 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 an object with a boolean <code>success</code> field. If <code>success</code> is <code>false</code>, the optional <code>response</code> is: <code>{ "body": string, "headers": object, "statusCode": number }</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. If true and the body is missing, the gateway returns an error.</p></div></div></td></tr></tbody></table>

### Resource Configuration Example

policies: - policyRef: name: dataweave-request-filter-flex config: script: | %dw 2.0 output
application/java --- if (attributes.headers\["x-api-key"\] != null) { success: true } else {
success: false, response: { statusCode: 401, body: "Missing API key", headers: {} } }
requiresPayload: false

### 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 Request Filter</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 success or error result</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>
