DEV Community

Max Katz for Okta Workflows

Posted on • Originally published at maxkatz.net on

How to Handle an External API Call Error in Workflows

The Okta Workflows team holds weekly community office hours where you can ask questions about workflows, uses cases, and share what you are working on.

I’m publishing some of questions and answers from the office hours as I believe they are extremely valuable how-to’s.

On to the question.

How to handle an external API call error in Workflows?

When calling an external API results in an error you want to gracefully handle the error and continue the flow execution. One way to handle an error is to use Error Handling – If Error card. It’s similar to try/catch logic.

The card has two sections Try and If Error.

In the Try section you place the API Connector card followed by any other logic. In this example there is a single Assign card to create a success message. You can add other cards as well. The message is then mapped to If Error card’s output.

If Error card – success section

If Error card – success section

In the If/Else section there is a default error message followed by any other logic. In this example it’s again a single Assign card which olds the error message. The message is then mapped to If Error card’s output.

If Error card – error section

If Error card – error section

Tip : Learn how to create outputs for an If/Else card.

After the If Error card you can add additional logic. Here is an example of sending a success or an error message to a Compose card:

Success outcome
Success outcome

Now you can test the flow. The flow uses a service called mock.codes. mock.codes provides for an easy way to reference and test HTTP responses.

Running the flow with HTTP response 200 (https://mock.codes/200) that results in success:

Success outcome

Success outcome

Running the flow with HTTP response 500 (https://mock.codes/500) that results in Internal Server Error:

Error outcome

Error outcome

The flow chart can help visualize the flow logic at a high-level:

Flow chart

Flow chart

Have a question about Okta Workflows? Not sure how to build a flow? Join the weekly community office hours to get help.

Top comments (0)