# Update a pipeline

`PATCH /v1/pipelines/{pipeline_id}`

Required scope: `schema:write`

Rename it, replace its ordered stages (send each existing stage with its `id`; a stage left out is archived) or make it the default.

## Path parameters

- `pipeline_id` (string, required)

## Request body (application/json)

- `is_default` (boolean or null, optional) Allowed values: `true`.
- `name` (string or null, optional)
- `stages` (object[] or null, optional)
  - `color` (string or null, optional) Allowed values: `"purple"`, `"green"`, `"red"`, `"yellow"`, `"gray"`, `"pink"`, `"blue"`, `"orange"`.
  - `forecast_category` (string, required) Allowed values: `"pipeline"`, `"best_case"`, `"commit"`, `"closed"`, `"omitted"`.
  - `id` (string or null, optional)
  - `name` (string, required)
  - `probability` (number or null, optional)
  - `type` (string, required) Allowed values: `"open"`, `"won"`, `"lost"`.

## Responses

- `200`: Successful Response
- `400`: The request is not valid.
- `401`: Not signed in, or the credentials are not valid.
- `402`: The balance is too low.
- `403`: Not allowed to do this.
- `404`: Not found.
- `409`: Conflicts with the current state.
- `413`: The request body is too large.
- `415`: The content type is not supported.
- `422`: A value in the request is not valid.
- `429`: Too many requests. Wait for `Retry-After` seconds.
- `500`: Something went wrong on our side.
- `502`: A service Valeron depends on refused the request.
- `503`: A service Valeron depends on is unavailable.

## Examples

### Request

```bash title="cURL"
curl -X PATCH "https://api.valeron.io/v1/pipelines/pl_01JBF6F9AC" \
  -H "Authorization: Bearer $VALERON_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "is_default": true,
  "name": "Jordan Rivera",
  "stages": [
    {
      "color": "purple",
      "forecast_category": "pipeline",
      "id": "pl_01J4YY08DC",
      "name": "Jordan Rivera",
      "probability": 1.5,
      "type": "open"
    }
  ]
}'
```

```js title="JavaScript"
const response = await fetch("https://api.valeron.io/v1/pipelines/pl_01JBF6F9AC", {
  method: "PATCH",
  headers: {
    Authorization: `Bearer ${process.env.VALERON_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "is_default": true,
    "name": "Jordan Rivera",
    "stages": [
      {
        "color": "purple",
        "forecast_category": "pipeline",
        "id": "pl_01J4YY08DC",
        "name": "Jordan Rivera",
        "probability": 1.5,
        "type": "open"
      }
    ]
  }),
});
if (!response.ok) throw new Error(`Valeron returned ${response.status}`);
const data = await response.json();
```

```python title="Python"
import os
import requests

response = requests.patch(
    "https://api.valeron.io/v1/pipelines/pl_01JBF6F9AC",
    headers={"Authorization": f"Bearer {os.environ['VALERON_API_KEY']}"},
    json={
        "is_default": True,
        "name": "Jordan Rivera",
        "stages": [
            {
                "color": "purple",
                "forecast_category": "pipeline",
                "id": "pl_01J4YY08DC",
                "name": "Jordan Rivera",
                "probability": 1.5,
                "type": "open",
            },
        ],
    },
)
response.raise_for_status()
data = response.json()
```

### Response 200

```json
{
  "id": "pl_01J4YY08DC",
  "is_default": true,
  "name": "Jordan Rivera",
  "stages": [
    {
      "color": "purple",
      "forecast_category": {
        "label": "Example",
        "value": "example"
      },
      "id": "pl_01J4YY08DC",
      "name": "Jordan Rivera",
      "probability": 1.5,
      "type": {
        "label": "Example",
        "value": "example"
      }
    }
  ]
}
```

### Response 401

```json
{
  "error": null
}
```

### Response 402

```json
{
  "error": null
}
```

### Response 403

```json
{
  "error": null
}
```

### Response 404

```json
{
  "error": null
}
```
