Using database steps in Flow Builder
Database steps in Flow Builder allow you to store a piece of data in server-less Databases during one invocation and retrieve it during another, based on a shared key. All stored values can be deleted, too.
In this article:
- Databases 101
- Store value step
- Retrieve value from Database step
- Delete value from Database step
- Public API
Databases 101
Learn all about Databases feature in the following article: Using Databases.
Store value** step**
The Store value step allows you to temporarily store values in a database that's connected to your workspace. A single database has a limited capacity (10 000 entries), so you are able to combine this step with the Delete value from Database step to clean up entries in a given database.
The Store value step configuration requires a couple of things.
A database
Choose the exact database you want to store the value to, as you are able to have more than one. If you'd like to see all your databases, click on View your databases and it will open a separate tab with all of them listed:
If you'd like to make a database on the spot, click on Create new database. It will also open a separate tab, allowing you to do the creation:
A key
You are required to input a key, which is the identifier for the value you’re going to store. This way you can locate it in your database.
A value
You are also required to input a value, which is the content you are going to store in the database. It can be stored:
-
- as a string
- or a JSON formatted object
- example:
Exemple de code
{
"name":"Super",
"surname":"Mario"
}
Both key and value fields accept variables. If a given key already exists, this step will overwrite the value for that key.
If you want to store data for a specific user, make sure that you include a unique reference in the key, such as a phone number or contact ID. This will allow you to retrieve the value for this same user later on.
Retrieve value from Database** step**
The Retrieve value from database step allows you to retrieve values that you've stored in your database.
The step configuration requires a key and a variable name:
- The key must be the same key from the Store value step.
- The variable name is what the value will be stored in.
Read value as JSON
The step offers the option to read the value as JSON. If you've stored a JSON object, then enabling this option will allow you to read out properties on the output variable using the dot notation (e.g. {{outputVariable.property}}).
Failure handling
There is a possibility of a failed status when a record cannot be found or a JSON error occurs. To keep your Flow running smoothly, you can enable branches that will handle it:
Delete value from Database** step**
The Delete value from database step will remove the key/value pair.
This step only requires a key to be configured. As the database where we store your values is limited, you'll want to use this step in your Flow to clean up entries that you no longer need and keep your flow working smoothly.
This step only requires a key to be configured. As the database where we store your values is limited, you'll want to use this step in your Flow to clean up entries that you no longer need and keep your flow working smoothly.
An additional way of keeping your Database clean is making use of the data retention settings of your databases.
Public API
In addition to the Flow Builder steps, we also offer a public API to interact with the database. This can be used to set/retrieve values from external systems as well as to list all key/value pairs. The API consists of the following endpoints:
List all key/value pairs
Exemple de code
curl "https://flows.messagebird.com/databases/database_id/" \\
-H 'Authorization: AccessKey <MESSAGEBIRD_ACCESS_KEY>'
List all Databases
Exemple de code
curl "https://flows.messagebird.com/database-browser/" \\
-H 'Authorization: AccessKey <MESSAGEBIRD_ACCESS_KEY>'
Get a key/value pair
Exemple de code
curl "https://flows.messagebird.com/databases/database_id/<KEY>" \\
-H 'Authorization: AccessKey <MESSAGEBIRD_ACCESS_KEY>'
Set a key/value pair
POST https://flows.messagebird.com/databases/database\_id (put key and value in the JSON body)
Exemple de code
curl -X "POST" "https://flows.messagebird.com/databases/database_id/" \\
-H 'Authorization: AccessKey <MESSAGEBIRD_ACCESS_KEY>' \\
-H 'Content-Type: application/json; charset=utf-8' \\
-d $'{
"key": "<YOUR_KEY>",
"value": "<YOUR_VALUE>"
}'
Delete a key/pair value
Exemple de code
curl -X "DELETE" "https://flows.messagebird.com/databases/database_id/<KEY>" \\
-H 'Authorization: AccessKey <MESSAGEBIRD_ACCESS_KEY>'
Delete multiple key/value pairs
Exemple de code
curl -X "POST" "https://flows.messagebird.com/databases/<database_id>/batch-delete" \\
-H 'Authorization: AccessKey <MESSAGEBIRD_ACCESS_KEY>' \\
-H 'Content-Type: application/json; charset=utf-8' \\
-d $'{
"documentIds": [<YOUR_KEY1>, <YOUR_KEY2>, <YOUR_KEY3>],
}'
Delete all key/value pairs
Exemple de code
curl -X "DELETE" "https://flows.messagebird.com/database-browser/<DATABASE_ID>/delete-all" \\
-H 'Authorization: AccessKey <MESSAGEBIRD_ACCESS_KEY>' \\
Update a key/value pair
Exemple de code
curl -X "PUT" "https://flows.messagebird.com/databases/<DATABASE_ID>/<KEY>" \\
-H 'Authorization: AccessKey <MESSAGEBIRD_ACCESS_KEY>' \\
-H 'Content-Type: application/json; charset=utf-8' \\
-d $'{
"key": "<YOUR_KEY>",
"value": "<YOUR_VALUE>"
}'
Upload multiple key/value pairs
POST https://flows.messagebird.com/databases/<database_id>/upload\
Exemple de code
curl -X "POST" "https://flows.messagebird.com/databases/<database_id>/upload" \\
-H 'Authorization: AccessKey <MESSAGEBIRD_ACCESS_KEY>' \\
-H 'Content-Type: text/csv; charset=utf-8' \\
-d @data.csv
Get the total count of all key/value pairs
Exemple de code
curl -X "POST" "https://flows.messagebird.com/databases/database_id/count" \\
-H 'Authorization: AccessKey <MESSAGEBIRD_ACCESS_KEY>'
Export multiple key/value pairs
POST https://flows.messagebird.com/databases/<database_id>/export\
Exemple de code
curl -X "POST" "https://flows.messagebird.com/databases/<DATABASE_ID>/export" \\
-H 'Authorization: AccessKey <MESSAGEBIRD_ACCESS_KEY>' \\
-H 'Content-Type: text/csv; charset=utf-8' \\
As multiple databases are supported:
- if you are calling the default database, use key-values parameter to indicate the ID.
- if you are calling a specific database, use database_id parameter.
📤 Feel free to contact our Support in case you might need some help!