# Move workflows to another connection

**POST** `/api/connections/{id}/replace`

Moves every workflow from this connection to another of the same app.

Needs [an API token](https://docs.gorunner.io/api/authentication#scopes) with the **Write** permission for connections (`connection:write`).

## Parameters

### Path

- `id` · Required · UUID: The connection to move workflows away from.

### Body

- `targetId` · Required · UUID: The connection to move them to: another one, of the same app, in this workspace.
- `workflowIds` · Optional · array of UUIDs: Only these workflows, up to 500. Moving the answer’s `workflowIds` back undoes it exactly.

## What moves

Every reference in each workflow’s draft and its stored versions: triggers, steps, branches, loops and error steps. `alsoOnTarget` names workflows that already used the target too; moving them back moves those steps as well.

Neither connection is deleted. Sending it again finds nothing left and answers 0, so it needs no `Idempotency-Key`. Then [delete the old one](https://docs.gorunner.io/api/connections/delete-connection) if you like.

## Responses

- 200 OK

  How many workflows moved, and which. 0 is fine: nothing used it.

- 400 `VALIDATION_ERROR`

  An ID isn’t a UUID, the body isn’t JSON, the two are the same connection, or they are for different apps.

- 403 `FORBIDDEN`

  The token lacks the **Write** permission for connections.

- 404 `NOT_FOUND`

  The connection or the target isn’t in this workspace.

- 500 `INTERNAL_ERROR`

  Nothing moved. Try again.

Any call can also answer: [`401 UNAUTHORIZED`](https://docs.gorunner.io/errors#UNAUTHORIZED) · [`401 TOKEN_ENDED`](https://docs.gorunner.io/errors#TOKEN_ENDED) · [`403 TOKEN_SURFACE_OFF`](https://docs.gorunner.io/errors#TOKEN_SURFACE_OFF) · [`403 FEATURE_OFF`](https://docs.gorunner.io/errors#FEATURE_OFF) · [`403 EMBED_NOT_ALLOWED`](https://docs.gorunner.io/errors#EMBED_NOT_ALLOWED) · [`403 EMBED_NOT_AVAILABLE`](https://docs.gorunner.io/errors#EMBED_NOT_AVAILABLE) · [`403 ACCOUNT_SUSPENDED`](https://docs.gorunner.io/errors#ACCOUNT_SUSPENDED) · [`413 PAYLOAD_TOO_LARGE`](https://docs.gorunner.io/errors#PAYLOAD_TOO_LARGE) · [`415 INVALID_CONTENT_TYPE`](https://docs.gorunner.io/errors#INVALID_CONTENT_TYPE) · [`429 RATE_LIMITED`](https://docs.gorunner.io/errors#RATE_LIMITED) · [`503 BUSY`](https://docs.gorunner.io/errors#BUSY) · [`503 PAUSED`](https://docs.gorunner.io/errors#PAUSED) · [`503 SERVICE_UNAVAILABLE`](https://docs.gorunner.io/errors#SERVICE_UNAVAILABLE). See [Errors](https://docs.gorunner.io/api/errors#by-status).

Request

**curl**

```bash
GORUNNER="https://api.gorunner.io"
GORUNNER_TOKEN="grt_…"  # needs Write for connections
CONNECTION_ID="your-connection-id"

URL="$GORUNNER/api/connections/$CONNECTION_ID/"
URL="${URL}replace"
curl -X POST "$URL" \
  -H "Authorization: Bearer $GORUNNER_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "targetId": "8c7d6e5f-4a3b-2c1d-0e9f-8a7b6c5d4e3f"
  }'
```

**JavaScript**

```js
const GORUNNER = "https://api.gorunner.io";
const TOKEN = process.env.GORUNNER_TOKEN;
const CONNECTION_ID = process.env.CONNECTION_ID;

const res = await fetch(
  `${GORUNNER}/api/connections/` +
    `${CONNECTION_ID}/replace`,
  {
    method: "POST",
    headers: {
        Authorization: `Bearer ${TOKEN}`,
        "Content-Type": "application/json",
      },
    body: JSON.stringify({
        targetId: "8c7d6e5f-4a3b-2c1d-0e9f-8a7b6c5d4e3f",
      }),
  },
);
const { data } = await res.json();
```

**Python**

```python
import os, requests

GORUNNER = "https://api.gorunner.io"
TOKEN = os.environ["GORUNNER_TOKEN"]
CONNECTION_ID = os.environ["CONNECTION_ID"]

res = requests.post(
    f"{GORUNNER}/api/connections/{CONNECTION_ID}/"
    f"replace",
    headers={"Authorization": f"Bearer {TOKEN}"},
    json={
      "targetId": "8c7d6e5f-4a3b-2c1d-0e9f-8a7b6c5d4e3f",
    },
)
data = res.json()["data"]
```

Response · 200 OK

```json
{
  "data": {
    "updated": 3,
    "workflowIds": [
      "3b1e5c2a-7d4f-4e8b-a1c6-5f2d9b0e7a31",
      "6e9a1c3f-8b2d-4a57-9e0c-3f7b5d1a8c42",
      "…"
    ],
    "alsoOnTarget": []
  }
}
```

**Every field**

### Body

- `targetId` · Required · UUID: The connection to repoint references to. Must exist in the same workspace, must differ from the path id, and must have the SAME `pieceId` as the source.
- `workflowIds` · Optional · array of UUIDs: Move only these workflows (their drafts and every version). The answer’s `workflowIds` moved back the other way is an exact Undo.

### Response · 200 OK

- `data` · object
  - `updated` · integer: How many workflows were moved (drafts and every stored version, counted once per workflow).
  - `workflowIds` · array of UUIDs: The workflows moved.
  - `alsoOnTarget` · array of UUIDs: Moved workflows that already named the target before: moving them back moves those steps too.

Related: [See which workflows use each connection](https://docs.gorunner.io/api/connections/get-connection-usage) · [Delete a connection](https://docs.gorunner.io/api/connections/delete-connection)

Source: https://docs.gorunner.io/api/connections/replace-connection-references
