Question

Resthook conventions via CLI

  • 1 April 2022
  • 2 replies
  • 105 views

I’m getting started with the Zapier CLI and I definitely would rather use rest hooks than polling. As I’m going through the CLI tutorial I see the example for creating a trigger file and it describes the convention as using a folder named “triggers”. I’m looking at the “How to use resthooks” section of the CLI documentation and I’m confused about the folder convention and file structure of these subscribeHook and unsubscribeHook functions. Are these resthook functions supposed to be separate files or are these functions supposed to be in my trigger file etc? Are there any sample applications that implement resthooks I could take a look at to understand the structure? I’m a backend developer so I understand implementing the resthooks in our API but I’m a little stuck on creating the JavaScript part of the integration via the Zapier CLI.


This post has been closed for comments. Please create a new post if you need help or have a question about this topic.

2 replies

Userlevel 7
Badge +9

Here’s a simple rest hook example: https://github.com/zapier/zapier-platform/tree/master/example-apps/rest-hooks

A great reference to get a view of what’s going on is to look at the schema that defines a Zapier integration: https://zapier.github.io/zapier-platform-schema/build/schema.html

How you organize your code into directories and files is very flexible, but you’ll see our common conventions in the examples, if you use the zapier scaffold command, and something you might do is start your project in the UI tool, and then convert it to the CLI to get a really nice, fast scaffold of your CLI project.  https://platform.zapier.com/docs/export

The common convention is to have a trigger directory, and a js file for each trigger that implements the trigger schema. https://zapier.github.io/zapier-platform-schema/build/schema.html#triggerschema. The operation in that file will implement the hook operation schema: https://zapier.github.io/zapier-platform-schema/build/schema.html#basichookoperationschema  You’ll include and reference functions for performSubscribe,  performUnsubscribe, performList, and perform in that file. 

Some folks will optimize and move common/shared code into their own modules, but start simple.  

 

Thank you for the detailed and thorough explanation! The github sample is exactly what I needed.