# Connections

> Keep an API's base URL, token and signing in one place, for the HTTP data sources and playbook steps that call it.

A connection holds what calling an API takes: its base URL, the headers that carry its token, and how requests are signed. [HTTP data sources](https://pulso.run/docs/concepts/data-sources.md#http-api) always call through one, and a playbook's [HTTP request steps](https://pulso.run/docs/concepts/playbooks.md#http-requests) can. Several of them can share one connection, so a token is kept once and changed in one place.

## Add a connection

Only admins add, change and delete connections, under **Settings → Integrations → Connections**:

1. Click **New connection**, pick **Custom** when it asks what the connection calls, and give it a **Name**.
2. Enter the **Base URL**, such as `https://api.example.com/v1`. Everything that calls through the connection adds a path to it and can't leave it. A query in it, such as `?api_key=…`, goes after the path and with the path's own query. Private and local addresses are refused.
3. Add **Headers**, one row each with its name and value, as `Authorization` and `Bearer sk_live_…`. **Add header** adds a row and **×** removes one.
4. If the API wants each request signed, add a [signing script](https://pulso.run/docs/concepts/connections.md#sign-requests) and its **Signing secret**.
5. Under **What it can send**, keep it read only or narrow it to the requests it needs, as [below](https://pulso.run/docs/concepts/connections.md#what-it-can-send).

For an integration's API, such as [Fly.io](https://pulso.run/integrations/fly/)'s, pick it instead of **Custom**: the form asks only for a name and what that integration needs, such as an app name and a token, and fills in the base URL, the headers and the signing for you. The connection then belongs to that integration, shown with its icon in the list and on its page, and adding the integration again offers it, so a new source can call through it without asking for its settings again. A connection that an integration's **Add to Pulso** makes belongs to it too; an integration it belongs to never changes. It also keeps the settings that aren't secret, such as Fly.io's app name, and its page lists them: the integration's monitors take their titles and playbook commands from them. Its **Settings** tab asks for the same settings, never for the base URL, headers or signing, which they make up; a secret one left empty keeps its value.

**Check connection**, under the settings, tries them before you save: Pulso sends the integration's API a request that only working credentials get an answer to, such as GitHub's `GET /rate_limit`, and says whether it worked and, if not, what the API said. Nothing is saved until you click **Save**. What the connection lets playbooks send doesn't limit this request, which only reads.

Header values and the signing secret are encrypted, and no page shows them again, not even to admins: leave a value empty to keep it, or type a new one to change it. A header renamed with its value left empty keeps its value. Every member sees the connection's name, its base URL without its query string, and its headers' names. If a response or an error holds a secret header's value, it shows as `[connection header Authorization]`, the signing secret as `[connection signing secret]`, and a value from the base URL's query as `[connection query api_key]`. A header is secret while its **Secret** box is ticked. A new row's box starts ticked, unless its name is a version, Accept, Content-Type or User-Agent header. A header that isn't secret, such as `X-Api-Version`, keeps its value as the API sends it, so monitors can filter on it.

Keep tokens in a connection, never in [account variables](https://pulso.run/docs/concepts/variables-and-address-book.md), which anyone in the account can read.

The connection's page lists what calls through it: its data sources, and the playbooks and playbook templates with a step that does. A change to its headers or its secret applies to all of them at once. A connection that a data source uses can't be deleted until the source calls through another; a playbook step whose connection was deleted fails, saying so.

## What it can send

Anyone who edits a monitor or a playbook can send requests through a connection with its credentials and read the answer. **What it can send** limits them, for monitors and playbook steps alike:

- **Read only**, the default: any `GET` request, and nothing else.
- **Only the requests listed**: each a method and a path after the base URL, as `GET /orders/*` or `POST /orders/{order}/refunds`, added one after another under **Custom requests**. A name is optional, and a named request shows under the HTTP step's **Operation**, as an integration's do. A saved request reads as text: changing or removing it says which monitors and playbooks send it, and nothing changes until you save. `*` or `{name}` stands for one part of the path, and `**` at the end for any number of them, so `GET /orders/**` allows `/orders` and everything under it. The query isn't checked.
- **Any request**, with any method and body.

An integration's connection lists the requests its API offers under **Built-in requests**, such as PlanetScale's backups, with a box for each; those that only read start ticked. The step's editor offers them under **Operation**, which fills in the method and the path; each `{name}` in it is then replaced by a value, as `{{signal.database}}`.

Pulso checks each request as it goes out, and refuses one the connection doesn't allow, saying why. The editors check it as you save: a monitor's path, and a playbook step's method and path, where a `{{…}}` value can stand for any part of the path. Narrowing it while a monitor or playbook sends something it would refuse says which, rather than leaving them to fail.

This is a second fence, not the first: give the connection a token that can do no more than it needs, such as a read-only key or one limited to a few resources. An integration's connection form says which one to create, and with which permissions.

## Sign requests

For an API that wants an HMAC of each request, a JavaScript script says what to sign and where the signature goes. Pulso signs with the **Signing secret**, which the script never sees. The script gets the request as `input.method`, `input.url`, `input.path`, `input.query` (the query string, without `?`), `input.headers` (lower-cased names) and `input.body`, plus `input.timestamp` (seconds), `input.timestamp_ms`, `input.nonce` and `input.body_sha256` (the body's SHA-256, in hex), and returns:

- `message`, optional: the text to sign.
- `headers`, optional: headers to add, where `{{signature}}` stands for the signature.
- `query`, optional: values to add to the query string, in that order, where `{{signature}}` stands for it too.
- `algorithm`, optional: `hmac-sha256` (the default), `hmac-sha1` or `hmac-sha512`.
- `encoding`, optional: the signature's, `hex` (the default) or `base64`.
- `key_encoding`, optional: `text` (the default), or `hex` or `base64` for a secret given encoded, whose bytes are the key.
- `key_prefix` and `derive`, optional: for an API that signs with a key derived from the secret through several HMACs. The key starts as `key_prefix` followed by the secret, and each text in `derive`, in turn, replaces it with the HMAC of the key and that text.

Or `{ error: "…" }` to fail the check with that reason. The script can call `sha256(text)` for a text's SHA-256 in hex. What the script returns is used as is, so an API key goes among the connection's **Headers**.

Pulso runs the script before each request, signs its `message` with the signing secret, and writes the signature wherever `{{signature}}` appears in the `headers` and `query` the script returned. Many APIs sign the timestamp, the method, the path and the body with HMAC-SHA256, and read the signature and the timestamp from two headers; **Insert an example** in the editor starts from this script:

```js
return {
  message: `${input.timestamp}${input.method}${input.path}${input.body}`,
  headers: { "X-Signature": "{{signature}}", "X-Timestamp": String(input.timestamp) }
};
```

With the base URL `https://api.example.com/v1`, a `POST` to `/orders` at `1767225600` with the body `{"id":1}` signs `1767225600POST/v1/orders{"id":1}`, as `input.path` is the URL's whole path, and sends `X-Signature` with the signature in hex and `X-Timestamp: 1767225600`.

Binance signs the query string, with a timestamp in milliseconds in it, and takes the API key in a header: `X-MBX-APIKEY: <your key>` among the headers, and this script:

```js
const query = [input.query, `timestamp=${input.timestamp_ms}`].filter(Boolean).join("&");
return { message: query, query: { timestamp: input.timestamp_ms, signature: "{{signature}}" } };
```

Coinbase Exchange signs the timestamp, the method, the path and the body with a secret given in base64, and wants the signature in base64:

```js
const path = input.query ? `${input.path}?${input.query}` : input.path;
return {
  message: `${input.timestamp}${input.method}${path}${input.body}`,
  key_encoding: "base64",
  encoding: "base64",
  headers: { "CB-ACCESS-SIGN": "{{signature}}", "CB-ACCESS-TIMESTAMP": String(input.timestamp) }
};
```

AWS Signature Version 4 hashes a canonical form of the request into the text it signs, and derives the key from the secret, the date, the region and the service. With the access key ID in the script and the secret access key as the **Signing secret**, for S3 in `eu-west-1`:

```js
const amzDate = new Date(input.timestamp * 1000).toISOString().replace(/[-:]/g, "").replace(/\.\d+/, "");
const date = amzDate.slice(0, 8), scope = `${date}/eu-west-1/s3/aws4_request`;
const headers = { host: input.url.split("/")[2], "x-amz-content-sha256": input.body_sha256, "x-amz-date": amzDate };
const names = Object.keys(headers).sort();
const canonical = [input.method, input.path, input.query, ...names.map((name) => `${name}:${headers[name]}`), "",
                   names.join(";"), input.body_sha256].join("\n");
return {
  message: ["AWS4-HMAC-SHA256", amzDate, scope, sha256(canonical)].join("\n"),
  key_prefix: "AWS4",
  derive: [date, "eu-west-1", "s3", "aws4_request"],
  headers: {
    "X-Amz-Date": amzDate,
    "X-Amz-Content-Sha256": input.body_sha256,
    Authorization: `AWS4-HMAC-SHA256 Credential=AKIA…/${scope}, SignedHeaders=${names.join(";")}, Signature={{signature}}`
  }
};
```

AWS signs the query with its values sorted by name, so the paths called through the connection give them in that order.

## Through the API

The [API](https://pulso.run/docs/api/overview.md) and the [MCP server](https://pulso.run/docs/api/mcp.md) list and read connections with `connections:read`, and create and change them with `connections:write` as an admin:

```bash
curl -X POST https://api.pulso.run/v1/connections \
  -H "Authorization: Bearer ak_..." -H "Content-Type: application/json" \
  -d '{"name": "Shop API", "base_url": "https://shop.example.com/v1", "access": "listed",
       "allowed_requests": ["GET /orders/*", {"name": "Refund an order", "method": "POST", "path": "/orders/{order}/refunds"}],
       "headers": [{"name": "Authorization", "value": "Bearer ..."}]}'
```

`headers` replaces the headers; one the connection already has keeps its value when sent without one. `secret` masks a header in what playbooks read back, and defaults as in the form. Header values and the signing secret are never returned; `signing_script` set to `null` stops signing. `access` and `allowed_requests` are as in [What it can send](https://pulso.run/docs/concepts/connections.md#what-it-can-send). For an integration's API, send `integration` and its `settings` instead of a base URL and headers, when creating it and when changing it. `GET /v1/connections/:id` also says what calls through it, and `POST /v1/connections/:id/check` tries an integration's connection as it's saved, as **Check connection** does.
