Webhooks

Examples for creating and receiving Calendly webhook subscriptions

Create a webhook subscription

Subscribe to invitee.created and invitee.canceled webhook events. Replace token, org, user, and webhook_url with values for your account.

1require 'faraday'
2require 'json'
3
4token = '<your oauth token>'
5org = 'https://api.calendly.com/organizations/<org_uuid>'
6user = 'https://api.calendly.com/users/<user_uuid>'
7webhook_url = '<your webhook endpoint>'
8base_url = 'https://api.calendly.com'
9
10conn = Faraday.new(
11 url: base_url,
12 headers: {
13 'Content-Type' => 'application/json',
14 'Authorization' => "Bearer #{token}"
15 }
16)
17
18response = conn.post('/webhook_subscriptions') do |req|
19 req.body = {
20 url: webhook_url,
21 events: ['invitee.created', 'invitee.canceled'],
22 organization: org,
23 user: user,
24 scope: 'user'
25 }.to_json
26end

Receive webhook events and filter by event type

Calendly sends webhook events for all meetings booked through our platform. You can filter by a specific event type if you only want to process certain events.

1require 'sinatra'
2
3EVENT_TYPE_FILTER = 'https://api.calendly.com/event_types/<uuid>'
4
5post '/webhook' do
6 request.body.rewind
7 payload = JSON.parse(request.body.read)
8 event_type = payload['scheduled_event']['event_type']
9
10 if event_type == EVENT_TYPE_FILTER
11 puts '--Received webhook event from Calendly--'
12 pp payload
13 else
14 puts '--Skipping webhook event--'
15 end
16
17 status :ok
18end

Follow these instructions to get started with Sinatra. After that, save this to webhook_receiver.rb and run with:

$$ ruby webhook_receiver.rb

Use ngrok to listen for webhook events locally

You can use ngrok to tunnel connections for local development. After starting ngrok, update the webhook_url in the subscription example above.

$$ ngrok http 4567