Articles in this section

Route requests with branching and the Response picker

In API builder, you can add branching to route request data down different paths, run different logic in each path, and return a response from each. This lets you build one API instead of several. API builder also adds a branching of its own, the Response picker, to every API response step. This article shows you how to add a branching to an API and explains how the Response picker works. API builder supports only the First matching branch type.

Every branch in an API must end in an API response. If a branch has no response, or the response isn't configured, the API returns 501 - Not Implemented. For other API errors, see Error handling in API builder.

Prerequisites: Manage permission, Administrator role, or account owner — You must have the Manage permission on the integration, the Administrator role on the account, or own the account. For details, see Manage user roles & permissions to an account.

Add a branching

  1. Go to Build Build icon or Resources Resources icon, and then select APIs. Select + Create API to create an API, or select your API to open it.
  2. Select the plus sign (+) next to a step, and then select Add branching.
  3. In Branching name, enter a name that describes what the branching does in the API, such as "Get an order" or "Update an order." Long names are truncated on the canvas; hover over the branching to see the full name.
  4. Keep First matching branch selected under Branching type. It's the only option. For how it works, see Branching overview.
  5. Under Define branch rules, select the name of each default branch, Branch X.0 and Branch X.1, to rename it.
  6. To add a description, select the Actions elipses-button.png menu for the branch.
  7. To add another branch, select + Branch. You can add up to 25 branches to a branching and up to 25 branchings to an API. You can also reorder branches and delete any branch except the first.
  8. Configure the conditions for each branch. For steps, see Configure branch conditions.
  9. Select Preview to check the results.
    • Input shows the request data that enters the branching.
    • Output shows the index and name of the first matching branch.
  10. Select Save & close.

The branching router icon appears on the canvas. Select it to edit the branching.

Response picker

The Response picker is a branching router that API builder adds automatically to every API response step. It routes each request to the response that matches the outcome, so your API can return different response codes and bodies for success, errors, and other cases.

The Response picker has two branches by default, each ending in a response node:

  • Success response runs when the success flag is true.
  • Error response runs when the success flag is false.

The API backend sets success to indicate whether the API succeeded. You can't edit the flag, but you can change a branch's conditions to route on other criteria, such as a specific error or a test mode response. Using the flag is recommended but not required.

To open the Response picker, select its router icon, which shows the tooltip Edit branching - Response picker.

To return more kinds of responses, select + Branch. Each new branch adds a response node, which has a blank name until you enter one.

Response picker rules

  • The Response picker is added automatically, and you can't rename it or delete it.
  • The Response picker always has two branches that lead to Success response and Error response nodes. You can't remove them, and the Delete branch option is unavailable on both branches.
  • You can rename the Success response and Error response branches.
  • Each branch you add creates a response node.
  • Branches are checked in order, and a request flows through only the first branch it matches.

For a complete API with a success response and error responses for a bad request, an unauthorized token, and a conflict, see API builder examples.