DEV Community

Elisa Levet for Zoom

Posted on

Setting up a Postgres database to receive Zoom webhooks

Thank you for joining us again for part two of this series. As a recap, in the last section we talked about webhooks, what are they, why use them and gave some real life examples.

I have decided to use a webhook-only app for this example because the setup is simple, and event subscriptions are all we'll need. You can also use webhooks with OAuth apps and the Server-to-Server OAuth apps if you need to make API requests.

Create a webhook-only app in the Zoom App Marketplace:

  • Log in to your Zoom account and head to the Zoom App Marketplace to start.
  • Click the dropdown that says Develop and then click Build App:

Zoom App Marketplace

  • Make sure to click Create under the tile that says Webhook Only and give your app a name.

Webhook Only app

Fill up the required information and once that's done, head to the Feature tab and make sure to enable event subscriptions. Give your event subscription a name and in the event notification endpoint URL, make sure to add your ngrok URL. We need to expose the local server to the internet to accept post requests from Zoom.

To get an event notification endpoint URL for this guide, run the following command:

$ ngrok http 3000
Enter fullscreen mode Exit fullscreen mode

Copy the ngrok https url displayed in terminal and include /webhook path, it should look like this:

https://exampleurl.ngrok.io/webhook

Enabling subscriptions

Click on Add events. For this guide, we will only add "Meeting has been created" and "Meeting has been deleted" and click done.

Event Types

Lastly, click Continue so you can activate your app.

Set up the sample app

Pre-requisites:

  1. Node JS
  2. Ngrok
  3. PostgreSQL
  4. Zoom Account
  5. Webhook-only app credentials

Now that your webhook-only app is created and activated in the Zoom Marketplace, it is time to run the sample app in your local environment.

Setup and install

First, clone the git repository found here:

git clone https://github.com/zoom/webhook-to-postgres
Enter fullscreen mode Exit fullscreen mode

Use NPM to install dependencies:

$npm install
Enter fullscreen mode Exit fullscreen mode

Open the .env file in your text editor and enter the following information from the feature section that you just configured:

# Zoom Secret token from your Webhook only app
ZOOM_WEBHOOK_SECRET_TOKEN=
Enter fullscreen mode Exit fullscreen mode

Create our Database

You can skip these steps if you already have Postgres installed in your local environment. If not, follow along to install pg and create a table in your database.

brew install postgresql
Enter fullscreen mode Exit fullscreen mode

After the installation is complete, we'll want to get PostgreSQL up and running, which we can do with services start.

brew services start postgresql
Enter fullscreen mode Exit fullscreen mode

With PostgreSQL now installed, we will connect to the default Postgres database running

psql postgres
Enter fullscreen mode Exit fullscreen mode

We are now inside psql in the Postgres database. You will see the prompt ends with an # to denote that we are logged in as the superuser, or root (postgres=#).
Commands within psql start with a backslash. To test this, we can check what database, user, and port we have connected to using the \conninfo command

postgres=# \conninfo
Enter fullscreen mode Exit fullscreen mode

Creating a role in Postgres

We are going to create a role called "me" and give it a password of "password":

postgres=# CREATE ROLE me WITH LOGIN PASSWORD 'password';
Enter fullscreen mode Exit fullscreen mode

And we want "me" to be able to create a database:

postgres=# ALTER ROLE me CREATEDB;
Enter fullscreen mode Exit fullscreen mode

Now, we will create a database for the "me" user. Exit from the default session with \q for quit and now we will connect Postgres with "me"

psql -d postgres -U me
Enter fullscreen mode Exit fullscreen mode

We can create a database with the SQL command as follows:

CREATE DATABASE zoomwebhooks;
Enter fullscreen mode Exit fullscreen mode

Connect to the new database

\c zoomwebhooks
Enter fullscreen mode Exit fullscreen mode

You are now connected to database "zoomwebhooks" as a user "me".

Creating a table in Postgres

Finally, in the psql command prompt, we will create a table called events with four fields, two VARCHAR types, one BIGINT type, and an auto-incrementing PRIMARY KEY ID:

CREATE TABLE events (
  ID SERIAL PRIMARY KEY,
  name VARCHAR(30),
  accountid VARCHAR(30),
  meetingid BIGINT
);
Enter fullscreen mode Exit fullscreen mode

We have finished with all our PostgreSQL tasks, and make sure to add the credentials in your .env file. Now it is time to get our app up and running!

# PostgreSQL credentials and information
PORT=
PG_USER=
PG_HOST=
PG_DATABASE=
PG_PASSWORD=
PG_PORT=

Enter fullscreen mode Exit fullscreen mode

Start the app
It is time to run the app

$npm run start
Enter fullscreen mode Exit fullscreen mode

While your app is running on port 3000, go to Zoom here and create a meeting or delete an existing meeting in your account.

Once you do this, you will see the event printed in your console and a new instance created in your Postgres database.

You can add as many events as you want, and they all will be stored in your database.

Thank you for follow along and happy coding 😀!

Top comments (0)