# Move a domain to its application's current routing, or back to the edge

> retarget connection: reference page for this CustomDomain™ API operation in the connections group. Covers parameters, request body, responses and error codes.

Source: https://docs.customdomain.ai/docs/api-reference/connections/retargetConnection

## `POST https://api.customdomain.ai/v1/connections/{id}:retarget`

A connected domain keeps the routing it connected with when its application's routing changes (domains still waiting for DNS follow the change). This moves one: the domain's expected records become those of the application's current routing, or with `{"to": "edge"}` those of the CustomDomain™ edge whatever the application's routing (the way back for a domain moved off the edge by mistake). The body is optional.

The customer's DNS is not changed. A moved domain goes back to `pending` with a fresh verification clock, is checked at once (a domain whose DNS already names the new place is `live` again in the response's `status`), and otherwise waits for its records (returned in `records`); drift is not reported while it waits. Moving a live domain off the edge stops edge serving at once (`stops_edge_serving`).

A domain whose records were written through a connected provider account that holds a usable key is moved by rewriting them, when the `move_rewrite` flag is on: the response carries `rewriting: true` and `customer_action_required: false`, the new records are written in the background and the domain is verified on them (`propagating`); if the write fails twice the customer is told as for any other move.

A no-op (`moved: false`) when the domain already points there. Refused (409) when the domain's records are stored and no rewrite is possible: records your backend supplied (change them with `PUT /connections/{id}/records`) or records written into the customer's DNS during setup by a rail that cannot rewrite them (disconnect and reconnect to move it). A server-side API key or an agent token only: a widget token is refused (403). Recorded in the audit log as `connection.retargeted`.

### Authentication

`apiKey`, `agentToken`

### Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `id` | path | string | yes |  |

### Request body (JSON)

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `to` | `application`, `edge` | no | Where to move the domain. |

### Responses

| Status | Description |
| --- | --- |
| `200` | The domain's routing after the move, and its records from now on. |
| `400` | Error envelope: {code, title, details, request_id}. |
| `401` | Error envelope: {code, title, details, request_id}. |
| `403` | Error envelope: {code, title, details, request_id}. |
| `404` | Error envelope: {code, title, details, request_id}. |
| `409` | Error envelope: {code, title, details, request_id}. |

### `200` response body

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `connection_id` | string | yes |  |
| `moved` | boolean | yes |  |
| `routing` | object | yes |  |
| `previous_routing` | object | no |  |
| `records` | array of object | yes |  |
| `customer_action_required` | boolean | yes |  |
| `rewriting` | boolean | no | CustomDomain™ is writing the new records itself, through the rail that wrote the old ones. Present only when true; `customer_action_required` is then false. |
| `stops_edge_serving` | boolean | yes |  |
| `status` | `pending`, `propagating`, `live`, `failed` | no |  |

The full specification is served at `GET https://api.customdomain.ai/v1/openapi.json`.
