# Continue links API

Make a private link that lets a visitor carry on a session they left part way, and end links before they expire.

A continue link opens an agent's session for one visitor, already knowing who they are and how far they got last time. Your server makes it with `POST /api/v1/resume-links` and ends it with `DELETE /api/v1/resume-links`. Both need a key with the `sessions:write` scope (**Create continue links** in the dashboard), which a new key doesn't have.

How the visitor lands, what the agent does and how to keep links safe are in [Continue links](/docs/developers/continue-links).

**Insurge turns this on for your workspace**

The link opens your agent's page, and that page has to be set up to read it. Until Insurge has set it up for your workspace, a continue link opens the agent's usual start, as a new session. Ask your Insurge contact before you build on continue links.

## Make a continue link

`POST /api/v1/resume-links` makes a new link each time you call it. Call it from your server, when the visitor is back and you know who they are.

**This opens a visitor's session**

Anyone who holds the link can carry on as that visitor, until it expires or you end it. Give it only to that visitor.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `meeting_id` | `string` | No | A meeting of the visitor, from meeting.ended or the API. If they have since carried on from it through a continue link, the link carries on from that newest visit, even if you give the older one. |
| `email` | `string` | No | Instead of meeting_id: the visitor's email. Uses their newest meeting with an agent that can be continued. |
| `agent_id` | `string` | No | With email: which agent's session to continue. With meeting_id: a check that the meeting was run by this agent. |
| `ttl_hours` | `number` | No | How long the link works, in hours, from 1 to 720 (30 days). Default: `168 (7 days)`. |

Give `meeting_id` or `email`. When you give both, `meeting_id` is used.

**cURL**

```bash title="Make a continue link"
curl -X POST 'https://api.insurgeai.com/api/v1/resume-links' \
  -H "Authorization: Bearer $INSURGE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"meeting_id": "your_meeting_id", "ttl_hours": 72}'
```

**Node.js**

```js title="Make a continue link"
async function makeContinueLink(meetingId) {
  const res = await fetch("https://api.insurgeai.com/api/v1/resume-links", {
    method: "POST",
    headers: {
      Authorization: `Bearer ${process.env.INSURGE_API_KEY}`,
      "Content-Type": "application/json",
    },
    body: JSON.stringify({ meeting_id: meetingId, ttl_hours: 72 }),
  });
  const body = await res.json();
  if (!res.ok) {
    // detail.code tells you why, for example "already_completed".
    const code = body.detail?.code ?? res.status;
    throw new Error(`No continue link: ${code}`);
  }
  return body; // { url, token, expires_at, meeting_id, lead_id, agent_id, progress }
}
```

**Python**

```python title="Make a continue link"
import os

import requests


def make_continue_link(meeting_id: str) -> dict:
    r = requests.post(
        "https://api.insurgeai.com/api/v1/resume-links",
        json={"meeting_id": meeting_id, "ttl_hours": 72},
        headers={"Authorization": f"Bearer {os.environ['INSURGE_API_KEY']}"},
        timeout=30,
    )
    if not r.ok:
        detail = r.json().get("detail")
        code = detail.get("code") if isinstance(detail, dict) else r.status_code
        raise RuntimeError(f"No continue link: {code}")
    return r.json()
```

```json title="200 OK"
{
  "url": "https://acme.insurgeai.com/s/Ab3dE6gH#resume=BwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSY",
  "token": "BwgJCgsMDQ4PEBESExQVFhcYGRobHB0eHyAhIiMkJSY",
  "expires_at": "2026-12-08T11:03:10Z",
  "meeting_id": "4e1d8a2c7b5f4c3a9e6d1b8f2a7c5e30",
  "lead_id": "c41e7b2a9d3f4e6a8b1c5d7f9e2a4b6c",
  "agent_id": "product-tour",
  "progress": {
    "sections_done": [
      "Workspace",
      "Pipelines"
    ],
    "sections_total": 4,
    "next_section": "Alerts"
  }
}
```

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `url` | `string` | No | The link to give the visitor: the agent's share link, with the token after #resume=. |
| `token` | `string` | No | The token on its own, for when you build the address yourself. Shown only in this answer: Insurge keeps only a hash of it. |
| `expires_at` | `string` | No | When the link stops working, in ISO 8601 UTC. |
| `meeting_id` | `string` | No | The visitor's newest visit in this chain of continued sessions: the one the next session carries on from. |
| `lead_id` | `string` | No | The visitor. Use it to end all their links. |
| `agent_id` | `string` | No | The agent the link opens. |
| `progress` | `object \| null` | No | How far the visitor got, across every visit: sections_done, sections_total and next_section. |

### When a link can't be made

These answers have a `detail` object with a `code` to branch on and a `message`:

```json title="409 Conflict"
{
  "detail": {
    "code": "already_completed",
    "message": "The visitor finished this demo."
  }
}
```

| Status | `code` | When |
|---|---|---|
| `404` | `no_meeting` | No meeting with that id; no visitor with that email; the visitor has no meeting with an agent that can be continued; or the meeting wasn't run by the `agent_id` you gave. |
| `409` | `already_completed` | The visitor's newest visit reached the end. There is nothing to continue. |
| `422` | `test_meeting` | The meeting was opened from a test link or a Preview. |
| `422` | `anonymous_lead` | The visitor never gave their email. |
| `422` | `not_resumable` | The agent isn't a Tour guide, Help desk or Training agent, or it is paused. |
| `422` | `no_link` | The agent has no live [share link](/docs/share/share-links) to open. Make one and try again. |

A body without `meeting_id` or `email`, or a `ttl_hours` outside 1 to 720, answers `422` with the [validation shape](/docs/developers/api/errors#error-bodies) instead.

## End continue links

`DELETE /api/v1/resume-links` ends links before they expire: one link by its token, or every link of one visitor. An ended link stops working at once.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `token` | `string` | No | The token of one link: the token field, or the part of the url after #resume=. |
| `lead_id` | `string` | No | The visitor: ends every one of their links. Ignored when token is given. |

**cURL**

```bash title="End every link of one visitor"
curl -X DELETE 'https://api.insurgeai.com/api/v1/resume-links' \
  -H "Authorization: Bearer $INSURGE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"lead_id": "your_lead_id"}'
```

**Node.js**

```js title="End every link of one visitor"
const res = await fetch("https://api.insurgeai.com/api/v1/resume-links", {
  method: "DELETE",
  headers: {
    Authorization: `Bearer ${process.env.INSURGE_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({ lead_id: leadId }),
});
const { revoked } = await res.json();
```

**Python**

```python title="End every link of one visitor"
r = requests.delete(
    "https://api.insurgeai.com/api/v1/resume-links",
    json={"lead_id": lead_id},
    headers={"Authorization": f"Bearer {os.environ['INSURGE_API_KEY']}"},
    timeout=30,
)
r.raise_for_status()
print(r.json()["revoked"])
```

```json title="200 OK"
{
  "revoked": 1
}
```

`revoked` is how many links were ended. Links that had already expired count; links ended before don't. `0` is not an error: there was nothing left to end, so it is safe to call again.

| Status | When |
|---|---|
| `403` | The key doesn't have `sessions:write`. |
| `422` | The body has neither `token` nor `lead_id`. |
