# API: Pipelines

| Method | Path | What it does | Scope |
|---|---|---|---|
| GET | `/v1/pipelines` | Pipelines with their stages (include_archived=true for archived ones too) | `deals:read` |
| POST | `/v1/pipelines` | Create a pipeline (owner). Stage types are fixed once set. | `settings:write` |
| DELETE | `/v1/pipelines/:id` | Archive a pipeline (owner). It must not be the default or hold open deals. | `settings:write` |
| PATCH | `/v1/pipelines/:id` | Rename, make default, or edit stages (owner). Stage types can't change; add a new stage instead. | `settings:write` |
| POST | `/v1/pipelines/:id/restore` | Restore an archived pipeline (owner) | `settings:write` |

## Examples

### GET /v1/pipelines

Pipelines with their stages (include_archived=true for archived ones too)

```bash
curl -s "https://api.closefinch.com/v1/pipelines" \
  -H "Authorization: Bearer $RA_API_KEY"
```

```js
const res = await fetch(`https://api.closefinch.com/v1/pipelines`, {
  method: "GET",
  headers: { authorization: `Bearer ${process.env.RA_API_KEY}` },
});
const data = await res.json();
```

### POST /v1/pipelines

Create a pipeline (owner). Stage types are fixed once set.

```bash
curl -s -X POST "https://api.closefinch.com/v1/pipelines" \
  -H "Authorization: Bearer $RA_API_KEY" \
  -H "content-type: application/json" \
  -d '{}'
```

```js
const res = await fetch(`https://api.closefinch.com/v1/pipelines`, {
  method: "POST",
  headers: { authorization: `Bearer ${process.env.RA_API_KEY}`, "content-type": "application/json" },
  body: JSON.stringify({}), // fields: see the OpenAPI schema
});
const data = await res.json();
```

### DELETE /v1/pipelines/$ID

Archive a pipeline (owner). It must not be the default or hold open deals.

```bash
curl -s -X DELETE "https://api.closefinch.com/v1/pipelines/$ID" \
  -H "Authorization: Bearer $RA_API_KEY"
```

```js
const res = await fetch(`https://api.closefinch.com/v1/pipelines/${id}`, {
  method: "DELETE",
  headers: { authorization: `Bearer ${process.env.RA_API_KEY}` },
});
const data = await res.json();
```

### PATCH /v1/pipelines/$ID

Rename, make default, or edit stages (owner). Stage types can't change; add a new stage instead.

```bash
curl -s -X PATCH "https://api.closefinch.com/v1/pipelines/$ID" \
  -H "Authorization: Bearer $RA_API_KEY" \
  -H "content-type: application/json" \
  -d '{}'
```

```js
const res = await fetch(`https://api.closefinch.com/v1/pipelines/${id}`, {
  method: "PATCH",
  headers: { authorization: `Bearer ${process.env.RA_API_KEY}`, "content-type": "application/json" },
  body: JSON.stringify({}), // fields: see the OpenAPI schema
});
const data = await res.json();
```

### POST /v1/pipelines/$ID/restore

Restore an archived pipeline (owner)

```bash
curl -s -X POST "https://api.closefinch.com/v1/pipelines/$ID/restore" \
  -H "Authorization: Bearer $RA_API_KEY" \
  -H "content-type: application/json" \
  -d '{}'
```

```js
const res = await fetch(`https://api.closefinch.com/v1/pipelines/${id}/restore`, {
  method: "POST",
  headers: { authorization: `Bearer ${process.env.RA_API_KEY}`, "content-type": "application/json" },
  body: JSON.stringify({}), // fields: see the OpenAPI schema
});
const data = await res.json();
```

Request and response schemas: [https://www.closefinch.com/openapi.json](https://www.closefinch.com/openapi.json). All resources: [API reference](https://www.closefinch.com/docs/api).
