Tutorial - Create a Workflow
Tutorial to create and run a workflow via the developer API
In this this tutorial we will go through the process of creating a workflow via the Developer API, running the workflow via the created webhook source, and then listening for events to capture the newly created document. All API calls within this tutorial will use cURL, don't forget to insert the Developer Access Token that was provided to you by the Portant integrations team.
💡TIP: Before getting started with the Developer API, try creating and running a workflow in the Portant Workflow web app to get familiar with how workflows in Portant operate. We recommend creating a workflow with a Google Docs template to ensure your account is correctly authorised with Google's APIs.
The following tutorial assumes you have covered all steps in the Getting Started guide.
Step 1. Create a workflow
We will name our first workflow "Developer Workflow" and use the Workflows POST endpoint to create the workflow.
If all is set up correctly you will receive as 201 Created
status code and see the following JSON response:
Note the ID value that was returned as we will use this for future requests in this tutorial.
If you navigate to https://app.portant.co/w/wkf_<id>/
with the return workflow ID you will see your newly created workflow. Important fields to note here are the source.webhookUrl and
status
fields.
The source.wbehookUrl
field contains the address that data will be sent to in order to initiate an automation once the workflow is complete and ready to create automations, note this value down as we will do this later in the tutorial.
The status
field shows that the workflow is "INCOMPLETE"
because we do not have any template documents in the workflow. The minimum requirements for a workflow to be complete is that it contains both a source and at least one type of template document. We will create our first template document in the next step.
Step 2. Create a Template Document
To create a template document we will use the following request to copy an existing Google Docs file to our workflow to use as a template.
The file_id
must contain the the ID of a file in Google Drive that you have access to. The ID of a file can be found simply by looking at the URL. For example the ID used in the request above is extracted from the following url: https://docs.google.com/document/d/1frlTt7Jj8HuXWHkS9o0mshLaym6NQBImsAIhw4Iiew4/
The actual file ID included above can be used for testing as this contains links to a publicly accessible document created by Portant.
Once the request is submitted you can expect to see the following response:
As we can see, a new document template has been added to our workflow that contains a copy of the template document we provided. The document resource contains a set of options that affect how the output documents are created. These options can be toggled via a PATCH request to the Document.
If you query the GET endpoint for our previously created workflow you will see the status is now complete but we would also like to set up notifications when a new document is created before we run our first automations.
Step 3. Listen for Automation Events
In order to listen for events from our automations we can configure an outgoing webhook to have our workflow notify us when a document is created. For this tutorial we will use https://webhook.site to quickly create a test webhook. Once you have your webhook address ready we will create a POST request as follows to create a new Outgoing Webhook configuration.
We can expect a 201 Created
response containing the webhook url we provided. Our workflow is now ready to run.
Step 4. Post Data to our Webhook Source
In order to start an automation our workflow's webhook source will be listening for a POST request that contains a JSON body with key-value pairs. We can use the following request for example. Note, we are submitting this to the webhook url that returned in the Workflow payload from Step 1:
Currently this endpoint will return a 200 OK
with an empty JSON dictionary as a payload. If you check the webhook.site you set up in the previous stage within a minute you should see an event occur that links to the the newly created document in your Google Drive.
In the Portant Workflow web app you will also be able to see the created outputs in the outputs page of your workflow. Congratulations! You have just created your first workflow and automation via the Portant Developer API!
For more details on all endpoints and resources please explore the API Reference. If you have any questions or feature requests for the API or Portant in general please don't hesitate to contact our customer success or integration teams directly. Happy Hacking!
...and if you were wondering... Jeremy is our Portant mascot! 🐨
Last updated