# Update a provider OAuth app

Save your provider OAuth client, optionally together with activation, World assignment, and tool defaults.

`PATCH https://api.smallworld.sh/api/v1/integrations/:integration/oauth-app`

## Parameters

| Name | Location | Type | Required | Description |
| --- | --- | --- | --- | --- |
| integration | path | string | Yes | An integration key from GET /integrations or /integration-configurations. |
| clientId | body | string | No | 1–256 trimmed characters. Omit to keep the existing client ID. |
| clientSecret | body | string | No | At most 512 characters, preserved exactly. Omit or send an empty string to keep the existing secret for the same client. |
| enabled | body | boolean | No | Workspace activation. Omitting it preserves activation. |
| authScheme | body | string | No | oauth2 or api_key, from the supported authSchemes. Omitting it preserves the selected scheme. |
| worldIds | body | UUID[] | No | Complete replacement of assigned Worlds. Omit to preserve assignments; [] removes them all. Duplicate IDs are rejected. |
| toolPolicies | body | object[] | No | Atomic tool-default updates, up to 256 entries. Each entry has toolName and policy (allow, ask, or deny). Omitted tools keep their defaults; [] changes none. |

## Request examples

### curl

```curl
curl --fail-with-body -X PATCH 'https://api.smallworld.sh/api/v1/integrations/notion/oauth-app' \
  -H "Authorization: Bearer $SMALLWORLD_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "clientId": "your-client-id",
  "clientSecret": "your-client-secret",
  "enabled": true,
  "worldIds": [
    "01995e56-e2d4-7f19-b691-7bf9af6abdc8"
  ]
}'
```

### typescript

```typescript
const response = await fetch("https://api.smallworld.sh/api/v1/integrations/notion/oauth-app", {
  method: "PATCH",
  headers: { Authorization: `Bearer ${apiKey}`, "Content-Type": "application/json" },
  body: JSON.stringify({
  "clientId": "your-client-id",
  "clientSecret": "your-client-secret",
  "enabled": true,
  "worldIds": [
    "01995e56-e2d4-7f19-b691-7bf9af6abdc8"
  ]
}),
});
if (!response.ok) throw new Error(`HTTP ${response.status}: ${await response.text()}`);
const result = await response.json();
```

### python

```python
response = requests.patch(
    "https://api.smallworld.sh/api/v1/integrations/notion/oauth-app",
    headers={"Authorization": f"Bearer {api_key}"},
    json={
  "clientId": "your-client-id",
  "clientSecret": "your-client-secret",
  "enabled": True,
  "worldIds": ["01995e56-e2d4-7f19-b691-7bf9af6abdc8"]
},
    timeout=30,
)
response.raise_for_status()
result = response.json()
```

## Responses

Returns the same redacted app configuration as GET /integrations/:integration/oauth-app.

### 200

Returns the same redacted app configuration as GET /integrations/:integration/oauth-app.

```json
{
  "integration": "notion",
  "clientId": "your-client-id",
  "hasClientSecret": true,
  "redirectUri": "https://api.smallworld.sh/api/integrations/oauth/notion/callback",
  "scopes": [],
  "requiresCredentials": true,
  "clientSecretRequired": true,
  "configured": true,
  "status": "configured"
}
```

### 400

invalid_request: A path or request body is invalid. Unknown fields are rejected. integration_invalid_provider: The integration key is unknown in this workspace. integration_setup_required: Complete provider or MCP setup before enabling the integration. integration_setup_not_supported: This integration does not accept workspace OAuth credentials. integration_oauth_client_invalid: The provider rejected the OAuth app credentials. integration_auth_scheme_not_supported: The integration does not support this connection method.

#### invalid_request

A path or request body is invalid. Unknown fields are rejected.

```json
{
  "statusCode": 400,
  "code": "invalid_request",
  "message": "The request is invalid"
}
```

#### integration_invalid_provider

The integration key is unknown in this workspace.

```json
{
  "statusCode": 400,
  "code": "integration_invalid_provider",
  "message": "Unsupported integration provider 'notion'"
}
```

#### integration_setup_required

Complete provider or MCP setup before enabling the integration.

```json
{
  "statusCode": 400,
  "code": "integration_setup_required",
  "message": "Complete the integration setup before users can connect it"
}
```

#### integration_setup_not_supported

This integration does not accept workspace OAuth credentials.

```json
{
  "statusCode": 400,
  "code": "integration_setup_not_supported",
  "message": "This integration does not accept workspace OAuth credentials"
}
```

#### integration_oauth_client_invalid

The provider rejected the OAuth app credentials.

```json
{
  "statusCode": 400,
  "code": "integration_oauth_client_invalid",
  "message": "Notion didn't accept this Client Secret. Copy it again from your Notion app settings."
}
```

#### integration_auth_scheme_not_supported

The integration does not support this connection method.

```json
{
  "statusCode": 400,
  "code": "integration_auth_scheme_not_supported",
  "message": "Notion does not support api_key connections"
}
```

### 401

authentication_required: The Authorization header is missing or empty. invalid_api_key: The API key is invalid or revoked, or the header doesn't use the Bearer scheme.

#### authentication_required

The Authorization header is missing or empty.

```json
{
  "statusCode": 401,
  "code": "authentication_required",
  "message": "Authentication is required"
}
```

#### invalid_api_key

The API key is invalid or revoked, or the header doesn't use the Bearer scheme.

```json
{
  "statusCode": 401,
  "code": "invalid_api_key",
  "message": "The API key is invalid or revoked"
}
```

### 403

ip_not_allowed: The request came from an address outside the workspace's IP allowlist.

#### ip_not_allowed

The request came from an address outside the workspace's IP allowlist.

```json
{
  "statusCode": 403,
  "code": "ip_not_allowed",
  "message": "The source IP address is not allowed by this account's security settings"
}
```

### 404

world_not_found: The World does not exist in this workspace.

#### world_not_found

The World does not exist in this workspace.

```json
{
  "statusCode": 404,
  "code": "world_not_found",
  "message": "World not found"
}
```

### 409

integration_auth_scheme_change_not_allowed: The current active OAuth setup cannot switch back to API-key connections.

#### integration_auth_scheme_change_not_allowed

The current active OAuth setup cannot switch back to API-key connections.

```json
{
  "statusCode": 409,
  "code": "integration_auth_scheme_change_not_allowed",
  "message": "Notion already uses your OAuth app. The connection method can't be changed back to personal access tokens."
}
```

### 413

request_too_large: The JSON body is larger than 12 MiB. File uploads count toward it, base64 or escaping included.

#### request_too_large

The JSON body is larger than 12 MiB. File uploads count toward it, base64 or escaping included.

```json
{
  "statusCode": 413,
  "code": "request_too_large",
  "message": "The request body is larger than 12 MiB."
}
```

### 415

unsupported_media_type: The request has a body that isn't JSON. Send JSON with Content-Type: application/json, or no body at all.

#### unsupported_media_type

The request has a body that isn't JSON. Send JSON with Content-Type: application/json, or no body at all.

```json
{
  "statusCode": 415,
  "code": "unsupported_media_type",
  "message": "Send the request body as JSON with Content-Type: application/json."
}
```

### 500

internal_error: An unexpected server error.

#### internal_error

An unexpected server error.

```json
{
  "statusCode": 500,
  "code": "internal_error",
  "message": "Internal server error"
}
```

## Notes

- Credentials and accompanying configuration are saved atomically after validation. Secrets are encrypted at rest.

- Changing clientId can require a new clientSecret. A provider can require both fields on first setup.

- Providers that do not support workspace OAuth apps reject the update. Provider validation can reject invalid credentials before saving.
