Contact Us 1-800-596-4880

Set Payload (<set-payload/>)

logo cloud IDE Cloud IDE

logo desktop IDE Desktop IDE

Sets or updates the payload of the message.

The payload can be a literal string or a DataWeave expression. Use the set-payload component only for simple expressions or transformations. For complex scenarios, use the Transform Message Component.

Component XML

This component supports the following XML structure:

<set-payload
  value=""
  doc:name="Set payload"
  doc:id="vnjpqo" />

Set Payload (<set-payload/>) attributes are configurable through the UI and XML.

Attribute Name Attribute XML Description

Set payload (default)

doc:name

Editable name for the component to display in the canvas.

N/A

doc:id

Automatically generated identifier for the component.

Value

value

A literal string or DataWeave expression that defines how to set the payload, for example, "some string" or #[now()]. This attribute is required.

N/A

resource

A .dwl file containing a DataWeave transformation script. These values are resolved statically (not dynamically). For example, using <ee:set-payload resource="myscript-$site.dwl"/> generates an error. For more information, see dwl File.

Encoding

encoding

Encoding of the payload that this component outputs.

Mime type

mimeType

MIME type of the payload that this component outputs. For more information, see Using Reader and Writer Properties.

Parameters

N/A

Appends a key-value pair for a reader property to the value of the outputMimeType attribute. Multiple key-value pairs are allowed. Reader properties are specific to the MIME type. For example, see the JSON reader properties for application/json. To find other reader properties, navigate to a supported format from the DataWeave format documentation, and see Using Reader and Writer Properties.

The mimeType and encoding attributes do not affect a DataWeave expression used as a value. These attributes affect the output Mule Message only. If a transformation is required, the DataWeave expression must contain an explicit output directive.

Examples

The following examples show how to set the payload using a static value or a DataWeave expression.

Example: Set the Payload with a Static Value

The following example sets a payload with static values:

<set-payload value="{ 'name' : 'Ana', 'office' : 'BA' }" mimeType="application/json" encoding="UTF-8"/>

Example: Set the Payload Using a DataWeave Expression

The following example sets the message payload to "Hello, World" appending today’s date using a DataWeave expression: #['Hello World!' ++ ' Today is ' ++ now()]

<set-payload value="#['Hello World!' ++ ' Today is ' ++ now()]"/>