# CRM sync

Check your HubSpot and Salesforce connections, read the sync log, and send a meeting to your CRMs again.

When HubSpot or Salesforce is connected on the dashboard's **Integrations** page, Insurge sends each presentation meeting's brief to it once the brief is ready. These endpoints let your systems watch that happen and run it again. Connecting a CRM is done in the dashboard, not through the API: see [HubSpot](/docs/integrations/hubspot) and [Salesforce](/docs/integrations/salesforce).

| Endpoint | Scope |
|---|---|
| `GET /api/v1/integrations/status` | `integrations:read` |
| `GET /api/v1/integrations/sync-log` | `integrations:read` |
| `POST /api/v1/integrations/sync/{meeting_id}` | `integrations:write` |

## Get connection status

`GET /api/v1/integrations/status` says which CRMs are connected. It never returns tokens or secrets.

**cURL**

```bash title="Get connection status"
curl 'https://api.insurgeai.com/api/v1/integrations/status' \
  -H "Authorization: Bearer $INSURGE_API_KEY"
```

**Node.js**

```js title="Get connection status"
const res = await fetch("https://api.insurgeai.com/api/v1/integrations/status", {
  headers: { Authorization: `Bearer ${process.env.INSURGE_API_KEY}` },
});
const { hubspot, salesforce } = await res.json();
if (!hubspot.connected && !salesforce.connected) console.warn("No CRM connected");
```

**Python**

```python title="Get connection status"
r = requests.get(
    "https://api.insurgeai.com/api/v1/integrations/status",
    headers={"Authorization": f"Bearer {os.environ['INSURGE_API_KEY']}"},
    timeout=30,
)
status = r.json()
print(status["hubspot"]["connected"], status["salesforce"]["connected"])
```

```json title="200 OK"
{
  "hubspot": {
    "configured": true,
    "connected": true,
    "portal_id": "24681357",
    "instance_url": null,
    "connected_at": 1795862400.0,
    "updated_at": 1796115600.0
  },
  "salesforce": {
    "configured": false,
    "app": {
      "registered": false,
      "source": null
    },
    "connected": false
  }
}
```

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `hubspot.configured` | `boolean` | No | Whether HubSpot can be connected at all. |
| `salesforce.configured` | `boolean` | No | Whether a Salesforce app is available to connect with: your own registered one, or one Insurge provides. |
| `salesforce.app` | `object` | No | registered (whether your own Salesforce app is saved), source (tenant for your own app, env for one Insurge provides, or null), and, when registered, client_id_hint (the first and last characters of your Consumer Key), login_url and updated_at. |
| `connected` | `boolean` | No | Whether that CRM is connected. When false, the connection fields below are left out. |
| `portal_id` | `string \| null` | No | The HubSpot account id, for HubSpot. |
| `instance_url` | `string \| null` | No | Your Salesforce org's address, for Salesforce. |
| `connected_at` | `number` | No | When it was connected, in Unix seconds. |
| `updated_at` | `number` | No | When the connection last changed, in Unix seconds. |

## Read the sync log

`GET /api/v1/integrations/sync-log` returns the newest sync attempts first, one entry per CRM per attempt.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `limit` | `number` | No | How many entries, 1 to 200. Default: `50`. |

**cURL**

```bash title="Read the sync log"
curl 'https://api.insurgeai.com/api/v1/integrations/sync-log?limit=20' \
  -H "Authorization: Bearer $INSURGE_API_KEY"
```

**Node.js**

```js title="Find failed syncs"
const res = await fetch("https://api.insurgeai.com/api/v1/integrations/sync-log?limit=200", {
  headers: { Authorization: `Bearer ${process.env.INSURGE_API_KEY}` },
});
const { log } = await res.json();
const failed = log.filter((e) => e.status === "error");
```

**Python**

```python title="Find failed syncs"
r = requests.get(
    "https://api.insurgeai.com/api/v1/integrations/sync-log",
    params={"limit": 200},
    headers={"Authorization": f"Bearer {os.environ['INSURGE_API_KEY']}"},
    timeout=30,
)
failed = [e for e in r.json()["log"] if e["status"] == "error"]
```

```json title="200 OK"
{
  "log": [
    {
      "id": "0d2f4a6c8e1b4d3f5a7c9e2b4d6f8a1c",
      "tenant_id": "acme",
      "meeting_id": "9b2e7c4d1a3f4b6e8d0c2a4e6f8b1d3c",
      "crm_type": "hubspot",
      "status": "success",
      "contact_id": "90817263",
      "engagement_id": "51627384",
      "error": null,
      "synced_at": 1796119658.5
    }
  ],
  "count": 1
}
```

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | No | The entry's id. |
| `meeting_id` | `string` | No | The meeting that was synced. |
| `crm_type` | `'hubspot' \| 'salesforce'` | No | Which CRM. |
| `status` | `'success' \| 'partial' \| 'error' \| 'skipped'` | No | partial: synced, with warnings in error. error: the sync failed part way or entirely; error says why. skipped: the CRM was not connected at the time. |
| `contact_id` | `string \| null` | No | The contact in your CRM. |
| `engagement_id` | `string \| null` | No | The record this sync wrote: a note in HubSpot, a task in Salesforce. |
| `error` | `string \| null` | No | The warnings or the reason, when there are any. |
| `synced_at` | `number` | No | When it ran, in Unix seconds. |
| `tenant_id` | `string` | No | Your workspace's id. |

## Sync a meeting again

`POST /api/v1/integrations/sync/{meeting_id}` sends one meeting to every connected CRM now and waits for the result. It needs the `integrations:write` scope, which a new key doesn't have.

**This writes to your CRM**

It finds or creates the contact and writes the meeting's brief to it. Running it again for the same meeting updates the note or task it wrote last time rather than adding another. It works for any meeting in your workspace, including ones Insurge doesn't sync on its own.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `meeting_id` | `string` | Yes | The meeting's id. |

**cURL**

```bash title="Sync a meeting again"
curl -X POST 'https://api.insurgeai.com/api/v1/integrations/sync/your_meeting_id' \
  -H "Authorization: Bearer $INSURGE_API_KEY"
```

**Node.js**

```js title="Sync a meeting again"
const res = await fetch(
  `https://api.insurgeai.com/api/v1/integrations/sync/${meetingId}`,
  { method: "POST", headers: { Authorization: `Bearer ${process.env.INSURGE_API_KEY}` } },
);
const { synced, errors } = await res.json();
if (errors.length) console.error(errors);
```

**Python**

```python title="Sync a meeting again"
r = requests.post(
    f"https://api.insurgeai.com/api/v1/integrations/sync/{meeting_id}",
    headers={"Authorization": f"Bearer {os.environ['INSURGE_API_KEY']}"},
    timeout=120,
)
r.raise_for_status()
result = r.json()
if result["errors"]:
    print(result["errors"])
```

```json title="200 OK"
{
  "synced": [
    "hubspot"
  ],
  "results": {
    "hubspot": {
      "success": true,
      "status": "success",
      "contact_id": "90817263",
      "created": false,
      "engagement_id": "51627384",
      "warnings": []
    }
  },
  "errors": []
}
```

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `synced` | `string[]` | No | The CRMs that were written to (success or partial). |
| `results` | `object` | No | One entry per connected CRM. On success: success, status (success or partial), contact_id, created (whether the contact was new), engagement_id and warnings. On failure: success false and error, plus skipped true when the CRM was disconnected while it ran. |
| `errors` | `string[]` | No | One line per CRM that failed, such as "salesforce: …". |

The answer is `200` even when a CRM failed: check `errors`. With no CRM connected, all three are empty. Each attempt is also written to the sync log.

| Status | When |
|---|---|
| `403` | The key doesn't have `integrations:write`. |
| `404` | `Meeting not found: <id>`. No such meeting in this workspace, or it is a test meeting. |
