# Update a connection

> Rename a connection, share it with the workspace, or replace its credentials (validated by the app first). Any editor who can see a connection shared with the workspace can update it.

Source: https://docs.stacksync.com/api-reference/connections/update_connection

`POST https://api.stacksync.com/v1/workspaces/{workspace_id}/connections/{connection_id}/update`

- Operation: `update_connection`
- Resource: Connections
- Access: writes data

## Authentication

- `Authorization: Bearer <key>`: A workspace API key (workspace_…, created by a workspace owner under Workspace settings > Stacksync API) acts with editor rights on that workspace only; a user API key (user_…, created under Profile > Stacksync API) acts as that user in every workspace they belong to. POST, PUT and PATCH requests must send Content-Type: application/json. Every authentication failure answers 403.
- `Content-Type: application/json` on every request with a body.

## Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `workspace_id` | integer | Yes | The workspace. List the ones your key can reach with GET /v1/workspaces. |
| `connection_id` | string (uuid) | Yes | The connection. |

## Query parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `region` | string (besg \| usnv) | Yes | Region of the connection: besg or usnv |

## Request body

`application/json`

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `connection_name` | string \| null, 3 to 63 characters, pattern `^[A-Za-z0-9_\- ]+$` | No | The new name: letters, numbers, dashes, underscores and spaces, 3 to 63 characters |
| `is_shared_with_workspace` | boolean \| null | No | True to share the connection with every member of the workspace |
| `credentials` | object \| null | No | The new credentials of the app |
| `validate_only` | boolean, default false | No | Run every check of the write and answer 204 without writing: a refused write answers the error the write would |

## Returns

### 200 OK

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `data` | object (Connection) | Yes |  |
| `data.connection_id` | string | Yes |  |
| `data.connection_name` | string | Yes |  |
| `data.app_type` | string | Yes | The type shown in Stacksync |
| `data.is_shared_with_workspace` | boolean | Yes |  |
| `data.created_time` | string | Yes | UTC, YYYY-MM-DD HH:MM:SS |
| `data.last_modified_time` | string | Yes | UTC, YYYY-MM-DD HH:MM:SS |
| `data.credentials_options` | object | Yes | The identifiers of the connection (instance_id, instance_url, shop_name, sub_domain...), never a secret |
| `data.connection_resource_id` | string \| null | Yes | The name workflow steps reference the connection by |
| `data.region` | string | Yes |  |
| `data.needs_reauthorization` | boolean | Yes | True when Stacksync marked the credentials invalid (the app refused to refresh them): reauthorize it in Stacksync. Credentials the app refuses on a read are reported by that read |

### 204 No Content

No body.

## Example request

```bash
curl -X POST "https://api.stacksync.com/v1/workspaces/{workspace_id}/connections/{connection_id}/update?region=usnv" \
  -H "Authorization: Bearer $STACKSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "connection_name": "Production Postgres"
}'
```

## Example response (200)

```json
{
  "data": {
    "connection_id": "<connection_id>",
    "connection_name": "<connection_name>",
    "app_type": "<app_type>",
    "is_shared_with_workspace": false,
    "created_time": "<created_time>",
    "last_modified_time": "<last_modified_time>",
    "credentials_options": {},
    "connection_resource_id": "<connection_resource_id>",
    "region": "<region>",
    "needs_reauthorization": false
  }
}
```

## Errors

| Status | Meaning | Body |
| --- | --- | --- |
| 400 | Bad Request | `{ "error": string, "msg": string, "field": string \| null }` |
| 403 | Forbidden | `{ "error": string, "msg": string, "field": string \| null }` |
| 404 | Not Found | `{ "error": string, "msg": string, "field": string \| null }` |
| 409 | Conflict | `{ "error": string, "msg": string, "field": string \| null }` |

## Related

- [API Reference overview](https://docs.stacksync.com/api-reference): base URLs, regions, pagination, idempotency and errors
- [Authentication](https://docs.stacksync.com/api-reference/authentication): API keys and the 403 answers
- OpenAPI document: https://docs.stacksync.com/openapi.json
- [List connections](https://docs.stacksync.com/api-reference/connections/list_connections)
- [Get a connection](https://docs.stacksync.com/api-reference/connections/get_connection)
- [Create a connection](https://docs.stacksync.com/api-reference/connections/create_connection)
- [Delete a connection](https://docs.stacksync.com/api-reference/connections/delete_connection)
- [Reauthorize a connection](https://docs.stacksync.com/api-reference/connections/reauthorize_connection)