Skip to main content

How to create a new POWR App on Zapier

  • Go to https://developer.zapier.com/ and login using LastPass credentials
  • Go to My integrations menu on the top right side and click on Start a Zapier Integration

You will be redirect to some page where you will need to set up some zapier configurations.


Authentication​


The first thing that you will need to do is to setup the authentication:

  • Select OAuth v2
  • On step 1, add a access_token field as a string
  • On step 2, copy Zapier's OAuth Redirect URL, you're going to need it to setup the authentication on our side.

Go back to powr project and open your rails console, we will need to create a new data on Doorkeeper::Application, where we have the following fields:

  • name
  • uid
  • secret
  • redirect_uri

You'll only need to fill name and redirect_uri fields, the others are going to be created automatically. Paste Zapier's OAuth Redirect URL on redirect_uri. Example:

Doorkeeper::Application.create(
name: "POWR New app",
redirect_uri: "https://zapier.com/dashboard/auth/oauth/return/App158239CLIAPI/"
)

and something like this will be created:

<Doorkeeper::Application:0x00007fdd1a6304d0> {
:id => 2,
:name => "POWR New app",
:uid => "aClT6jmPc9QmP1IlRIYPAIOUeNn09TSf6igk6H0VVz0",
:secret => "-bS3yqzeG64_7g-n3T4ZR6_79dJvdROD0iOy85UISs4",
:redirect_uri => "https://zapier.com/dashboard/auth/oauth/return/App158239CLIAPI/",
:scopes => #<Doorkeeper::OAuth::Scopes:0x00007fdd1a643350 @scopes=[]>,
:created_at => Wed, 01 Jun 2022 23:13:07 UTC +00:00,
:updated_at => Wed, 01 Jun 2022 23:13:07 UTC +00:00,
:confidential => true
}

How to create Triggers​


Every Zap starts with a trigger, powered by either a webhook subscription that watches for new data as it comes in or a polling GET API call to check for new data periodically. In our case, we're going to use webhooks. If you want to understand why and detailed explanation, I highly recommend you to take a look on this doc here: https://zapier.com/engineering/webhook-design/

Example: I'm using a POWR Contacts app and everytime I got a new contact in any of my apps, I want a new spreadsheet to be created with this new data.

In our database structure, a Site has many contacts from many apps, so I will need to create a trigger to choose from which website I want to sync my new contacts.

Trigger to list Websites​


Let's create a trigger to list all websites:

  • on Sidebar, click on triggers and then, Add Trigger
  • fill key, name, noun and description fields
  • set visibility options as hidden. Save and go to API Configuration tab
  • on step 1, create a pooling type to get websites (this will only be shown when the user is configuring his zapier, so it won't be a problem to be a pooling route)
  • Save and test you API request.

Trigger to create new Contacts​


Now, let's create a trigger for new contacts:

  • on Sidebar, click on triggers and then, Add Trigger
  • fill key, name, noun and description fields
  • set visibility options as Important. Save and go to Input Designer tab and Add User input field
  • fill required fields and on options section, select required, dropdown and dynamic
  • on Dropdown Source, choose the previous trigger that you have created for listing Sites. Fill the other fields left, save and go to API Configuration tab

New Subscriptions​


Now, let's create REST hook for new subscriptions:

You will need a route that everytime a user setup a Zap (subscribe a new zap), Zapier is going to post some data to this route saying Hey, I have a new subscription here for this website! (use your imagination here lol)

In our side, we have a table called sites_webhook where we store the webhook_id, site_id, status and url. We need this to know which webhook is it and also the url so when we have new contacts, we can send a post directly there.

So for subscribe, I created this route here: https://www.powr-staging.io/api/v1/sites/{{bundle.inputData.site_id}}/webhook

where: {{bundle.inputData.site_id}} is the key name that we created on Input Designer tab

Unsubscribe​


You will also need a unsubscribe route so we can set the webhook as inactive everytime a user decides to unsubscribe. Can be something like this: https://www.powr-staging.io/api/v1/sites/{{bundle.inputData.site_id}}/webhook/{{bundle.subscribeData.id}}

Perform List​


And a Perform List, that will return a contact sample data in the Zap Editor, something like this: https://www.powr-staging.io/api/v1/site/{{bundle.inputData.site_id}}/contacts


Notes​


This is an example about how I did it on POWR Contacts, but you can fit it according your needs.

You can also take a look here to check, in case I missed some step: https://developer.zapier.com/app/158239/version/1.0.0/triggers

We also need some approval from Zapier so the app can goes live and it can take a while. You can provide staging url so them can test it whithout needing to push it to production.

Explaning how to test it on Zapier https://www.loom.com/share/6c2e9ce1fc5c4a528dbdb8053430bdeb