# Flows

A *flow* is a reusable block of logic that can be called from any [app](https://docs.appfarm.io/reference/apps) in your solution. Flows are used to encapsulate integrations and business logic once, and then reuse them across apps without rebuilding them each time.

Flows can be thought of as functions at the solution level: they accept inputs, run logic, and return results. A single flow can be called from many apps, so any change made to the flow propagates everywhere it is used.

A flow can be used to:

* Encapsulate an integration with an external system, such as Brønnøysund, Google Drive, or Visma, so that the same integration logic is shared across apps.
* Implement shared business logic, such as a customer lookup or a status transition, that would otherwise be duplicated per app.

{% hint style="info" %}
**Server-side execution**\
Flows run on the server. This makes them well-suited for integrations, data aggregations, and any logic that should not run in the browser.
{% endhint %}

{% hint style="info" %}
**Flows and schemas**\
Flows often send and receive data that does not need to be persisted. To support this, flows are paired with [schemas](https://docs.appfarm.io/reference/platform-concepts/schemas), a way to describe external data structures. Schema data can be used directly as input and ouput in actions without first being modelled as an object class.
{% endhint %}

### Actions

A flow consists of one or more [actions](https://docs.appfarm.io/reference/actions). An action is the unit of logic within a flow and works in much the same way as an action in an app or service - it is composed of [action nodes](https://docs.appfarm.io/library/action-nodes) that run in sequence.

### Available action nodes

Flows currently support a subset of the platform's action nodes. Action nodes that are specific to apps, such as navigation nodes, are not available in flows.

The following action nodes are available in flows:

**Data:** [Create Object](https://docs.appfarm.io/library/action-nodes/create-object), [Read Objects](https://docs.appfarm.io/library/action-nodes/read-objects), [Update Object](https://docs.appfarm.io/library/action-nodes/update-object), [Delete Objects](https://docs.appfarm.io/library/action-nodes/delete-objects), [Persist Objects](https://docs.appfarm.io/library/action-nodes/persist-objects)

**Logic:** [While](https://docs.appfarm.io/library/action-nodes/while), [Foreach](https://docs.appfarm.io/library/action-nodes/foreach), [Next Iteration](https://docs.appfarm.io/library/action-nodes/next-iteration), [Exit Loop](https://docs.appfarm.io/library/action-nodes/exit-loop), [Exit Block](https://docs.appfarm.io/library/action-nodes/exit-block), [If](https://docs.appfarm.io/library/action-nodes/if), [Block](https://docs.appfarm.io/library/action-nodes/block), [Catch Exception](https://docs.appfarm.io/library/action-nodes/catch-exception), [Throw Exception](https://docs.appfarm.io/library/action-nodes/throw-exception), [End Execution](https://docs.appfarm.io/library/action-nodes/end-execution), [Sleep](https://docs.appfarm.io/library/action-nodes/sleep)

**Other:** [Run Action](https://docs.appfarm.io/library/action-nodes/run-action), [Run Flow](https://docs.appfarm.io/library/action-nodes/run-flow), [Web Request](https://docs.appfarm.io/library/action-nodes/web-request), [Send Email](https://docs.appfarm.io/library/action-nodes/send-email), [Send SMS](https://docs.appfarm.io/library/action-nodes/send-sms), Create Shortlink, [Update Secret](https://docs.appfarm.io/library/action-nodes/update-secret)

**Debug:** [Log to Console](https://docs.appfarm.io/library/action-nodes/log-to-console)

### Inputs and outputs

An action inside a flow defines the data it accepts as inputs and the data it returns. Inputs are passed when the flow is called, and outputs are returned to the caller once the flow completes.

**Inputs.** Flow inputs are defined using [action params](https://docs.appfarm.io/reference/actions/action-params). Action params on flows can be simple data types, [enumerated types](https://docs.appfarm.io/reference/data-model/enumerated-types), [object class references](https://docs.appfarm.io/reference/data-model/object-classes) and [schemas](https://docs.appfarm.io/reference/platform-concepts/schemas), the latter allowing structured data to be passed into a flow without first modelling it as an object class.

**Outputs.** A Flow returns output through two mechanisms:

* [**Action Variables**](https://docs.appfarm.io/reference/actions/action-variables) hold simple data types, schemas, or references to enumerated types or object classes.
* [**Action data sources**](https://docs.appfarm.io/reference/actions/action-data-sources) hold collections, similar to [runtime-only data sources](https://docs.appfarm.io/reference/apps/data/data-sources) in apps, but scoped to the action rather than the app.

A flow can return any number of action variables and action data sources as part of its output. Once the flow completes, they are available to the calling action in the same way any action variable or data source would be.

### Calling a Flow

Flows are called from an action using the [Run Flow](https://docs.appfarm.io/library/action-nodes/run-flow) action node. Input values are mapped from the calling context — data sources, app variables, or function results — into the flow's input parameters. Once the flow completes, its output action variables are available to subsequent action nodes in the calling action.

Flows can be called from:

* Actions in apps
* Actions in flows

### Secrets

Flows access credentials and other sensitive values through [secrets](https://docs.appfarm.io/reference/security/secrets), the same mechanism used elsewhere in the platform. Store any API keys, tokens, or passwords required by a flow as secrets, and reference them from within the flow's actions.


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.appfarm.io/reference/flows.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
