> ## Documentation Index
> Fetch the complete documentation index at: https://docs.apinizer.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Update WebSocket Settings

> Updates WebSocket routing settings for a WebSocket API proxy. These settings control WebSocket connection behavior including timeouts, reconnection, and retry configuration.

## Endpoint

```
PATCH /apiops/projects/{projectName}/apiProxies/{apiProxyName}/settings/websocket/
```

## Authentication

Requires a Personal API Access Token.

### Header

```
Authorization: Bearer YOUR_TOKEN
```

## Request

### Headers

| Header        | Value            | Required |
| ------------- | ---------------- | -------- |
| Authorization | Bearer {token}   | Yes      |
| Content-Type  | application/json | Yes      |

### Path Parameters

| Parameter    | Type   | Required | Description    |
| ------------ | ------ | -------- | -------------- |
| projectName  | string | Yes      | Project name   |
| apiProxyName | string | Yes      | API Proxy name |

### Request Body

#### Full JSON Body Example

```json theme={null}
{
  "websocketSettings": {
    "connectionLostTimeout": 60,
    "reuseAddr": true,
    "connectTimeout": 30,
    "maxRetries": 3,
    "retryDelay": 1000,
    "autoReconnect": true,
    "autoReconnectMaxRetries": 5,
    "autoReconnectRetryDelay": 2000
  },
  "deploy": false,
  "deployTargetEnvironmentNameList": []
}
```

#### Request Body Fields

| Field                           | Type           | Required | Default | Description                                                        |
| ------------------------------- | -------------- | -------- | ------- | ------------------------------------------------------------------ |
| websocketSettings               | object         | Yes      | -       | WebSocket settings object (see fields below)                       |
| deploy                          | boolean        | No       | false   | If true, deploy the API proxy after saving changes                 |
| deployTargetEnvironmentNameList | array\[string] | No       | -       | List of environment names to deploy to (required when deploy=true) |

#### websocketSettings Fields

| Field                   | Type    | Required | Default        | Description                                               |
| ----------------------- | ------- | -------- | -------------- | --------------------------------------------------------- |
| connectionLostTimeout   | integer | No       | System default | Timeout in seconds before a connection is considered lost |
| reuseAddr               | boolean | No       | System default | Enable socket address reuse (SO\_REUSEADDR)               |
| connectTimeout          | integer | No       | System default | WebSocket connection timeout in seconds                   |
| maxRetries              | integer | No       | System default | Maximum number of initial connection retry attempts       |
| retryDelay              | integer | No       | System default | Delay between initial connection retries in milliseconds  |
| autoReconnect           | boolean | No       | System default | Enable automatic reconnection after connection loss       |
| autoReconnectMaxRetries | integer | No       | System default | Maximum number of auto-reconnect attempts                 |
| autoReconnectRetryDelay | integer | No       | System default | Delay between auto-reconnect attempts in milliseconds     |

**Note:** All fields are optional. Only provided fields are updated. Default values are inherited from system settings.

## Response

### Success Response (200 OK)

```json theme={null}
{
  "success": true
}
```

When `deploy=true` is specified:

```json theme={null}
{
  "success": true,
  "deploymentResult": {
    "success": true,
    "deploymentResults": [
      {
        "environmentName": "production",
        "success": true,
        "message": "Deployment successful"
      }
    ]
  }
}
```

| Field                                                 | Type    | Description                                       |
| ----------------------------------------------------- | ------- | ------------------------------------------------- |
| success                                               | boolean | Whether the settings update was successful        |
| deploymentResult                                      | object  | Deployment result (only present when deploy=true) |
| deploymentResult.success                              | boolean | Whether all deployments were successful           |
| deploymentResult.deploymentResults                    | array   | Per-environment deployment results                |
| deploymentResult.deploymentResults\[].environmentName | string  | Name of the target environment                    |
| deploymentResult.deploymentResults\[].success         | boolean | Whether deployment to this environment succeeded  |
| deploymentResult.deploymentResults\[].message         | string  | Deployment status message                         |

### Error Response (400 Bad Request)

```json theme={null}
{
  "error": "bad_request",
  "error_description": "API Proxy type is not WEBSOCKET"
}
```

### Error Response (401 Unauthorized)

```json theme={null}
{
  "error": "unauthorized_client",
  "error_description": "Invalid token"
}
```

### Error Response (404 Not Found)

```json theme={null}
{
  "error": "not_found",
  "error_description": "ApiProxy (name: MyWebSocketAPI) was not found!"
}
```

## cURL Example

### Example 1: Configure Connection and Auto-Reconnect

```bash theme={null}
curl -X PATCH \
  "https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyWebSocketAPI/settings/websocket/" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "websocketSettings": {
      "connectionLostTimeout": 120,
      "connectTimeout": 30,
      "autoReconnect": true,
      "autoReconnectMaxRetries": 10,
      "autoReconnectRetryDelay": 3000
    }
  }'
```

### Example 2: Configure Retry Settings

```bash theme={null}
curl -X PATCH \
  "https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyWebSocketAPI/settings/websocket/" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "websocketSettings": {
      "maxRetries": 5,
      "retryDelay": 2000,
      "reuseAddr": true
    }
  }'
```

### Example 3: Disable Auto-Reconnect

```bash theme={null}
curl -X PATCH \
  "https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyWebSocketAPI/settings/websocket/" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "websocketSettings": {
      "autoReconnect": false
    }
  }'
```

### Example 4: Save and Deploy

```bash theme={null}
curl -X PATCH \
  "https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyWebSocketAPI/settings/websocket/" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "websocketSettings": {
      "connectionLostTimeout": 120,
      "connectTimeout": 30,
      "autoReconnect": true
    },
    "deploy": true,
    "deployTargetEnvironmentNameList": ["production"]
  }'
```

## Notes and Warnings

* **WebSocket Only**: This endpoint is only applicable to API Proxies with WebSocket type. Using it on HTTP/REST proxies will result in an error.
* **Connection Lost Timeout**: If no data is received within this timeout, the connection is considered lost. Set higher for long-lived idle connections.
* **Initial Retries vs Auto-Reconnect**: `maxRetries` and `retryDelay` control the initial connection attempt. `autoReconnect*` settings control reconnection after an established connection is lost.
* **Retry Delay**: Both `retryDelay` and `autoReconnectRetryDelay` are in milliseconds.
* **Socket Reuse**: `reuseAddr=true` allows reusing the socket address, which is useful in high-connection environments.
* **System Defaults**: When a field is not set, the value is inherited from system-level settings.
* **Deploy**: When `deploy=true`, the API proxy is automatically deployed to the specified environments after saving.

## Permissions

User must have **`API_MANAGEMENT` + `MANAGE`** permission in the project.

## Related Documentation

* [Update Connection Settings](/api-reference/api-proxies/settings/update-connection-settings) - Update HTTP connection settings
* [Update Routing Addresses](/api-reference/api-proxies/settings/update-routing-addresses) - Update backend routing addresses
* [Get API Proxy](/api-reference/api-proxies/crud/get-api-proxy) - Get API proxy details
