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

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 holds the error message. The message is then mapped to If Error card’s output.

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.

Sending success or error message to Compose card

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

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

Error outcome

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

If-error flow chart

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

Published by

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.