# Ask for a key

> Asks for a key for your company. Only from siteswap.pro, signed in as an owner or admin (the API keys page does this). The key is in this answer only. It answers 403 key_pending until a SiteSwap admin approves it.


`POST https://dev.siteswap.pro/api/v1/keys`

Asks for a key for your company. Only from siteswap.pro, signed in as an owner or admin (the API keys page does this). The key is in this answer only. It answers `403 key_pending` until a SiteSwap admin approves it.

## Body

- `name` (string, required)
- `purpose` (string, required): What the key is for. A SiteSwap admin reads it before approving
- `scopes` (("listings:read" | "listings:write" | "offers" | "alerts")[], required): What it may do

```json
{
  "name": "Stock sync",
  "purpose": "Keep our yard stock in step with our inventory system.",
  "scopes": [
    "listings:read",
    "listings:write"
  ]
}
```

## Responses

- 201: Created
- 400: bad_request, key_in_url or invalid_json: the request could not be read
- 401: missing_key or invalid_key: no key, or a key that is not valid or was revoked
- 403: key_pending, key_declined, scope_missing, terms_required or account_unavailable: see Errors
- 404: not_found: nothing here that you may see
- 413: too_large: the body is over 256 KB
- 429: rate_limited or daily_quota: wait for Retry-After seconds

## Response fields

- `id` (string): The key's public prefix: the 10 characters after `ssk_`
- `name` (string)
- `purpose` (string)
- `status` ("pending" | "active" | "declined" | "revoked"): `pending` until a SiteSwap admin approves it
- `scopes_asked` (string[])
- `scopes` (string[]): What it was granted; empty until approved
- `per_minute` (integer): Requests a minute
- `per_day` (integer): Requests a day (UTC)
- `calls` (integer): Calls counted so far
- `last_used_at` (string | null): The last call
- `created_at` (string): When it was asked for. ISO 8601 in UTC
- `asked_by` (string): Who asked for it
- `note` (string | null): Why it was declined, from the SiteSwap admin
- `key` (string): The key itself, shown only here

```json
{
  "data": {
    "id": "string",
    "name": "string",
    "purpose": "string",
    "status": "pending",
    "scopes_asked": [
      "string"
    ],
    "scopes": [
      "string"
    ],
    "per_minute": 0,
    "per_day": 0,
    "calls": 0,
    "last_used_at": "string",
    "created_at": "string",
    "asked_by": "string",
    "note": "string",
    "key": "string"
  },
  "meta": {
    "request_id": "3f9a1c0b7d2e",
    "api_version": "v1"
  }
}
```

## Example

```bash
curl -X POST "https://dev.siteswap.pro/api/v1/keys" \
  -H "Content-Type: application/json" \
  -d '{"name":"Stock sync","purpose":"Keep our yard stock in step with our inventory system.","scopes":["listings:read","listings:write"]}'
```