Debug your API

Debug your API

Technical errors

Sometimes your API endpoint does not behave the way you expect. If the call results in an error you will get a link to more detailed information in your error response.

Example:

500 Internal Server Error

...               # headers omitted for readability

{
   "error": "https://api.zuunr.com/errors/123abc
}

GET that resource and include authorization header

GET https://api.zuunr.com/errors/123abc

authorization: {{SANDBOX_AUTH}}
200 OK

{
  "error": {
    "message": "must be string",
    "location": "/processors/onRequest/Translator/transformations/~1response/body/hello/$concat/0/$concat/0"
  }
}

Let’s have a look at what that means.

location is where your endpoint-config JSON is failing. In this case it is processor onRequest that fails when using component Translator to set field "/response" (‘/’ are escaped as ‘~1’). The error is happening inside the JSON template

{"body":{"hello":{"$contact":[A, ...]}}}

at index 0 (A in the example above ).

message is an explanation of what is failing at that location, i.e why index 0 is failing. In this example because it is not a string.

If you get an error message you cannot understand – please reach out to me – I’ll be happy to help 🙂

Debugging unintended behavior

When you do not get an error but the endpoint still does not behave as you expect, you can debug one specific API endpoint by providing two extra headers in the API request.

Example:

GET /examples/hello-world

trace: true                 # turn on debugging
authorization: {{SANDBOX_AUTH}} # show that you are allowed to turn on debugging

This will result in a response like

200 OK

trace-id: example~1hello-world     # use this id!

{
  "hello": "world"
}

use the trace-id above and you will get something like

200 OK

{
  "preExecutionProcessorModels": [
    {
      "onRequest": {
        "request": ...
      }
    },
    {
      "sendResponse": {
        "request": ...
        "response": ...
      }
    }
  ]
}

preExecutionProcessorModels contains an array of objects where each object contains has the processor name as key and the processor model as it was before the specific processor was started. The array is ordered the same way as the execution of processors performed.

Investigate the models and change your endpoint config until the endpoint works the way you want.