> ## Documentation Index
> Fetch the complete documentation index at: https://docs.curator.interworks.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Dynamic Body Content in the API Relay

> Let an incoming request set or edit the body that the API Relay sends to your target API.

The API Relay normally sends a fixed request body to your target API. Dynamic Body Content lets a value
from the incoming request set or edit that body when the relay runs. You can send the value as
the whole body, or drop it into a placeholder inside a body you have already written.

## Before you start

1. Enable **Integration Automation**. Go to **Settings > Portal Settings > Features**, turn on
   "Integration Automation" in the Functionality section, then save and refresh.
2. Create an API Relay. Go to **Integrations > Automation > API Relay** and add a relay with your target
   API in the **URL** field.
3. In **Outgoing Request Content**, enter your default request in the **Body Content** field. This is the
   body the relay sends when no dynamic value arrives.

## Enable Dynamic Body Content

Open your relay and, in the Outgoing Request Content section, set the following fields.

* **Allow Dynamic Body Content.** Turn this on to reveal the rest of the dynamic fields.
* **Dynamic Body Content Variable.** Enter the name of the input field in the incoming request that
  carries the value you want to use. This name is required once the toggle is on. If the incoming request
  leaves this field out, the relay sends your static Body Content instead.
* **Perform Find/Replace of Body Content.** This switch chooses one of the two modes below.

### Mode 1: Replace the whole body

Leave **Perform Find/Replace of Body Content** turned off. The incoming value becomes the entire request
body. Use this when the caller already knows the exact body to send and you only want the relay to pass
it through.

### Mode 2: Drop the value into a placeholder

Turn **Perform Find/Replace of Body Content** on and set **Find/Replace Placeholder** to a marker you put
inside the Body Content field. When the relay runs, it swaps that marker for the incoming value and sends
the rest of the body as written. Use this when most of the body is fixed and only one part changes per
request.

For example, set Body Content to:

```json theme={null}
{ "report": "Quarterly Sales", "token": "__TOKEN__" }
```

Set the placeholder to `__TOKEN__` and the variable to `token`. A request that sends `token=abc123`
produces:

```json theme={null}
{ "report": "Quarterly Sales", "token": "abc123" }
```

## Adjust the value before it is sent

The **Dynamic Body Content Variable Advanced Processing** repeater edits the incoming value before the
relay uses it. Add one or more rules, and the relay applies them in order.

* **Remove Portion.** Enter the text to strip out of the value. For example, remove `Bearer ` so a value
  of `Bearer abc123` becomes `abc123`.
* **Find/Replace Portion.** Enter the text to find and the text to replace it with.

Each rule runs against the incoming value first. The placeholder swap in Mode 2 happens afterward, using
the adjusted value.

## Things to know

* **Browser calls must avoid a CORS preflight.** The relay endpoint does not return CORS headers, so a
  front-end `fetch` that triggers a preflight -- a custom header or a JSON content type -- is blocked by
  the browser. Call it as a "simple request" instead: GET or POST with form-encoded parameters and no
  custom headers (which is how Dynamic Body Content is meant to receive its value), or trigger it from
  your backend.
* **One variable per relay, but it can carry several values.** Dynamic Body Content maps a single
  incoming field into the body. That one value can still hold multiple pieces -- put a fragment of JSON
  in it and drop that fragment into the body with Mode 2. For example, set Body Content to
  `{"type":"widget",__EXTRA_KEY_VALUE_PAIRS__}` with the placeholder `__EXTRA_KEY_VALUE_PAIRS__` and the
  variable `dynamic-content`. A request sending `dynamic-content="token":"1234","name":"John Doe"`
  produces `{"type":"widget","token":"1234","name":"John Doe"}`. Depending on how the caller sends the
  request, a fragment like this may need to be URL-encoded on the way in and will arrive decoded, so
  account for encoding and decoding around any characters your fragment contains. To fill parts of the
  body from more than one incoming field, send a full body and use Mode 1, or set up separate relays.
* **A blank value clears the body.** If the incoming request includes the variable with an empty value,
  the relay treats that empty value as the body. To fall back to your static Body Content, leave the
  variable out of the request rather than sending it blank.
* **Body content applies to POST relays.** A GET relay sends its parameters on the URL and ignores the
  body.

## Related

* [Sending Data to Webhooks](/embedding_using_analytics/data_manager/sending_data_to_webhooks)
