# Move a WordPress site onto an account key

`POST https://api.astroway.info/v1/site-keys/connect/exchange`

Second half of connecting a site to an account. The owner picks a key on api.astroway.info/dashboard/connect, which sends the admin back to the site with a one-time `code`; the plugin exchanges it here, server side, sending its site key in `X-Api-Key`. The code lives 5 minutes; the same code from the same site key within 10 minutes returns the same answer, so a plugin that crashed before saving can ask again. The site key stops working 24 hours after the exchange. Errors: `400 INVALID_CODE`, `410 CODE_EXPIRED`, `403 SITE_MISMATCH`.

Group: System. Auth: `X-Api-Key` header. Operation ID: `site-keys_connect_exchange`.

## Parameters

| Name | In | Required | Type | Description |
|---|---|---|---|---|
| `fields` | query | no | string | Comma-separated dotted paths, relative to `data`, to keep in the response. A path is applied to every element of an array, so `planets.name` means the name of each planet. Paths that match nothing come back in `_fields_unmatched`; a list where nothing matches at all is a 400, because an empty object would be a confident wrong answer. |
| `precision` | query | no | integer | Round every non-integer number in the response to this many decimal places. Integers are left alone, because an id is not a measurement. Ecliptic longitudes ship with fourteen decimals by default; 2 is about a tenth of an arcminute. |

## Request body

| Field | Type | Required | Description |
|---|---|---|---|
| `code` | string | yes | The one-time code the dashboard appended to the return URL. |
| `site_url` | string | yes | The site home URL, the same one the site key was issued for. |

```json
{
  "code": "Jx3l0v8QeZcX2n9F1aK7pM4sT6bW5yR0uH2dG8jC1oE",
  "site_url": "https://example.com"
}
```

## Responses

| Status | Meaning |
|---|---|
| 200 | Successful calculation |
| 400 | Validation error |
| 401 | Missing or invalid API key |

### Success fields, under `data`

| Field | Type | Required | Description |
|---|---|---|---|
| `key` | string | no |  |
| `plan` | string | no |  |
| `domain` | string | no |  |
| `account` | string | no |  |

## Example

```bash
curl -X POST https://api.astroway.info/v1/site-keys/connect/exchange \
  -H "X-Api-Key: aw_live_..." \
  -H "Content-Type: application/json" \
  -d '{ "code": "Jx3l0v8QeZcX2n9F1aK7pM4sT6bW5yR0uH2dG8jC1oE", "site_url": "https://example.com" }'
```

---

Rendered from https://api.astroway.info/v1/openapi.json. HTML page: https://api.astroway.info/docs/api/operations/site-keys_connect_exchange/
