---
title: Set Header
description: Learn how to use EIPs
documentId: ipaas-eips-setheader
locale: en-US
---

The **Set Header** EIP defines or modifies the message header.

## Parameters

| Parameter | Description | Default value | Type |
|-----------|-----------|--------------|------|
| Name | Name of the message header that will be set. | | String |
| Expression | Defines the value that will be set in the header. It is mandatory and can use various supported expression languages, such as Simple, XPath, JSONPath. | | 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*, *simple*, *jsonpath*, etc.).

* **Second level**: defines the actual value of the expression, that is, the data that will be assigned to the header.

### Common types of expressions

* `constant`: defines a fixed value.
In the example, it will always return `"400"`.

```yaml
    - setHeader:
        name: my-header-name
        expression:
          constant:
            expression: "400"
```

* `simple`: allows you to use *placeholders* and simple logic to access message data.
In the example, it returns the value of the `operacao` header.

```yaml
- setHeader:
    name: my-header-name
    expression:
      simple:
        expression: "${header.operacao}"
```

* `jsonpath`: extracts information from messages with JSON body.
In the example, it returns the value of the `token` field inside the `data` object.

```yaml
- setHeader:
    name: my-header-name
    expression:
      jsonpath:
        expression: "$.data.token"
```

* `xpath`: extracts information from messages with XML body.
In the example, it returns the `id` attribute of the `customer` node inside `order`.

```yaml
- setHeader:
    name: my-header-name
    expression:
      xpath:
        expression: "/order/customer/@id"
```

* `groovy/javascript/python` (or another scripting language): uses custom scripts for complex operations.
In the example, the expression checks the length of the message body.
If the message body contains data, it sets the header as `Valid`; if it is empty, it sets it as `Invalid`.
It uses Groovy to perform this check conditionally.

```yaml
- setHeader:
    name: my-header-name
    expression:
      groovy:
        expression: "return request.body.length() > 0 ? 'Valid' : 'Invalid'"
```

## Example

* The following example defines the header name as `Content-Type`.
* The `expression` parameter is configured as `constant`, meaning it will have a fixed value.
This value will always be `application/json`, indicating that the request body will be in JSON format.

```yaml
- setHeader:
    id: setHeader-4103186938
    description: Set header urlencoded
    expression:
      constant:
        expression: application/json
    name: Content-Type
```
