---
title: Use variables in a flow
url: https://docs.triply.cc/how-to/use-variables-in-a-flow/
description: 'Make a flow reusable with variables: define them, use them in task fields and queries, keep
  credentials in masked values, and save sets of values as presets.'
availability:
- 'Private preview: This feature is switched on per instance, by arrangement. Get in touch if you would
  like access.'
---

# Use variables in a flow

This page covers giving a flow values that change from run to run — a file URL, a dataset name,
an API key. For what variables are and why, see [Variables](https://docs.triply.cc/concepts/flows/#variables); for
their properties and where a run's values come from, the
[Flows reference](https://docs.triply.cc/reference/flows/#variables).

## Define a variable

1. In the flow builder, open the **Variables** tab of the **Flow elements** panel.
2. Click **New variable**.
3. Enter a **Name** — for example `dataset`. Names starting with `system_` are reserved.
4. Optionally add a **Description**, shown to whoever runs the flow.
5. Leave **Required** on if a run cannot do without a value.
6. To limit the values a run may give it, click **Add option** under **Allowed options** for each
   one. The run dialog then offers a list instead of a text field.
7. Click **Save**, then **Save** the flow.

The system variables, such as `system_triggererAccountName` and `system_triplyToken`, are listed
under **System variables**; they need no defining. A run started by a hook also gets variables
describing the upload; see [System variables](https://docs.triply.cc/reference/flows/#system-variables).

## Use a variable in a task

- **For a whole field:** click **$** beside the field and pick the variable, or
  **Create a new variable** to define one on the spot. This works for the fields in a task's
  settings and for the account, dataset and graph names of its inputs and outputs.
- **Inside text:** in an email subject or body, a request's headers or body, or a **Stop run**
  message, write `?dataset` wherever the value should go: `Imported ?dataset`.
- **In an inline SPARQL query:** use a query variable with the same name. In
  `select * { ?s ?p ?dataset }`, `?dataset` is replaced by the flow variable's value, as a string
  literal.
- **In a saved query:** give its API variables a value under **Query variables**, choosing the
  flow variable.

## Set a variable from a query

1. Add a **Set variables** task (under **Data processing**) and connect it before the tasks that
   need the value.
2. To query a dataset, connect it as the task's input.
3. Under **Query**, write a SELECT query that selects the variables to set:
   `select ?latest { … } order by desc(?date)`. Only its first row is used.
4. Use `?latest` in the later tasks like any variable. The **Variables** tab lists it under
   **Task output variables**.

See [Set variables](https://docs.triply.cc/reference/flow-tasks/#set-variables) for how the values are converted
and when a flow cannot run.

## Store a credential as a masked value

1. Open **Masked values** in the flow's navigation and click **Add masked value**.
2. Enter a **Name** — `API_KEY`, say — an optional **Description**, and the **Value**.
3. Click **Save**.
4. Use it in a task as `?API_KEY`, like any variable. In an **Import from web** or
   **Send request** task, for example, add a header `Authorization` with the value
   `Bearer ?API_KEY` under **Request headers**.

Only people with the **Manage flow masked variables** permission see and change the value;
everyone who may run the flow can use it.

## Save a set of values as a preset

A flow needs at least one variable first.

1. Open **Presets** in the flow's navigation and click **Add Preset**.
2. Give it a label, fill in the **Variables**, and click **Save**.
3. To have its values filled in whenever someone runs the flow or adds a schedule, switch on
   **Default preset**.

To run a flow with a preset, see [Run a flow](https://docs.triply.cc/how-to/run-a-flow/#run-it-by-hand).
