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

Partial update

Only the fields present in jsonErrorResponseTemplate are applied. An omitted field (or one sent as null) keeps its stored value, so a call that changes one setting never resets the others — a customised jsonValue survives a call that only flips jsonErrorResponseTemplateActive. The Default column below is what a newly created template starts with, not what an omitted field falls back to on update. An explicit false or an empty string is applied as sent. Unrecognised fields are ignored, so a client that reads the object and posts the whole thing back keeps working unchanged.

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 the fields you send are updated; every field you leave out keeps its stored value.

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)

{
"status": "FAILURE",
"resultMessage": "Invalid JSON template"
}

Error Response (401 Unauthorized)

{
"status": "FAILURE",
"resultMessage": "Token is not valid!"
}

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

Example 4: Change One Field (Partial Update)

Only the field in the body is written. The stored jsonValue, permitSpecialChars and jsonErrorResponseTemplateActive are left exactly as they were.

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": {
"contentType": "application/problem+json;charset=UTF-8"
}
}'

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.