Skip to main content

Building an Integration with Multiple Flows

Overview#

In this tutorial we'll cover how to create an integration with multiple flows. In this scenario, we are our fictional B2B software company, Progix. Our customers would like to sync inventory and customer data from their "Acme ERP" systems into Progix. Our integration to Acme ERP will be made up of three flows:

  1. When customer data in Acme ERP is created or updated, the data is processed and sent to Progix.
  2. When inventory data in Acme ERP is updated, that data processed and sent to Progix.
  3. Acme ERP needs to be configured to send data to the previous two flows' webhook endpoints. A third flow runs at deploy-time and sets up webhooks within Acme ERP.

The first two flows could be developed as distinct integrations, but then customer would need two instances deployed to them to integrate with Acme ERP (more as we handle more webhook types). That would get get pretty burdensome. It's much cleaner and maintainable to have a single "Acme ERP" integration that contains the various Acme ERP related flows.

Creating Our Data Sync Flows#

First we'll create a new integration. When we're dropped into the integration designer, we start with a flow that has the default name "Flow 1". We can develop our first flow - the one that syncs customer data - in this editor.

When we're ready to add the second flow, we can click the + ADD FLOW button on the top-left side of the integration designer area.

We can call the new flow "Sync Inventory Data", and while we're at it we can rename "Flow 1" to "Sync Customer Data".

Each "Sync Data" flow can be developed as you would normally develop an integration. You can read about developing integrations on the building integrations docs article.

Config Variables with Multiple Flows#

Config variables are shared between flows. That lets us enter Progix or Acme ERP credentials just once when configuring an instance of the integration. If we open up the Config Variables drawer, we can customize the deployment experience for our support team members and customers. I'll go ahead and add headings like "Progix Configuration" and "Acme ERP Configuration" and add some config variables and credentials that will be required for the various flows in the integration:

Testing Our Data Sync Flows#

Each flow has its own unique webhook URL and can be tested independently from the other flow. To test a flow, we can swap over to the flow we'd like to test by clicking the name of the current flow on the top left of the integration designer drawer, select the flow we'd like to test Then, we can click SAVE & RUN TEST.

Running a test in one flow will not invoke the other flow(s).

Create Our Initialization Flow#

At this point, we have two working flows that can process data from Acme ERP. We could stop development here, and whenever we deploy an instance of this integration we could manually enter in the Webhook URLs that the instance is assigned into Acme ERP.

I'd like to create those webhooks programmatically, instead. Let's create a third flow and call it "Initialization" that sets up those webhooks within Acme ERP. Like last time, we'll add a new flow, and give it a name and description.

Leveraging Deploy time Triggers#

We want this "initialization" flow to run when an instance of the flow is deployed. To make that happen, we need to configure the trigger to run at deploy time. We'll click into the Integration Trigger and select that the trigger is a Deploy type trigger:

Referencing Webhook URLs as Inputs#

Our "Initialization" flow will have two steps - one for each webhook we need to set up in Acme ERP to point to the two other "sync data" flows. An integration is cognizant of its own flows' webhook URLs, and those are accessible from the trigger's results.webhookUrls.FLOW_NAME. We can pass those webhook URLs as inputs into a custom component that is responsible for creating webhooks within Acme ERP:

We can test this flow as we would any other flow, and verify within Acme ERP that webhooks pointing to our test integration were set up as we'd expect.

Deploy to a Customer#

Our integration is ready. Now, we can publish it and deploy an instance of the integration to one of our customers. The instance configuration page that we see here reflects what we created above. Note again that each of our flows have a unique webhook URL:

After clicking SAVE AND DEPLOY we can see under the Executions tab that our initialization deploy time flow ran successfully and configured webhooks in Acme ERP, so customer and inventory data will start streaming to their respective flows in this instance:

Deploy time triggers aren't just for webhooks

Deploy time triggers can be used for a number of things. We used them to configure webhooks in this tutorial, but you could use them to set up users in a system, configure directories in a file store, enable features in a third-party service, etc. Anything you might want to run when an instance is first deployed can be placed in a flow with a trigger of type Deploy.