Return code of an API

Hi,
If I am using an API call in a server action, how do I check whether the API returned successfully or failed?

Many thanks!

If you check the Pass Errors option then the action will stop and return the error. If you don’t check the option then you can handle the response yourself, the API step returns the status, headers and data. You can check the HTTP status if it was successfully, status 200-299 is normally successful, 400-499 are warnings and 500-599 are errors.

1 Like

Thank you Patrick, but how exactly do I check that status?

Isn’t your api returning the status, when you call it? You can see the status and headers when you fetch the API schema - so use the status which is returned there.

That was the missing link!
I had not fetched the API schema and thus did not have access to the returned values in subsequent steps. Done it now.
Many thanks!

Alex

1 Like

Actually, through trial and error, I just discovered that I can access the status returned by the api by using the expression {{my_api_name.status}}

This may be a well known fact to most people but I certainly was not aware of it.

The fetched API schema did not bring this variable - though I realize that this would be dependent of what the api provider provides.

If indeed {{api.status}} always means the result of an api, it may be worth documenting it somewhere.

Also, many thanks to @patrick and @teodor for your quick responses! You can’t imagine how valuable they are for a non-programmer trying to punch above his weight :slight_smile:

Alex