# HTTP request

> Call your own systems or any web API from a flow, sign in with a secret from the vault, and keep fields of the reply in variables.

Calls a web address (your booking system, your CRM, any API) and keeps fields from the reply in variables. The run waits for the answer, then follows **Success** or **Error**.



## The request

| Setting | What it does |
| --- | --- |
| Method | GET, POST, PUT, PATCH or DELETE. |
| Address | The address, with variables if you need them: `https://api.example.com/orders/{{order_id}}`. Use `https://`: plain `http://` works but gets a warning. |
| Headers | Extra headers, with variables in their values. Headers the platform sets itself (`Host`, `Content-Length`, `Connection`…) are refused. |
| Body | For anything but GET. Usually JSON: `{"phone": "{{contact.address}}", "people": {{party_size}}}`. |
| Sign in with | A secret from the workspace's vault (below). |
| Timeout (seconds) | How long to wait for the reply: 0.5 to 30 seconds (10 by default). |

Variables are inserted safely:

- in the **address**, a value is encoded so it stays one part of the address: an answer like `1/../admin` can't change which page you call. Only a variable at the very start (`{{api_base}}/orders`) is inserted as a whole base address.
- in a **JSON body**, a value inside quotes is escaped as text, and a value outside quotes becomes the matching JSON value (a number, `true`, `null`…), so nothing a contact types can break the JSON.

When the body looks like JSON and you set no `Content-Type`, `application/json` is sent.

## Signing in: the vault

Never type passwords or API keys into the step: everyone who can open the flow would see them, and the checks warn you. Store them in the workspace's **vault** instead, and pick them under **Sign in with**. The value never appears in the flow, in test mode or in logs.

Each secret has a **kind** and the **hosts** it may be sent to:

| Kind | Sent as |
| --- | --- |
| `bearer` | `Authorization: Bearer <value>` |
| `basic` | `Authorization: Basic …`, from a `user:password` value. |
| `header` | A header of your choice (`X-Api-Key: <value>`). |
| `query` | A parameter added to the address (`?key=<value>`). |

A secret only goes to the hosts it was saved for (`api.example.com`, or `*.example.com` for its subdomains), wherever the address comes from; a request anywhere else fails with "Secret not allowed for this host". Credentials are also dropped if your API redirects elsewhere.

Admins add, replace and remove secrets with the [REST API](https://nomongeta.zenhalab.com/www/nomongeta/en/docs/developers/rest-api) (`PUT` and `DELETE` on `/secrets/<name>`); builders see the names to pick from.

## Keeping parts of the reply

Under **Keep from the response**, map fields of the JSON reply to variables with a **Field (JSON path)**:

| Path | Reads |
| --- | --- |
| `$.id` | The `id` field. |
| `$.booking.table` | `table` inside `booking`. |
| `$.items[0].name` | `name` of the first item. |
| `$` | The whole reply (into a data variable, or as text). |

A field that isn't there leaves its variable unchanged (test mode shows a warning). A reply that isn't JSON can still be kept whole with `$`.

## Outputs

| Output | When |
| --- | --- |
| Success | The reply came back with a 2xx status. The mapped fields are saved. |
| Error | Anything else: a 4xx or 5xx status, a timeout, a network error, a blocked address, a reply too large, or the limits below. |

Connect **Error**: an API is never up 100 % of the time. A message and a [Hand to a person](https://nomongeta.zenhalab.com/www/nomongeta/en/docs/flow-builder/handoff) is a good default.

## Limits and safety

- Requests to private and internal addresses (your office network, `localhost`, cloud metadata services) are refused, also when the address comes from a variable.
- By default, one incoming message can lead to at most 5 requests, 20 seconds of requests in total, and replies of up to 512 KB.
- Test mode makes **real** requests: aim it at a test environment when a call would book, charge or change something. See [Testing and debugging](https://nomongeta.zenhalab.com/www/nomongeta/en/docs/flow-builder/testing).
