Sending data to flows
Every Flow you create is kicked off through a trigger which can be one of the following:
- A message received from a Real Time Event Stream such as Kafka or Rabbit
- Webhook: A Single Flow API call to trigger a specific flow
- Webhook: A MultiFlow API call that can trigger one or more flows
You do not need to use all three methods but you will need to use at least one to get Flows going. In the following sections we will learn how to set up and work with each of them.
Real Time event stream
Flows is most powerful when it works with a real time data feed. Feeds through Kafka are currently the preferred way to trigger Flows but we can support any other real time event stream such as Rabbit and Amazon SQS. To set up a Kafka feed, you will need to provide all connection details that would be required for Flows to connect to and consume the data. The connection details required are the following:
Field Name | Description |
Name | Generic name for the stream |
Bootstrap Servers | Comma separated list of IPs and ports for the server |
Group ID | The group ID you wish Flows to connect as |
Offset | 'Earliest' or 'Latest' - where to start reading the stream |
Protocol | SASL_SSL etc |
SASL mechanism | e.g Plain |
SASL configuration | e.g org.apache.kafka.common.security.plain.Plain LoginModule required username="fred" password="letmein" |
At this stage, real time feeds need to be configured by the Flows team. Once you’ve collected the above information please contact the team for your feed to be enabled.
Running a Single Flow
You can trigger a single flow through API and return the results by using the flows unique ID. In order to start calling a single flow you must create and enable the flow first.
Single flow calls are synchronous calls so they are particularly useful when you want to call a Flow and get a response back from the flow that your are calling
Once you have a flow enabled you can trigger it through an API call to the following endpoint:
POST https://run.flows.world/v2/flows/<flow-id>
Parameter Location | Parameters | Description | Type |
Path | flow-id | The unique ID of the flow which can be found on the overview page of the flow | String |
Header | x-api-key | API Token need to trigger non public flows (see Security) | String |
Body | payload | A data set of parameters and values to pass into the flow | Json Object |
Example: POST https://run.flows.world/v2/flows/0l83dca4-2209-2585-g3h1-36dv6d5c918c
{
"message":"Hello Flows!"
}
Running Multiple Flows
With MultiFlow Webhooks, you can broadcast a message from your system to several flows that are waiting for that particular message to trigger. This is very similar to how flows works with real time stream events but MultiFlow Webhooks allow you to send a message through an API call instead of through an event streaming system.
You can send a MultiFlow webhook by making a POST call to the following API:
https://run.flows.world/v2/events/<event-name>
Parameter Location | Parameters | Description | Type |
Path | event-name | The name of the even that your are sending. This could be any name you choose (Deposit, Registration, Login etc) | String |
Header | x-api-key | API Token needed to trigger non public flows (see Security) | String |
Header | workspaces | A comma separated set of workspace IDs to send the event to | String |
Body | payload | A data set of parameters and values to pass into the flow | Json Object |
When you call this API, Flows will determine if it has seen the message type before. If it has, it will continue and trigger any flow that has this message configured as a trigger. If it is the first time the message has been sent then Flows will automatically learn it and will create an internal representation of the message which will now be available as a trigger that can be added to any number of flows.
Take for example the following simulated Deposit event that is being sent for the first time
POST: https://run.flows.world/v2/events/Deposit
{
"UserName":"Mike",
"UserID":12343,
"Data": {
"Amount":10.44,
"Currency":"EUR",
}
}
Flows will notice that it hasn’t seen this message before and will add a trigger for it named “Deposit”. When called the first time, the following will be returned:
{
[
{
"flows": [], //No Flows Triggered
"learned": {
"messageName": "Deposit", //The name of the new message
"newMessage": true, //Flag to indicate if message is new or not
"fields": [. //The set of fields that have been learned for this message
{
"field": "UserName",
"type": "string"
},
{
"field": "UserID",
"type": "integer"
},
{
"field": "Data.Amount",
"type": "double"
},
{
"field": "Data.Currency",
"type": "string"
}
]
},
"workspaceId": "Wjlp1MNpa7I4PPbmlA"
}
]
}
Because this was the first time, no flows would be triggered (TotalFlows=0) however you can now find this new message type as a trigger when creating a flow.
If you call the same method again, you will get back the following:
[
{
"flows": [], //No Flows triggers
"learned": {
"newMessage": false, //Message is not new
"fields": [] //Nothing new learned
},
"workspaceId": "Wjlp1MNpa7I4PPbmlA"
}
]
Flows has learnt nothing new and has not triggered any flows. If you add something to the payload, and run it again, you will see the new field being added.
Once you have successfully sent a message it will trigger any flows configured to listen to that message.
See Triggers for more information on how to create a flow to listen to these messages
Security & Public Flows
When triggering flows through webhooks, you will likely want to secure these calls which can be done by using API Keys. An API key can be created from the admin panel and be applied to one or more workspaces. Once an API has been created it can be used by adding it as an HTTP header to your single or multi flow API call:
x-api-key: <Your API Key>
There might be times when you need to access a flow directly from an unsecure location, such as your website's front end. To make this possible, you'll need to set up your flow as a "Public" flow. This can be easily done by adjusting its properties. Once a flow is marked as public, it can be run without an API key from anywhere you need it.
When using public flows, caution is necessary as they can be accessed by anyone from anywhere. It is important to avoid including any features that could alter sensitive data within public flows.