# Set stages

Replaces the organization's stages, in pipeline order (at most 20). Give names (`"Demo booked"`: the key becomes `demo_booked`) or `{ "key", "label" }`. Renaming a stage or changing the order keeps its key and the rows on it; a stage that still holds rows cannot be removed (move them first with PATCH `stage`). The answer is the list as GET /stages gives it.

## Authentication

Send `Authorization: Bearer gtk_…`. Create the key under **Connect assistant → API keys**. Every `gtk_` key can call these routes, also while the Signals API is closed. A missing, invalid or revoked key is **401**.

### Body parameters

- **`stages`** `array` · **required** — Names or `{ key, label }` objects, in pipeline order. A key is lowercase letters, digits and `_`, up to 40 characters; a label up to 40 characters.

## Response

- **`…`** `object` · **required** — The list as GET /stages gives it.

## Credits

Free. This call never uses credits.

## Errors

- **400** `invalid_request` — Not a list, more than 20, a key that is not valid, the same stage twice, or a stage that still holds rows (the error says which and how many).
- **503** `service_unavailable` — Stages are not available in this environment yet.
- **409** `invalid_state` — The key has no user behind it, so mySDR cannot record who did it.
- **401** `authentication_error` — The Authorization header is missing, or the key is unknown or revoked.
- **403** `permission_error` — API access is not part of your plan, or your account is suspended.
- **429** `rate_limit_error` — More than 60 requests per minute, or more than 3 at the same time, on one key. Wait for the Retry-After header.
- **503** `service_unavailable` — The API is temporarily unavailable. Retry later.
- **500** `internal_error` — Something went wrong on our side.

## Example

### cURL

```bash
curl -X POST "https://mysdr.app/api/v1/stages" \
  -H "Authorization: Bearer $MYSDR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "stages": [
      "New lead",
      "MQL",
      {
        "key": "sql",
        "label": "SQL"
      },
      "Demo booked",
      "Won",
      "Lost"
    ]
  }'
```

### JavaScript

```javascript
const response = await fetch('https://mysdr.app/api/v1/stages', {
  method: 'POST',
  headers: {
    Authorization: `Bearer ${process.env.MYSDR_API_KEY}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    "stages": [
      "New lead",
      "MQL",
      {
        "key": "sql",
        "label": "SQL"
      },
      "Demo booked",
      "Won",
      "Lost"
    ]
  })
});
const body = await response.json();
```

### Python

```python
import json
import os
import urllib.request

payload = {
  "stages": [
    "New lead",
    "MQL",
    {
      "key": "sql",
      "label": "SQL"
    },
    "Demo booked",
    "Won",
    "Lost"
  ]
}

request = urllib.request.Request(
    "https://mysdr.app/api/v1/stages",
    headers={
    "Authorization": f"Bearer {os.environ['MYSDR_API_KEY']}",
    "Content-Type": "application/json"
    },
    data=json.dumps(payload).encode(),
    method="POST",
)
with urllib.request.urlopen(request) as response:
    body = json.load(response)
```

### Example response

```json
{
  "object": "list",
  "data": [
    {
      "key": "new_lead",
      "label": "New lead",
      "position": 1,
      "leads": 0,
      "companies": 0
    },
    {
      "key": "mql",
      "label": "MQL",
      "position": 2,
      "leads": 0,
      "companies": 0
    }
  ],
  "dashboard_url": "https://mysdr.app/en/gtm/leads"
}
```
