> ## 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 Custom Message Settings

> Updates custom response message settings for an API proxy. Custom message settings allow the gateway to return a predefined response instead of forwarding to the backend.

## Endpoint

```
PATCH /apiops/projects/{projectName}/apiProxies/{apiProxyName}/settings/custom-message/
```

## 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}
{
  "buildCustomMessage": true,
  "customMessageTemplate": "{\"status\": \"ok\", \"message\": \"Service is running\"}",
  "customMessageContentType": "application/json",
  "customMessageHttpStatusCode": 200,
  "deploy": false,
  "deployTargetEnvironmentNameList": []
}
```

#### Request Body Fields

| Field                           | Type           | Required | Default | Description                                                        |
| ------------------------------- | -------------- | -------- | ------- | ------------------------------------------------------------------ |
| buildCustomMessage              | boolean        | No       | false   | Enable custom response message building                            |
| customMessageTemplate           | string         | No       | -       | Response body template (supports variables)                        |
| customMessageContentType        | string         | No       | -       | Content-Type header for the custom response                        |
| customMessageHttpStatusCode     | integer        | No       | -       | HTTP status code for the custom response                           |
| 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) |

**Note:** All fields are optional. Only provided fields are updated.

## 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"
      }
    ]
  }
}
```

#### Response Fields

| Field                              | Type    | Description                             |
| ---------------------------------- | ------- | --------------------------------------- |
| success                            | boolean | Indicates if the request was successful |
| deploymentResult                   | object  | Only present when `deploy=true`         |
| deploymentResult.success           | boolean | Overall deployment success status       |
| deploymentResult.deploymentResults | array   | Per-environment deployment results      |

### 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: MyAPI) was not found!"
}
```

## cURL Example

### Example 1: Enable Custom JSON Response

```bash theme={null}
curl -X PATCH \
  "https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAPI/settings/custom-message/" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "buildCustomMessage": true,
    "customMessageTemplate": "{\"status\": \"ok\", \"version\": \"1.0\"}",
    "customMessageContentType": "application/json",
    "customMessageHttpStatusCode": 200
  }'
```

### Example 2: Enable Custom XML Response

```bash theme={null}
curl -X PATCH \
  "https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAPI/settings/custom-message/" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "buildCustomMessage": true,
    "customMessageTemplate": "<response><status>ok</status><message>Service healthy</message></response>",
    "customMessageContentType": "application/xml",
    "customMessageHttpStatusCode": 200
  }'
```

### Example 3: Disable Custom Message (Resume Normal Routing)

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

### Example 4: Save and Deploy

```bash theme={null}
curl -X PATCH \
  "https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAPI/settings/custom-message/" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{
    "buildCustomMessage": true,
    "customMessageTemplate": "{\"status\": \"ok\"}",
    "customMessageContentType": "application/json",
    "deploy": true,
    "deployTargetEnvironmentNameList": ["production"]
  }'
```

## Notes and Warnings

* **Custom Message Mode**: When `buildCustomMessage=true`, the gateway returns the custom response template instead of routing to backend
* **Template Variables**: The template supports Apinizer variables (e.g., `${request_httpMethod}`, `${request_uri}`) that are resolved at runtime
* **Content Type**: Set `customMessageContentType` to match your template format (e.g., `application/json`, `application/xml`, `text/plain`)
* **HTTP Status Code**: The `customMessageHttpStatusCode` overrides the default 200 status code
* **Use Cases**: Health check endpoints, mock responses, maintenance responses, API versioning redirects
* **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 Error Handling](/api-reference/api-proxies/settings/update-error-handling) - Configure error handling strategy
* [Update Maintenance Mode](/api-reference/api-proxies/settings/update-maintenance-mode) - Configure maintenance mode
* [Update Routing Status](/api-reference/api-proxies/settings/update-routing-status) - Enable/disable routing
