# Integrations

Connect Docsheaf to Slack, GitHub and GitLab, your own services through webhooks and API tokens, and apps built on the Docsheaf API.

Integrations connect your docs to the tools your team already uses. Organization admins set them up in
**Organization settings**:

| Tab | What's there |
| --- | --- |
| **Integrations** | Slack channels, Git commit statuses, the app directory and installed apps |
| **Webhooks** | Endpoints of your own that hear what happens in your docs |
| **Apps** | Apps your organization builds on the Docsheaf API |

Personal **API tokens** are in **Account settings → API tokens**. None of these depends on your plan.

## Slack

Post your docs' activity to Slack channels:

| Event | On by default |
| --- | --- |
| Change requests opened | ✓ |
| Change requests merged | ✓ |
| Reviews | ✓ |
| Sites published | ✓ |
| Comments |  |

### Connect a channel

{% tabs %}
{% tab title="Add to Slack" %}
1. In **Organization settings → Integrations**, choose **Add to Slack**.
2. Pick the channel in Slack and allow access.
3. You're brought back to Docsheaf with the channel connected.
{% endtab %}

{% tab title="Incoming webhook URL" %}
1. In Slack, create an app with **Incoming Webhooks**, add a webhook to the channel and copy its URL
   (`https://hooks.slack.com/services/…`).
2. In **Organization settings → Integrations**, open **Or paste an incoming webhook URL** (or
   **Connect with an incoming webhook URL** if **Add to Slack** isn't offered), paste the URL, enter
   the channel's name and choose **Connect**.
{% endtab %}
{% endtabs %}

You can connect as many channels as you like, each with its own settings.

### Choose what a channel hears about

Each connected channel has:

- **Posts about**: the events above it posts.
- **Spaces**: **Every space open to the organization**, or **Only the spaces I choose**.

{% hint style="info" %}
Restricted spaces, and spaces in a restricted site or collection, stay out of a channel set to
**Every space open to the organization**. To post about one, choose it under **Only the spaces I
choose**.
{% endhint %}

The channel shows when it last received a message, or the last error. If Slack says the webhook was
removed, connect the channel again. **Disconnect** stops the posts.

## GitHub and GitLab commit statuses

When a space is connected with [Git Sync](git-sync) and a push can't go straight into the
docs, Docsheaf opens a change request for it. The pushed commit then shows the review on GitHub or
GitLab as a **Docsheaf** status:

| Status | When |
| --- | --- |
| Pending | The change request is waiting for review |
| Success | The change request was merged |
| Failure | A reviewer requested changes |

This works on its own once Git Sync is set up.

## Webhooks

Webhooks send what happens in your docs to a service of your own, such as CI, chat or a search index. An
organization can have up to 10.

### Add a webhook

1. In **Organization settings → Webhooks**, choose **Add webhook**.
2. Enter an `https` URL on the public internet, and pick the events.
3. Copy the **signing secret**: it's shown only once.

| Event | When |
| --- | --- |
| `change_request.created` | A change request is opened |
| `change_request.merged` | A change request is merged (published) |
| `change_request.archived` | A change request is archived |
| `review.submitted` | A review is submitted |
| `comment.created` | A comment is posted |
| `space.content_updated` | A space's published content changes |
| `site.published` | A site is published |
| `site.unpublished` | A site is unpublished |

**Send test** sends a `ping` event. **Pause** stops deliveries until you resume, and **Roll secret**
replaces the secret: the old one stops working at once.

### What Docsheaf sends

Each event is a `POST` with a JSON body:

```json
{
  "id": "evt_…",
  "type": "change_request.merged",
  "createdAt": "2026-12-01T09:30:00.000Z",
  "organizationId": "org_…",
  "data": {
    "space": { "id": "spc_…", "title": "Guides", "siteId": "site_…" },
    "changeRequest": { "id": "cr_…", "number": 42, "subject": "Update quickstart", "status": "merged", "url": "…" },
    "actor": { "id": "usr_…", "name": "Ada Lovelace" }
  }
}
```

The headers are `Docsheaf-Event` (the event type), `Docsheaf-Delivery` (the delivery id) and
`Docsheaf-Signature`.

### Verify the signature

`Docsheaf-Signature` looks like `t=1764581400,v1=5f2b…`. `v1` is the hex HMAC-SHA256 of
`<t>.<raw body>`, keyed with your signing secret. Check it before trusting a request:

```js
import { createHmac, timingSafeEqual } from 'node:crypto';

export function isFromDocsheaf(header, rawBody, secret) {
  const parts = Object.fromEntries(header.split(',').map((p) => p.split('=')));
  const expected = createHmac('sha256', secret).update(`${parts.t}.${rawBody}`).digest('hex');
  const fresh = Math.abs(Date.now() / 1000 - Number(parts.t)) < 300; // refuse old requests
  return fresh && expected.length === parts.v1?.length && timingSafeEqual(Buffer.from(expected), Buffer.from(parts.v1));
}
```

Sign the body exactly as it arrived, before any JSON parsing.

### Deliveries and retries

Answer with any `2xx` status within 10 seconds. Network errors, timeouts, `408`, `429` and `5xx`
answers are retried after 10 seconds and again after a minute, and deliveries still pending later are
sent once more. Other answers fail at once. Each webhook lists its **Recent deliveries** with their
status; **Send again** resends one. Delivery history is kept for 30 days.

Edits made directly on a space's content are grouped, so autosave sends one `space.content_updated`
instead of one per keystroke. A merge sends it at once.

## API tokens

Personal API tokens call the Docsheaf REST API as you, with your permissions. Create
them in **Account settings → API tokens** and send them as `Authorization: Bearer dsk_…`.

| Setting | Choices |
| --- | --- |
| **Access** | **Read and change**, or **Read only** |
| **Expires** | **Never**, **In 30 days**, **In 90 days** or **In a year** |
| **Works in** | **Every organization I belong to**, **Only this organization**, or **Only some spaces of this organization** |

A token limited to some spaces can read and change those spaces only, not sites, members or settings.
Copy a token when it's created: it isn't shown again. Each token shows when it was last used, and
**Revoke** stops it at once.

Tokens can't manage your account's sign-in methods, sessions or other tokens, and they're refused by
an organization that requires two-factor sign-in until you've turned it on.

## Apps

Apps are built on the Docsheaf API by your team or someone else, and installed per organization. An
installed app can read your docs, or read and change them, within the spaces you choose. It can also
add its own [blocks](blocks) to the editor's `/` menu.

### Install an app

1. Find the app in **Organization settings → Integrations → App directory**, or start from the app's own
   website.
2. Sign in if asked, and review the consent screen: what the app wants to do (**read**, or **read and
   write**).
3. Pick the organization and the spaces it can reach (all, or some), and allow it.

Only organization admins can install apps. Apps in the directory were reviewed by the Docsheaf team, and
go back to review when they change what they are or what they ask for.

### Manage installed apps

**Organization settings → Integrations → Installed apps** lists each app with who built it, the spaces
it reaches (you can change them), whose access it uses and when it was last used.

- An app acts with the access of the admin who installed it, capped at viewer for **read** and editor
  for **write**. Its actions appear in the audit log as "_admin_ via _app_".
- If that admin leaves the organization, the app stops working until another admin chooses
  **Reconnect with my access**. **Use my access instead** moves it to you at any time.
- **Uninstall** stops its tokens at once.

### Build an app

Organizations can build their own apps in **Organization settings → Apps**: apps use OAuth 2.0 (the
authorization code flow, with PKCE), can receive the webhook events above, and can declare blocks that
editors embed in pages. A public app can ask to be listed in the app directory.
