> ## Documentation Index
> Fetch the complete documentation index at: https://docs.fastgen.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Event-based

**Run workflows when pre-defined events occur.**

<img src="https://mintcdn.com/organa/x4VcIWGQE6pfuZkY/images/event-workflows-getting-started-header.webp?fit=max&auto=format&n=x4VcIWGQE6pfuZkY&q=85&s=b964d0887df858decf2bb0ba507883ca" alt="event-workflows-getting-started-header" width="1476" height="596" data-path="images/event-workflows-getting-started-header.webp" />

## Overview

Event-based workflows will listen to events you create through the [Create Event Action](/actions/native-action/create-event) in other APIs or workflows and will be executed if these events are emitted. Each event based workflow can listen to one unique event, while multiple different workflows can listen to the same event.

These workflows are an excellent way to modularize your backend processes which will grant you more efficiency when making changes.

## Let's build an event based workflow

<Steps>
  <Step title="Create an event">
    Let’s imagine we have an API endpoint which is called every time a new order is submitted. It will create an invoice, update our warehouse stock and execute a database query to check if the supply of the sold unit is still larger than 50.

    Now, if an order is processed and the stock of that product (SKU) drops below the 50 threshold, we are using the [Create Event Action](/actions/native-action/create-event) to emit an event as we want to handle the reorder process with our supplier in a separate, event-based workflow.

    <img width="250" height="250" src="https://mintcdn.com/organa/x4VcIWGQE6pfuZkY/images/create-event-example.webp?fit=max&auto=format&n=x4VcIWGQE6pfuZkY&q=85&s=3a8bd9afd17ee16338041afc7f5da812" data-path="images/create-event-example.webp" />

    We call the event `sku_reorder` and will store the ID of the SKU of the order `{{$body.sku.id}}` as a parameter. We receive the SKU ID from the body sent to this endpoint and will be able to pass it to our event-based workflow to re-use it there.
  </Step>

  <Step title="Create event based workflow">
    Navigate to *Workflows* on the left side bar, click *Add workflow* and choose `Event`.

    The <Tooltip tip="This is the first action block of every event workflow">Top Action</Tooltip> lets you specify a name, description and most importantly to which unique event it listens to. The toggle lets you activate and deactivate the workflow. If a workflow is not toggled as active, it won't execute.

    <img width="250" height="250" src="https://mintcdn.com/organa/x4VcIWGQE6pfuZkY/images/event-workflow-top-action.webp?fit=max&auto=format&n=x4VcIWGQE6pfuZkY&q=85&s=469ee8eb47e7da15cf0538ab0c1f825a" data-path="images/event-workflow-top-action.webp" />

    Now we can build our supply reorder process and will be able to access the SKU ID at `{{$param.sku}}`.
  </Step>

  <Step title="Debug">
    Similarly to the API Builder, you are able to use the [Debug Mode](/developer-tools/debug) to directly test and debug your workflow. In the top right you can modify the JSON parameters.
  </Step>

  <Step title="Deploy">
    Deploy your workflow with one click and it will instantly be live and hosted.
  </Step>
</Steps>

## Video Guide

### Feature Overview

<iframe
  width="674"
  height="315"
  src="https://www.youtube.com/embed/sQBjQkaJw-U?si=2b-_otDap8qgSoDe"
  title="YouTube video player"
  frameborder="0"
  allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; 
picture-in-picture; web-share"
  allowfullscreen
/>

### University Guide

<iframe width="674" height="315" src="https://www.youtube.com/embed/Hc1CYJDEDQw" title="YouTube video player" frameborder="0" allow="accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture; web-share" allowfullscreen />
