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

# How to create a Workflow

> Configure a workflow in Invopop to process documents.

Although workflows can be created via the API, we strongly recommend using the [Invopop Console](https://console.invopop.com) for an easier set up.

In the **Workflows** section click on **+ Create workflow**. You will see a template selection screen. The first two items are blank workflows for each document type:

<img src="https://mintcdn.com/invopop/gppDYSnFxKXpVvfp/assets/guides/workflow-template-empty.png?fit=max&auto=format&n=gppDYSnFxKXpVvfp&q=85&s=16d2558750ad5f0e36850e18b9fed24d" width="100%" alt="Parts of a workflow" className="rounded-lg" data-path="assets/guides/workflow-template-empty.png" />

* **Empty Invoice workflow**: for sales or expenses.
* **Empty Party workflow**: for suppliers or customers.

Choose [Empty Invoice workflow](https://console.invopop.com/redirect/workflows/new?template=empty-invoice) for this example and then click **Load Template**.

Give your workflow a name and description by filling the fields on the right sidebar.

Add steps to your new workflow by tapping on the **+ Add step** button and selecting an action from the right. Some steps will require configuration in order to function correctly.

The "developer mode" <img src="https://mintcdn.com/invopop/gj0LtB6xhc-5_Lcq/assets/guides/workflow-switcher.png?fit=max&auto=format&n=gj0LtB6xhc-5_Lcq&q=85&s=16f39a7bca8b93c60e0e3a42bbf1136a" alt="Developer mode switch" className="inline-block m-0 w-14" width="112" height="60" data-path="assets/guides/workflow-switcher.png" /> switch at the top right of the canvas can be used to display the JSON representation of the workflow. This makes it easy to copy and paste workflows from examples or other workspaces. Make sure to return to the visual editor view to ensure the document is validated.

## Creating conditions

Conditions create blocks that execute when a given *status* and *code* (optional) match the response of a workflow step. There are two status signals (`OK` and `KO`) plus `Any`, which matches regardless of the status.

* **OK**: when a workflow step completes as expected.
* **KO**: when there was an error in the step's execution.
* **Any**: will match both `OK` and `KO`.

Codes are generally text or numbers returned by providers. Only some steps will return codes along with their status signals. For example, the *Send VERI\*FACTU (Spain)* step will return the error code as [specified by the AEAT](https://prewww2.aeat.es/static_files/common/internet/dep/aplicaciones/es/aeat/tikeV1.0/cont/ws/errores.properties) along with the `KO` status signal. Since GOBL already handles many of the validations in tax authorities lists, we recommend only implementing conditions which happen in your workflow with certain regularity and which should be handled automatically.

As an example, we will handle the case where a supplier is not registered in the taxpayer census by the AEAT:

<Steps>
  <Step title="Add a condition on the step">
    On the desired step, click on the menu button `...` and select **Add condition**.

    <Frame>
      <img src="https://mintcdn.com/invopop/gppDYSnFxKXpVvfp/assets/guides/workflow-add-condition.png?fit=max&auto=format&n=gppDYSnFxKXpVvfp&q=85&s=63fcf8884e4f75550fa05a70c43416e9" width="100%" alt="Add condition" noZoom data-path="assets/guides/workflow-add-condition.png" />
    </Frame>
  </Step>

  <Step title="Configure the condition">
    <Frame>
      <img src="https://mintcdn.com/invopop/gppDYSnFxKXpVvfp/assets/guides/workflow-add-condition-match.png?fit=max&auto=format&n=gppDYSnFxKXpVvfp&q=85&s=541ad082b478643dbace2929512414f4" width="100%" alt="Add match conditions" noZoom data-path="assets/guides/workflow-add-condition-match.png" />
    </Frame>

    Configure the matching conditions in the popover:

    1. **Status**: `KO`.
    2. **Code**: `4107` (Tax ID not identified in the taxpayer census).
    3. **End workflow here**: `✔` (the workflow will stop executing after this block).
  </Step>

  <Step title="Add an action to the condition block">
    <Frame>
      <img src="https://mintcdn.com/invopop/gppDYSnFxKXpVvfp/assets/guides/workflow-add-condition-action.png?fit=max&auto=format&n=gppDYSnFxKXpVvfp&q=85&s=f4d4253fadab0e42c4a831d44fd7bacc" width="100%" alt="Add condition action" noZoom data-path="assets/guides/workflow-add-condition-action.png" />
    </Frame>

    Click on "Select an action" and handle the condition as you wish. In this case, we are choosing to send a Slack message (e.g. for manual intervention).
  </Step>
</Steps>

## Running a workflow

Workflows in Invopop can be executed through the following methods:

* Manually via the Invopop Console
* Via API calls to the [create job endpoint](/api-ref/transform/jobs/create-a-job-put)
* Automatically by an embedded application.

Workflows are executed on *silo entries* (such as invoices or suppliers), this action creates a *job*. When a job is run, the silo entry will be updated with any changes or attachments generated during processing. The status of a job can be seen in the silo entry's activity tab, or in the **Workflows** → **History** section accessible from the left sidebar.

## Error handling

Any step that causes an error (`KO`) from which the job can't recover, and is not handled through a condition,  will trigger the error handling flow. To enable this section, tap on <kbd>Handle Errors</kbd> at the bottom of the workflow creation screen, then add steps into this area which you want to execute when the job fails (often times setting the entry's state to `Error` and possibly sending a notification).

## FAQ

<AccordionGroup>
  <Accordion title="How do I update deprecated workflow steps?">
    If your step conditions display a **This step contains deprecated conditions** warning, your workflow will continue working normally, but we recommend updating your workflow so that you can modify it without unexpected behavior.

    Steps under deprecated conditions will display with a warning symbol ⚠️ with the label "Go to \[action name]". Click on the menu button `...` and select "Replace", and then select the replacement action from the sidebar. So, for example, if the deprecated step is labelled "Go to Set state", replace this step with "Set state" and choose the same configuration as the original step (which you should find further down within the same workflow).

    Once all deprecated steps are replaced, locate the referenced action(s) and delete.
  </Accordion>
</AccordionGroup>

## Related resources

|                |                                                                                                                                                                                                                                                                                                                                                                                |
| -------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
| API Reference  | <Icon icon="code" /> [Create a workflow](/api-ref/transform/workflows/create-a-workflow)<br /><Icon icon="code" /> [Fetch all workflows](/api-ref/transform/workflows/fetch-all-workflows)<br /><Icon icon="code" /> [Create a job (POST)](/api-ref/transform/jobs/create-a-job-post)<br /><Icon icon="code" /> [Create a job (PUT)](/api-ref/transform/jobs/create-a-job-put) |
| Related Guides | <Icon icon="book" /> [Workflows Guide](/guides/workflows)                                                                                                                                                                                                                                                                                                                      |
