Creating Workflows with the Pipedream REST API
Pipedream's workflow editor is built for speed. You can build and host entire HTTP REST endpoints, or scheduled cron tasks all within the workflow builder. This skips the unproductive ritual of scaffolding yet other project, pulling down dependencies, configuring your linter, test suite and firing up an HTTP tunnel.
However, there may be times where you'll need to programmatically generate a copy of an existing workflow, but for another account. For example, if you're a BigCommerce Partner or App Developer, you may offer an automation for your merchants that polls their products, inventory or recent orders and processes them using that merchants access token.
Access tokens allow you to perform actions on behalf of your users. For example, with a merchant's BigCommerce Access Token, we can automate portions of the merchant's store using the BigCommerce API.
While you could manually duplicate a workflow you made for a specific merchant to perform tasks like these, it's not as productive or real time as generating the workflow programmatically.
In this short guide, we'll show you how you can use the Pipedream Workflow REST API to create a new workflow based on another.
If you want to learn about the original workflow we've built as an example, read on. But if you want to jump ahead to how to use the Create Workflow Endpoint, feel free to jump ahead to the Copying the workflow for a new merchant section.
The stage
In this example, we're assuming the role of a BigCommerce App developer. We're using the Node.js starter template which stores our users BigCommerce store access tokens within a MySQL database.
Not familiar with BigCommerce apps? You can build your own app with this short tutorial.
When merchants install our app, their BigCommerce access tokens will be stored within our database. We used DigitalOcean's Database-as-a-Service to spin up a quick database so it's accessible from both our locally hosted BigCommerce app as well as Pipedream.
While BigCommerce offers webhooks for events like when new products are created or updated, it's never a bad idea to have additional redundancy for polling the products in case of an outage or missed webhook.
Let's start by making a scheduled workflow that runs daily.
Then we'll add a new MySQL - query row step and we'll hardcode a query to our MySQL database with the store's storeHash
(a.k.a unique ID):
Yes, you're not reading this wrong, we're hardcoding the storeHash
prop to this step. And that's ok, this workflow is only dedicated to using this particular store's accessToken
. We'll show you how we can modify this hardcoded value for another workflow later.
Using the accessToken
within a BigCommerce action
Not only can you leverage accounts that you've connected while logged into the Pipedream dashboard, but you can also pass credentials directly into pre-built actions using external auth.
We've added the BigCommerce - Get Products action as a new step in the workflow, next we click Use external authentication:
And now you'll be able to reference the accessToken
and storeHash
from the previous MySQL query step in our workflow:
Now the step uses our accessToken
stored from our own database, and can successfully retrieve the products from this store:
The next steps depend on your own circumstance, which BigCommerce API endpoints you need to check against, or additional logic you need to perform.
Let's move onto how to copy and reconfigure this workflow via the Pipedream Workflow REST API.
Copying the workflow for a new merchant
When another merchant installs our app, we'll need to create this workflow but with their storeHash
instead of the original.
Here's where the magic begins.
Within the original workflow, open the right hand side menu and select Instantiate via API:
Select which props you'd like to include in the scaffolded HTTP request. In this case I selected all except the MySQL row:
After clicking Generate API Code you'll receive the entire scaffolding needed to create the same workflow over the REST API - Create Workflow endpoint:
Specifically we'll just need to replace storeHash
at steps[0].props.value
, then our new workflow will use the accessToken
belonging to another BigCommerce store.
You can use an HTTP request building tool such as Postman, Bruno, or HTTPie to perform this request. Or alternatively you can use the HTTP request builder within Pipedream itself.
To make an authenticated request to the Pipedream REST API, you'll need your workspace's API key. You can find it by following this short guide.
I recommend the latter if you want to automate creating additional workflows as part of an app install event. Then you can scale this workflow production for each new merchant that installs your BigCommerce app.
Limitations (for now)
For now you can only replace the props
configuration for a given workflow. It's currently not possible to alter the steps
or code within a specific step.
But this endpoint allows you to recreate templatized version of your workflows to quickly scale automations for your customers individually.
Learn more
📚 Check out the Create Workflow REST API Endpoint
🛍️ Learn more about developing BigCommerce apps
🤝 Join the Pipedream community
🔨 Follow the Pipedream Quickstart guide