Access data from actions, API requests and set up environment variables.

variables-getting-started-header

Accessing data

In Fastgen, each action block has a predefined data structure that specifies the format and structure of the data that the action block generates. This data structure can be found in the documentation for each action.

To access the outputs generated by other action blocks, Fastgen provides different options:

From actions

If you want to access data from any other action block, regardless of whether it’s the previous one or not, you can use the following syntax: {{$action.action-name}}, where “action-name” is the name of the action block you want to access the outputs from. For example, if you want to access the outputs of an action block named “Send Email”, you can use {{$action.send-email}}.

One exception are variables you define within the Variable Action. To access a defined variable you use {{$var.action-name}}. So if you define a variable in a variable action block and name it “Follow up link”, you can access it using {{$var.follow-up-link}}.

Note how the action key within the variable is the lowercase form of the action name, with all spaces and special characters replaced by hyphens -

This syntax allows you to access data generated by any action block in your workflow.

From API requests (API-Builder only)

If you want to access data from requests to the API itself, such as the request body, header, query params, etc., you can use the {{$body.KEY}}, {{$query.KEY}}, {{$path.KEY}}, {{$user.KEY}} and {{$header.KEY}} syntax, where “KEY” is the relevant and case-sensitive key in the request’s data structure. For example, to access the “name” field from the request body, users can use {{$body.name}}.

Using these variable syntaxes, you can easily access data generated by other action blocks and use it in subsequent action blocks in your workflow. This feature allows for a high degree of flexibility and control over the data flow within your workflows.

From events (Event workflows only)

If you create an Event based workflow and want to access data from the API/workflow which emitted the event, you can store parameters within the JSON of the Create Event and then access it through {{$param.KEY}}.

Indexing variables

One crucial feature of variables is their ability to support indexing, which allows you to access specific elements within a given list.

To index a variable, you can use the following syntax: {{$variableName[index]}}. For example, if the request body has the key myList, which is an array of values, you can access the third element of the array like this: {{$body.myList[2]}}.

It’s important to note that indexing in programming is typically zero-indexed, which means that the first element in an array has an index of 0, the second element has an index of 1, and so on

In addition to indexing a variable directly, you can also index it through other variables. Sticking with the previous example, you can use {{$body.myList[$query.myIndex]}} to use the number from the query parameter myIndex to get that specific item from myList.

Lastly, it’s worth noting that indexes can also be negative. In this case, -1 represents the last element in an array, -2 represents the second-to-last element, and so on. Accessing the last element would then look like this: {{$body.myList[-1]}}.

Setting fallback values

In Fastgen, you can define fallback values for variables to ensure that a default value is used if the variable is not set or does not have a value. Fallback values provide a way to handle instances where the desired value is not available or cannot be retrieved.

To define a fallback value for a variable, you can use the following syntax: {{$action.action-name, fallback="Fallback value"}} or {{$action.action-name, fallback=3.14}} if the value is a number. This syntax is used when defining the variable in the action block itself.

You can also set a fallback value by clicking on any variable and using the fallback value input modal.

Video Guide