How to Handle an External API Call Error in Workflows
Tags: nocode, okta, oktaworkflows, automation
Published: 2022-08-16 23:13:27

---
title: How to Handle an External API Call Error in Workflows
published: true
date: 2022-08-16 05:26:09 UTC
tags: nocode, okta, oktaworkflows, automation
canonical_url: https://maxkatz.net/2022/04/29/how-to-handle-an-external-api-call-error-in-workflows/
series: Okta Workflows How-To Guide
---

The [Okta Workflows](https://www.okta.com/platform/workflows/) team holds weekly community [office hours](https://calendly.com/oktaworkflows/group-office-hours-okta-workflows) where you can ask questions about workflows, uses cases, and share what you are working on.

{% embed https://dev.to/oktaworkflows/all-okta-workflows-how-to-guides-4nl9 %}

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](https://katzmax.files.wordpress.com/2022/04/workflows_officehours_trycatch2.png?w=1024)](https://katzmax.files.wordpress.com/2022/04/workflows_officehours_trycatch2.png)
<figcaption>If Error card – success section</figcaption>

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](https://katzmax.files.wordpress.com/2022/04/workflows_officehours_trycatch3.png?w=1024)](https://katzmax.files.wordpress.com/2022/04/workflows_officehours_trycatch3.png)
<figcaption>If Error card – error section</figcaption>

> **Tip** : Learn how to [create outputs](https://dev.to/maxkatz/workflows-tips-18-access-all-user-properties-output-for-ifelse-condition-and-partial-user-update-371g-temp-slug-9813454) 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](https://katzmax.files.wordpress.com/2022/04/workfows_officehours_trycatch4.png?w=1024)](https://katzmax.files.wordpress.com/2022/04/workfows_officehours_trycatch4.png)<figcaption>Success outcome</figcaption>

Now you can test the flow. The flow uses a service called [mock.codes](https://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](https://mock.codes/200)) that results in success:

[![Success outcome](https://katzmax.files.wordpress.com/2022/04/workflows_officehours_trycatch5.png?w=1024)](https://katzmax.files.wordpress.com/2022/04/workflows_officehours_trycatch5.png)
<figcaption>Success outcome</figcaption>

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

[![Error outcome](https://katzmax.files.wordpress.com/2022/04/workflows_officehours_trycatch6.png?w=1024)](https://katzmax.files.wordpress.com/2022/04/workflows_officehours_trycatch6.png)
<figcaption>Error outcome</figcaption>

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

[![Flow chart](https://katzmax.files.wordpress.com/2022/04/workflows_officehours_trycatch7.png?w=1024)](https://katzmax.files.wordpress.com/2022/04/workflows_officehours_trycatch7.png)
<figcaption>Flow chart</figcaption>

* * *

Have a question about Okta Workflows? Not sure how to build a flow? Join the weekly community [office hours](https://calendly.com/oktaworkflows/group-office-hours-okta-workflows) to get help.