Update JSON Error Response Template

Overview

Updates JSON error response template for an API proxy. JSON error template defines the format of error responses for REST/JSON APIs.

Endpoint

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

Authentication

Requires a Personal API Access Token.

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

{
  "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
}

Request Body Fields

Field Type Required Default Description
jsonErrorResponseTemplateActive boolean No false Enable/disable JSON error template
jsonValue string No - JSON error response template
contentType string No application/json;charset=UTF-8 Content type for error response
permitSpecialChars boolean No false Permit 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

Field Type Description
success boolean Indicates if the request was successful

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 '{
    "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 '{
    "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
  }'

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
  • Permissions: Requires ROLE_MANAGE_PROXIES permission