# Test sign-in details before saving

**POST** `/api/connections/test`

Tests sign-in details before you save them. Nothing is stored.

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

## Parameters

### Body

- `pieceId` · Optional · string: The app, for a new connection. Needed without `connectionId`.
- `connectionId` · Optional · UUID: For a change: a saved connection of the same app. Fields you leave blank keep its saved values.
- `config` · Optional · object: The details to test.

## Read it

`success: true` with `account`, who it signed in as. Or `success: false` with `error`, in the service’s words, and `cause`: `refused`, `expired`, `server`, `forbidden` or `other`.

`noVerdict: true` means no answer came back: no worker, the time ran out, or this installation doesn’t run the app (`reason`). Only then should a form offer to save untested.

## Responses

- 200 OK

  The result, whatever it was. Read `success` and `noVerdict`.

- 400 `VALIDATION_ERROR`

  No app, an unknown app, an app other than the connection’s, or details that aren’t valid.

- 403 `FORBIDDEN`

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

- 403 `MANAGED_CONNECTION`

  The partner manages this connection through its own API, so it can’t be changed here.

- 404 `NOT_FOUND`

  `connectionId` isn’t in this workspace.

- 422 `SECRETS_REQUIRED`

  The change moves where the connection points (a host, server, port, database, address or connection string) and left a saved secret blank. `details.fields` names the secrets to send again. Nothing changed.

- 500 `INTERNAL_ERROR`

  The saved connection couldn’t be read. 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

curl -X POST "$GORUNNER/api/connections/test" \
  -H "Authorization: Bearer $GORUNNER_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "pieceId": "email",
    "config": {
      "host": "smtp.office365.com",
      "port": "587",
      "email": "warehouse@bakery.example",
      "password": "…"
    }
  }'
```

**JavaScript**

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

const res = await fetch(
  `${GORUNNER}/api/connections/test`,
  {
    method: "POST",
    headers: {
        Authorization: `Bearer ${TOKEN}`,
        "Content-Type": "application/json",
      },
    body: JSON.stringify({
        pieceId: "email",
        config: {
          host: "smtp.office365.com",
          port: "587",
          email: "warehouse@bakery.example",
          password: "…",
        },
      }),
  },
);
const { data } = await res.json();
```

**Python**

```python
import os, requests

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

res = requests.post(
    f"{GORUNNER}/api/connections/test",
    headers={"Authorization": f"Bearer {TOKEN}"},
    json={
      "pieceId": "email",
      "config": {
        "host": "smtp.office365.com",
        "port": "587",
        "email": "warehouse@bakery.example",
        "password": "…",
      },
    },
)
data = res.json()["data"]
```

Response · 200 OK, refused

```json
{
  "data": {
    "success": false,
    "error": "smtp auth: 535 5.7.3 Authentication unsuccessful",
    "cause": "refused"
  }
}
```

**Every field**

### Body

- `pieceId` · Optional · string: The app, for an add. Required without `connectionId`.
- `connectionId` · Optional · UUID: For a change: the draft is laid over this connection’s stored config (a blank field keeps the saved value). Same app, same workspace.
- `config` · Optional · object

### Response · 200 OK

- `data` · object
  - `success` · boolean
  - `message` · string
  - `account` · string
  - `error` · string
  - `cause` · string: One of `refused`, `expired`, `server`, `forbidden`, `other`.
  - `noVerdict` · boolean: No verdict came back (no worker, the time ran out, an app this build does not serve): the only case a form offers to save without a test.
  - `reason` · string: One of `no_worker`, `timeout`, `not_served`.

Related: [Create a connection](https://docs.gorunner.io/api/connections/create-connection) · [Test a connection](https://docs.gorunner.io/api/connections/test-connection)

Source: https://docs.gorunner.io/api/connections/test-connection-draft
