Ana içeriğe geç

Update JSON Error Response Template

Endpoint

PATCH /apiops/projects/{projectName}/apiProxies/{apiProxyName}/settings/json-error-template/

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

{
"jsonErrorResponseTemplate": {
"jsonErrorResponseTemplateActive": true,
"jsonValue": "{\n \"fault\": {\n \"correlationId\": \"#CORRELATIONID#\",\n \"faultCode\": \"#FAULTCODE#\",\n \"faultString\": \"#FAULTMESSAGE#\",\n \"faultStatusCode\": \"#FAULTSTATUSCODE#\",\n \"responseFromApi\": \"#RESPONSEFROMAPI#\"\n }\n}",
"contentType": "application/json;charset=UTF-8",
"permitSpecialChars": false
},
"deploy": false,
"deployTargetEnvironmentNameList": []
}

Request Body Fields

FieldTypeRequiredDefaultDescription
jsonErrorResponseTemplateobjectYes-JSON error template object (see fields below)
deploybooleanNofalseIf true, deploy the API proxy after saving changes
deployTargetEnvironmentNameListarray[string]No-List of environment names to deploy to (required when deploy=true)

jsonErrorResponseTemplate Fields

FieldTypeRequiredDefaultDescription
jsonErrorResponseTemplateActivebooleanNofalseEnable/disable JSON error template
jsonValuestringNo-JSON error response template
contentTypestringNoapplication/json;charset=UTF-8Content type for error response
permitSpecialCharsbooleanNofalsePermit special characters in template

Template Variables

The JSON template can use the following variables (replaced at runtime):

  • #CORRELATIONID# - Request correlation ID
  • #FAULTCODE# - Error fault code
  • #FAULTMESSAGE# - Error fault message
  • #FAULTSTATUSCODE# - HTTP status code
  • #RESPONSEFROMAPI# - Response from backend API (if available)

Default Template

{
"fault": {
"correlationId": "#CORRELATIONID#",
"faultCode": "#FAULTCODE#",
"faultString": "#FAULTMESSAGE#",
"faultStatusCode": "#FAULTSTATUSCODE#",
"responseFromApi": "#RESPONSEFROMAPI#"
}
}

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

Response

Success Response (200 OK)

{
"success": true
}

Response Fields

FieldTypeDescription
successbooleanIndicates if the request was successful

When deploy=true is specified:

{
"success": true,
"deploymentResult": {
"success": true,
"deploymentResults": [
{
"environmentName": "production",
"success": true,
"message": "Deployment successful"
}
]
}
}
FieldTypeDescription
deploymentResultobjectDeployment result (present when deploy=true)
deploymentResult.successbooleanOverall deployment success status
deploymentResult.deploymentResultsarrayPer-environment deployment results

Error Response (400 Bad Request)

{
"error": "bad_request",
"error_description": "Invalid JSON template"
}

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 JSON Error Template

curl -X PATCH \
"https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAPI/settings/json-error-template/" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"jsonErrorResponseTemplate": {
"jsonErrorResponseTemplateActive": true,
"jsonValue": "{\n \"fault\": {\n \"correlationId\": \"#CORRELATIONID#\",\n \"faultCode\": \"#FAULTCODE#\",\n \"faultString\": \"#FAULTMESSAGE#\",\n \"faultStatusCode\": \"#FAULTSTATUSCODE#\"\n }\n}",
"contentType": "application/json;charset=UTF-8"
}
}'

Example 2: Custom JSON Error Template

curl -X PATCH \
"https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAPI/settings/json-error-template/" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"jsonErrorResponseTemplate": {
"jsonErrorResponseTemplateActive": true,
"jsonValue": "{\n \"error\": {\n \"id\": \"#CORRELATIONID#\",\n \"code\": \"#FAULTCODE#\",\n \"message\": \"#FAULTMESSAGE#\",\n \"status\": #FAULTSTATUSCODE#\n }\n}",
"contentType": "application/json;charset=UTF-8",
"permitSpecialChars": true
}
}'

Example 3: Save and Deploy

curl -X PATCH \
"https://demo.apinizer.com/apiops/projects/MyProject/apiProxies/MyAPI/settings/json-error-template/" \
-H "Authorization: Bearer YOUR_TOKEN" \
-H "Content-Type: application/json" \
-d '{
"jsonErrorResponseTemplate": {
"jsonErrorResponseTemplateActive": true,
"jsonValue": "{\n \"fault\": {\n \"correlationId\": \"#CORRELATIONID#\",\n \"faultCode\": \"#FAULTCODE#\",\n \"faultString\": \"#FAULTMESSAGE#\",\n \"faultStatusCode\": \"#FAULTSTATUSCODE#\"\n }\n}",
"contentType": "application/json;charset=UTF-8"
},
"deploy": true,
"deployTargetEnvironmentNameList": ["production"]
}'

Notes and Warnings

  • Template Variables: Use #VARIABLE# syntax for runtime replacement
  • JSON Format: Template must be valid JSON (use escaped quotes in string)
  • Content Type: Default is application/json;charset=UTF-8
  • Special Characters: When permitSpecialChars=true, special characters are not escaped
  • Active Flag: Set jsonErrorResponseTemplateActive=true to enable template
  • REST APIs: Primarily used for REST/JSON APIs
  • 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.