1. Home
  2. ...
  3. EIPs
  4. Set Body

Set Body

Learn how to use EIPs

The Set Body EIP defines or modifies the message body.

Parameters

Parameter
Description
Default value
Type
ExpressionDefines the value that will be set in the message body (body).ExpressionDefinition

Expression

The expression allows you to calculate or dynamically define values during message processing in the integration flow. It is a way to configure behaviors that can vary according to the context of the message in transit.

The expression is organized into two hierarchical levels that allow the structure to be more extensible and adaptable to different contexts:

  • First level: specifies the type of logic that will be applied (constant, jsonPath, xPath, etc.).

  • Second level: defines the actual value of the expression, that is, the data that will be assigned to the message body.

Common types of expressions

  • constant: defines a fixed value, useful for static messages. In the example, it always sets the message body as the static JSON {"status": "error"}.
  • jsonpath: extracts data from the message body when it is in JSON format. In the example, it extracts the value located at $.data.attributes from the JSON in the message body.
  • xpath: extracts information when the message body is in XML format. In the example, it selects the XML node corresponding to /response/body/item from the message body.
  • script: allows you to use scripting languages (JavaScript, Groovy, etc.) to dynamically create a body. In the example, it executes a JavaScript script to dynamically generate the message body.
  • binary: defines a binary body, useful for sending files or non-textual data. In the example, it sets the message body as Base64-encoded data.

Example

  • The code snippet sets the message body as dynamic XML containing an <id> element.
  • The expression parameter uses the simple language, which allows you to insert dynamic values and perform simple string manipulations.
  • The expression ${header.id} inserts the value of the header called "id" into the XML.
  • For example, if the "id" header has the value 123, the message body will be configured like this:

How happy are you with this page?

We use cookies to enhance your experience on our site. By continuing to browse, you agree to our use of cookies.Learn more