The API I am calling correctly returns a 200 in the status code but in the back end the only field that is available in the workflow is returned_an_error being “no”. Despite 200 coming back from the API.
The assumption here is that the ONLY non-error status code is 200?
Exactly. A 20x response is technically not an error. But some API will return 200 but have a payload for error. What you need to do is to merge the good payload with the error payload and enter it manually. Use conditionnal to detect error message. In this case, using continue workflow doesn’t matter because the API doesn’t return an error code le 40X or 50x.
I don’t agree. But I don’t understand what you mean by
When you initilize the API, you have the response. But in this case, you need to enter the response manually by merging this response and the error payload.
Let’s say you have a good response:
If there is an error then the workflow will continue and you can use the status_code in the flow.
However, despite the fact that the raw response has status_code 200 when you get this into the workflow Bubble ignores the status code and just gives you returned)an_error = no.
I don’t beleive this is correct, as there are multiple 2xx responses that are “not an error” and using the built-in Bubble function for this purpose means you can’t tell what the actual return code is - you just know it isn’t an error.
I didn’t answer @NigelG but there’s two case here
A) API return 200, but with an error message payload
B) API Doesn’t return 200
In A) case, you need to create a merge of the API response + API error response to be able to use it. Bubble will not return true for return an error
in B) case, you need to use detect header and include error in response. Bubble will return true if there’s an error (a code that is not 200)
My problem is that I not only have to watch for an error, but also take 2 different actions depending on whether code 201 or 202 is involved, and I can only retrieve the status_error_code when code 400 is involved.
Unfortunately, the api doc is private and specific to our company.
To explain the WF, I only want to validate the identified bike action when the api returns 201, because if the api returns 202 it means that the unique code has already been used.
Because I don’t have access to API Doc, this is hard to help.
For example, are both returning the same payload? If not, you can use this to know if this was a created or accepted code. Do payload return created date? you could use this to know if this was just created or if this already exist. Often, 201-202 will not return any payload. If this is the case, I guess that once item is created, you may have a GET endpoint to get this item. Maybe before your request, you could fetch the GET endpoint with the unique code, if this return an error (so doesn’t exist), continue with action (create), if this already exist, do something else (accepted).
Don’t hesitate to create a new ideaboard for this request (add status code when “detect header” and “include error” is enable, not just for error status code)
Indeed, the payload is empty when it’s 201 or 202 and the unique code to identify the bike is only verifiable during the post_bike that I do. And why is it that in the api’s manual response, we can see the status_code, and it’s not possible to retrieve it afterward?
This is not an actual feature sadly. This is why I suggest to make a request on ideaboard. You can try to contact support. This could be something that can be added easily on their side.
The last option that I could see, is to make your own plugin with a server side action. Because you don’t have any payload returned, it’s an easy thing to set and you will just return 1 field with the status code.