Ana içeriğe geç

Update Custom Message Settings

Endpoint

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

Authentication

Requires a Personal API Access Token.

Authorization: Bearer YOUR_TOKEN

Request

Headers

HeaderValueRequired
AuthorizationBearer {token}Yes
Content-Typeapplication/jsonYes

Path Parameters

ParameterTypeRequiredDescription
projectNamestringYesProject name
apiProxyNamestringYesAPI Proxy name

Request Body

Full JSON Body Example

{
"buildCustomMessage": true,
"customMessageTemplate": "{\"status\": \"ok\", \"message\": \"Service is running\"}",
"customMessageContentType": "application/json",
"customMessageHttpStatusCode": 200,
"deploy": false,
"deployTargetEnvironmentNameList": []
}

Request Body Fields

FieldTypeRequiredDefaultDescription
buildCustomMessagebooleanNofalseEnable custom response message building
customMessageTemplatestringNo-Response body template (supports variables)
customMessageContentTypestringNo-Content-Type header for the custom response
customMessageHttpStatusCodeintegerNo-HTTP status code for the custom response
deploybooleanNofalseIf true, deploy the API proxy after saving changes
deployTargetEnvironmentNameListarray[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)

{
"success": true
}

When deploy=true is specified:

{
"success": true,
"deploymentResult": {
"success": true,
"deploymentResults": [
{
"environmentName": "production",
"success": true,
"message": "Deployment successful"
}
]
}
}

Response Fields

FieldTypeDescription
successbooleanIndicates if the request was successful
deploymentResultobjectOnly present when deploy=true
deploymentResult.successbooleanOverall deployment success status
deploymentResult.deploymentResultsarrayPer-environment deployment results

Error Response (401 Unauthorized)

{
"error": "unauthorized_client",
"error_description": "Invalid token"
}

Error Response (404 Not Found)

{
"error": "not_found",
"error_description": "ApiProxy (name: MyAPI) was not found!"
}

cURL Example

Example 1: Enable Custom JSON Response

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

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)

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

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.