Error 204 (No Content) API response

I have an API that can response with 200 or with 204 depending if I have data of an endpoint or not. when the API respond 200 the data action works perfect, but when the API respond 204 I can't do that data action works.

Configuration Response:

{
  "translationMap": {
    "string": "$.data"
  },
  "translationMapDefaults": {
    "string": "\"error\""
  },
  "successTemplate": "{\n \"string\": ${string} \n }"
}

If I use the default configuration response...

{
  "translationMap": {},
  "translationMapDefaults": {},
  "successTemplate": "${rawResult}"
}

...Data action test works, and in the step 9 (Resolve translation map), I can see that rawResults is null (204 No Content)

{
 "rawResult": "null"
}

Is there any way I can get a default value from a data action when the API response is 204 and the body is empty (null), but keeping the result I get with the API response being 200?

I have tried velocity too, but when the body of the response is empty and I use "translationMap" or "translationMapDefaults" the data action fails.

Hi Javier,
I reproduced your example and I do not know of any way to work around it in a single action.

One possible work around, depending on how your API behaves is to have 2 data actions. The first one will handle 200 responses and the second one will handle 204 responses. If the 200 data action fails call the 204 data action.

If that idea doesn't work for you go ahead and open up a ticket with customer care. This is in the gray area of "Bug or feature?" so I can't promise that it will be changed, but it will get us to take a closer look at what it would take to handle this scenario.

--Jason

Thanks Jason,
I've already opened a case with Care (0002770842).
Making two requests helps us now but it is not the solution, the service we call is heavy and making 2 calls to obtain the data means having the client in silence for 3-4 seconds.

This topic was automatically closed 31 days after the last reply. New replies are no longer allowed.