> ## Documentation Index
> Fetch the complete documentation index at: https://docs.instance.sale/oss/llms.txt
> Use this file to discover all available pages before exploring further.

# Developer API & MCP

> Programmatic REST API and Model Context Protocol (MCP) server to query leads, manage tags, and trigger automations in Instance.

Instance provides two programmatic interfaces to access your CRM data, manage tags, update deal stages, and trigger Instagram automations:

1. **REST API**: Standard HTTP endpoints for webhooks, external tools (Make, Zapier, n8n), and backend services.
2. **MCP Server**: Native Model Context Protocol server connecting AI assistants (Claude Desktop, Cursor, Windsurf, Claude Code) over stdio.

Both interfaces authenticate using workspace API keys.

***

## 1. Authentication

Generate an API key in the dashboard:

1. Navigate to **Dashboard -> Settings -> API Keys**.
2. Click **Create New Key** and enter a descriptive label.
3. Copy the generated key (`inst_live_...`).

For REST API calls, pass the key in your HTTP request headers:

```http theme={null}
X-API-Key: inst_live_your_api_key_here
```

Or:

```http theme={null}
Authorization: Bearer inst_live_your_api_key_here
```

***

## 2. Response Envelopes

All REST API endpoints return a standard JSON envelope with either a `success` or `error` status.

### Success Response Envelope

```json theme={null}
{
  "status": "success",
  "data": {
    "id": "cuid_123",
    "ig_username": "sarah_coach",
    "name": "Sarah Jenkins",
    "email": "sarah@example.com",
    "phone": "+14155552671",
    "followers_count": 14200,
    "following_count": 890,
    "qualification_score": 88,
    "qualification_summary": "High budget coaching prospect with 10k+ followers",
    "is_qualified": true,
    "status": "Qualified",
    "tags": ["VIP", "High Budget"],
    "last_interaction": "2026-11-21T18:30:00.000Z",
    "created_at": "2026-11-20T12:00:00.000Z"
  }
}
```

### Error Response Envelope

```json theme={null}
{
  "status": "error",
  "message": "Contact not found in this workspace",
  "code": 404
}
```

***

## 3. REST Endpoints Reference

### Workspace and Pipelines

| Method | Endpoint | Description |
| :- | :- | :- |
| `GET` | `/api/v1/workspace/info` | Workspace metadata and connected Instagram account details |
| `GET` | `/api/v1/tags` | List all custom company tags in the workspace |
| `POST` | `/api/v1/tags` | Create a new company tag (`{"name": "VIP"}`) |
| `DELETE` | `/api/v1/tags/:name` | Delete a company tag from the workspace |
| `GET` | `/api/v1/pipelines` | List configured CRM deal statuses and pipeline stages |
| `GET` | `/api/v1/automations` | List published automation funnels available to trigger |

### Contacts and CRM Leads

| Method | Endpoint | Description |
| :- | :- | :- |
| `GET` | `/api/v1/contacts` | Paginated list of contacts with score, tag, and status filters |
| `GET` | `/api/v1/contacts/find` | Find a single contact by query (`?username=`, `?email=`, or `?phone=`) |
| `GET` | `/api/v1/contacts/:id` | Retrieve full contact profile by ID |
| `POST` | `/api/v1/contacts` | Create or sync a unified contact record |
| `PATCH` | `/api/v1/contacts/:id` | Update contact profile fields (`name`, `email`, `phone`) |
| `POST` | `/api/v1/contacts/:id/tags` | Add tags to a contact (`{"tags": ["VIP", "Hot Lead"]}`) |
| `DELETE` | `/api/v1/contacts/:id/tags/:name` | Remove a specific tag from a contact |
| `POST` | `/api/v1/contacts/:id/status` | Update contact pipeline deal stage (`{"status": "Qualified"}`) |

### Audience Lists and Segmentation

| Method | Endpoint | Description |
| :- | :- | :- |
| `GET` | `/api/v1/audience-lists` | List all audience lists in the workspace with contact counts |
| `POST` | `/api/v1/audience-lists` | Create an audience segmentation list (`name`, `description`, `color`) |
| `GET` | `/api/v1/audience-lists/:id/contacts` | Query contacts in a list (`channelFilter`, `search`, `page`, `limit`) |
| `POST` | `/api/v1/audience-lists/:id/assign` | Bulk assign contacts into an audience list (`{"contactIds": ["..."]}`) |
| `DELETE` | `/api/v1/audience-lists/:id` | Delete an audience list |

### Automation Funnel Execution

| Method | Endpoint | Description |
| :- | :- | :- |
| `POST` | `/api/v1/automations/:id/trigger` | Trigger an automated Instagram sales funnel for a contact |

Trigger request payload:

```json theme={null}
{
  "contactId": "cuid_contact_123",
  "variables": {
    "discountCode": "PROMO50",
    "offerUrl": "https://example.com/checkout"
  }
}
```

*(Alternatively, supply `"username": "target_handle"` instead of `contactId`)*.

***

## 4. Rate Limiting

To prevent accidental loops and protect self-hosted databases from overload, all public endpoints enforce request rate limits:

* **Limit**: 60 requests per rolling 60-second window per API key.
* **HTTP 429 Response**: When the limit is exceeded, the server returns status code `429 Too Many Requests` with a `Retry-After: 60` header:

```json theme={null}
{
  "status": "error",
  "statusCode": 429,
  "message": "Too Many Requests. Rate limit exceeded: 60 requests per minute.",
  "code": 429,
  "ttl": 60000
}
```

***

## 5. Code Examples

### cURL

```bash theme={null}
curl -X GET "http://localhost:4000/api/v1/contacts?status=Qualified&limit=25" \
  -H "X-API-Key: inst_live_your_key_here" \
  -H "Content-Type: application/json"
```

### Node.js (Fetch)

```javascript theme={null}
const response = await fetch("http://localhost:4000/api/v1/contacts?status=Qualified&limit=25", {
  method: "GET",
  headers: {
    "X-API-Key": "inst_live_your_key_here",
    "Content-Type": "application/json"
  }
});
const result = await response.json();
console.log(result.data);
```

### Python

```python theme={null}
import requests

url = "http://localhost:4000/api/v1/contacts"
headers = {
    "X-API-Key": "inst_live_your_key_here",
    "Content-Type": "application/json"
}
params = {
    "status": "Qualified",
    "limit": 25
}

response = requests.get(url, headers=headers, params=params)
print(response.json())
```

***

## 6. Model Context Protocol (MCP) Server

The Instance MCP server allows AI assistants (such as Claude Desktop, Cursor, Windsurf, and Claude Code) to interact with your CRM as native tools.

Add the `instance` server to your MCP configuration using `npx`:

```json theme={null}
{
  "mcpServers": {
    "instance": {
      "command": "npx",
      "args": ["-y", "instance-mcp"],
      "env": {
        "INSTANCE_API_URL": "http://localhost:4000",
        "INSTANCE_API_KEY": "inst_live_your_api_key_here"
      }
    }
  }
}
```

***

## 7. Available AI Tools Reference

Connected AI agents have access to 11 native CRM tools over stdio:

| Tool Name | Parameters | Description |
| :- | :- | :- |
| `instance_workspace_info` | None | Get connected Instagram accounts, handle, and workspace metadata |
| `instance_list_contacts` | `page`, `limit`, `search`, `status`, `tag`, `qualified`, `minScore`, `maxScore` | Search and filter CRM leads with qualification scores |
| `instance_find_contact` | `username`, `email`, or `phone` | Instant lookup for a specific contact by handle or contact info |
| `instance_create_contact` | `username`, `name`, `email`, `phone`, `status`, `tags` | Create or sync a new contact into the CRM |
| `instance_update_contact_status` | `contactId`, `status` | Move a deal through pipeline stages (e.g. Qualified, Closed Won) |
| `instance_add_tags` | `contactId`, `tags` | Apply tags to a lead (e.g. `VIP`, `Hot Lead`) |
| `instance_trigger_automation` | `automationId`, `contactId`, `username`, `variables` | Launch an Instagram automation funnel for a contact |
| `instance_get_audience_lists` | None | List all audience lists and segmentation groups |
| `instance_create_audience_list` | `name`, `description`, `color` | Create a new audience segmentation list |
| `instance_query_audience_contacts` | `listId`, `channelFilter`, `search`, `page`, `limit` | Filter contacts inside a specific audience list |
| `instance_assign_to_audience_list` | `listId`, `contactIds` | Assign contacts into a targeted audience list |


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.