# Call an API from a flow

Send data to another service, or fetch data from it, and use the response in the steps that follow.

Source: https://support.rework.com/article/call-an-api-from-a-flow

Not every system your team uses has its own step in the picker. The **HTTP request** step covers the rest: it calls any address on the internet, sends the data you choose, and hands the response to the steps below. It's how an automation talks to a billing system, a partner's API or an internal service.

## Step 1: Add the step and set the call

Click the **+** where the call belongs, search for **HTTP request**, then open it:

- **method**: **GET** to read, **POST**, **PUT**, **PATCH** or **DELETE** to change something.
  
- **url**: the full address, starting with `https://`. Tokens work here, so the address can carry an id from an earlier step.
  
- **headers**: click **Add row** for each header the other service expects, for example `Accept: application/json`.
  
- **Body mapping**: how the request body is built. See the table below.
  
- **Connection**: the saved credentials to sign the call with, if the service needs them.
  

Click **Save**. The **Needs config** notice clears once the required fields are filled in and saved.

![The HTTP request step with its method, URL, headers, body mapping and connection](https://storage.googleapis.com/reworkv3-public/success/260923/Fhhir5b2p7mVOUPXu7eUvKQDBcBWGNx7w6mdX2pYM8LubIVcGIiBLmnJ6OYzYXpS/img.Tk2C0lhcdZaxxNGxLx0r3VCz2x136PnQhZPS8hGoHQriC0UZSqNpblfxSivjBehw.png)

## Step 2: Choose how the body is built

| Body mapping | Sends |
| --- | --- |
| **Map automatically from upstream** | The output of the step above, as it is |
| **Map key by key** | Only the fields you list under **Body fields**, each with its own value or token |
| **Raw JSON body** | A JSON document you write yourself, tokens included |

![The body mapping options](https://storage.googleapis.com/reworkv3-public/success/260923/NIvqSsoKN9UAVBDBLg10uo7IUO80XByLzPfm0yVjI7BNdYflo9WJtdVtBd7n3s5M/img.NhLVOkmsY891cccQzgrJETIKWjwbQmrt9jUI9xoxwQhqrsJPFNx075LShI8ZLtQn.png)

A **GET** request sends no body, so the mapping only matters for the methods that change something.

## Step 3: Authenticate with a connection

Never paste a password or an API key into the URL or a header. 💡 Save it once as a connection and pick it in the **Connection** field, where it stays encrypted and reusable. See [Save a connection](https://support.rework.com/article/save-a-connection).

## Step 4: Test the call

Click **Test step**. The request is really made, so a **GET** only reads, while **POST**, **PUT** and **DELETE** really change the target. The result shows what came back.

## Step 5: Use the response further down

The step's output holds the response, and the steps below can read it with tokens:

| Field | Holds |
| --- | --- |
| `status` | The HTTP status code, for example `200` |
| `body` | The response body, with its own fields inside |
| `headers` | The response headers |

So an email below the call can say `{{<step name>.body.id}}`, and a filter can continue only when `status` is what you expect.

## What the app refuses

Two rules protect your workspace, and both show up as a failed step rather than a silent surprise:

- **Private and internal addresses are refused.** The URL has to be a public address, so an automation can't be pointed at something inside your network.
  
- **Redirects are not followed.** If the service answers with a redirect, the step fails and tells you to use the final address directly.
  

See [Fix a failed run](https://support.rework.com/article/fix-a-failed-run) for reading those errors.
