# Integration routes: create, get

URL: /code/api/integration/records · Id: `page:code/api/integration/records`

> The Integration Verbs create, get as api.sb routes, with inputs, result, refusals and an example.

Reference for [Integration](/business/nouns/integration), one group of [Integration routes](/code/api/integration).

### Integration.create
Creates an Integration. [Verb page](/business/nouns/integration/create?interface=api).

```text
POST /{namespace}/integrations
```

Body, as JSON: the inputs. Emits `Integration.created`.

**Inputs**

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `acquired` | `string` | Yes | One of `owned`, `wrapped`, or `recruited`. |
| `terms` | `text` | No | The terms the Startup holds the right to use and resell it under. |
| `scope` | `string` | Yes | One of `studio`, `startup`, or `customer`. |
| `sync` | `string` | No | Which side leads a sync connector: `platform` or `provider`. |
| `mode` | `string` | Yes | How records move: `mirror` writes db.sb out to the outside tool; `import` turns edits there into Changes. db.sb is the record in both. |
| `venue` | `string` | No | The id of the ad, social or app-store venue the account is on, when it is on one. |
| `account` | `string` | No | The outside account’s own id, such as an ad account, a workspace or a repository. |
| `grants` | `string[]` | No | The outside permissions the account holder approved: the narrowest set its Verbs need. |
| `connectedBy` | [Party](/business/nouns/party) | No | Who approved the connection; a Human’s own account is used only under that Human’s Mandate. |
| `environment` | `string` | No | A `test` Integration reaches only the upstream’s test account, as a Stripe test account does. |
| `expiresAt` | `datetime` | No | When access lapses unless refreshed. |
| `refreshedAt` | `datetime` | No | When the platform last renewed the outside token. |
| `lastError` | `string` | No | The error slug of the last failed call or refresh, cleared by the next success. |
| `cursor` | `string` | No | Where the last sync run stopped, so the next run reads only what changed. |
| `system` | [System](/business/nouns/system) | No | An Integration connects an outside Source to one System, with credentials at Studio, Startup or Customer scope. |
| `source` | [Source](/business/nouns/source) | No | an Integration binds one wrapped Source to a System with credentials. |

**Returns**

| Output | Type | Required | Description |
| --- | --- | --- | --- |
| `integration` | [Integration](/business/nouns/integration) | Yes | The Integration. |

**Refuses when**

| Check | Error | Fix | Then call |
| --- | --- | --- | --- |
| The key is valid, but its scopes do not allow this operation. | [`forbidden`](/code/api/errors/forbidden) | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |

**Example**

```bash
curl -X POST https://api.sb/leaseline.app/integrations \
  -H "Authorization: Bearer $STARTUP_BUILDER_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"acquired":"owned","scope":"studio","mode":"mirror"}'
```

```json
{
  "api": "https://api.sb/leaseline.app",
  "integration": {
    "$id": "https://api.sb/leaseline.app/integrations/integration_alVwjQcmRy",
    "$type": "Integration",
    "acquired": "owned",
    "scope": "studio",
    "mode": "mirror",
    "state": "connecting"
  },
  "action": {
    "$id": "https://api.sb/leaseline.app/actions/act_br07HsG8MG",
    "operation": "Integration.create",
    "status": "done"
  },
  "links": {
    "self": "https://api.sb/leaseline.app/actions/act_br07HsG8MG"
  }
}
```

### Integration.get
Returns one Integration by id. [Verb page](/business/nouns/integration/get?interface=api).

```text
GET /{namespace}/integrations/{id}
```

Path: `id`. Query: the other inputs. Reads only: it emits no Event.

**Inputs**

| Input | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | `string` | Yes | The id of the Integration. |
| `at` | `string` | No | A time or Version name: the record as it stood then. Unset: as it stands now. |

**Returns**

| Output | Type | Required | Description |
| --- | --- | --- | --- |
| `integration` | [Integration](/business/nouns/integration) | Yes | The Integration. |

**Refuses when**

| Check | Error | Fix | Then call |
| --- | --- | --- | --- |
| The key is valid, but its scopes do not allow this operation. | [`forbidden`](/code/api/errors/forbidden) | Use a key whose scopes cover the operation, or ask an owner of the namespace to grant them. | None. |

**Example**

```bash
curl https://api.sb/leaseline.app/integrations/integration_alVwjQcmRy \
  -H "Authorization: Bearer $STARTUP_BUILDER_API_KEY"
```

```json
{
  "api": "https://api.sb/leaseline.app",
  "$type": "Integration",
  "$id": "https://api.sb/leaseline.app/integrations/integration_alVwjQcmRy",
  "integration": {
    "$id": "https://api.sb/leaseline.app/integrations/integration_alVwjQcmRy",
    "$type": "Integration",
    "acquired": "owned",
    "scope": "studio",
    "mode": "mirror",
    "state": "connecting"
  },
  "links": {
    "self": "https://api.sb/leaseline.app/integrations/integration_alVwjQcmRy",
    "up": "https://api.sb/leaseline.app/integrations"
  },
  "actions": {
    "call": "https://api.sb/leaseline.app/integrations/integration_alVwjQcmRy/call",
    "pause": "https://api.sb/leaseline.app/integrations/integration_alVwjQcmRy/pause",
    "reconnect": "https://api.sb/leaseline.app/integrations/integration_alVwjQcmRy/reconnect"
  }
}
```