How to retrieve Calendly event UUID for scheduled appointments

I need help getting the unique identifier for booked meetings in Calendly. The issue is that users schedule appointments through a booking_url redirect instead of my API, so I can’t capture the UUID during the booking process.

require 'net/http'

class SchedulingController < ApplicationController
  before_action :authenticate_user

  def fetch_event_types
    owner_uri = ENV['CALENDLY_OWNER_URI']
    api_endpoint = "https://api.calendly.com/event_types?user=#{owner_uri}"

    request_headers = {
      'Accept' => 'application/json',
      'Authorization' => "Bearer #{ENV['CALENDLY_ACCESS_TOKEN']}"
    }

    api_response = Net::HTTP.get_response(URI(api_endpoint), request_headers)
    parsed_data = JSON.parse(api_response.body)

    render json: parsed_data
  end
end

The API returns data like this:

{
  "collection": [{
    "uri": "https://api.calendly.com/event_types/BBBBBBBBBBBBBBBB",
    "name": "30 Min Consultation",
    "active": true,
    "booking_method": "standard",
    "slug": "consultation-call",
    "scheduling_url": "https://calendly.com/consultation-call",
    "duration": 30,
    "kind": "solo",
    "type": "StandardEventType",
    "color": "#0069ff",
    "created_at": "2023-05-15T10:30:25.123456Z",
    "updated_at": "2023-06-20T14:22:18.987654Z",
    "description_plain": "Book a 30 minute consultation",
    "description_html": "<p>Book a 30 minute consultation</p>",
    "profile": {
      "type": "User",
      "name": "Sarah Wilson",
      "owner": "https://api.calendly.com/users/BBBBBBBBBBBBBBBB"
    }
  }]
}

Since appointments get created through the scheduling_url redirect rather than my application, I want to call https://api.calendly.com/scheduled_events/{uuid} to get event details for my database.

I also need to create records in my Session model after each successful booking. Right now the booking happens outside my app through Calendly’s interface. I’m thinking about fetching event data and using it to populate my database automatically. Is there a better approach?

Here are my model relationships:

class Therapist < ApplicationRecord
  has_many :sessions
  has_many :clients, through: :sessions
end

class Session < ApplicationRecord
  belongs_to :therapist
  belongs_to :client
  has_one :note
end

class Client < ApplicationRecord
  has_many :sessions
  has_many :notes
  has_many :therapists, through: :sessions
end

class Note < ApplicationRecord
  belongs_to :session
  belongs_to :client
end

You need the scheduled events API endpoint to grab UUIDs after bookings complete. I’ve dealt with this exact problem building a coaching platform with external scheduling. Hit GET https://api.calendly.com/scheduled_events with query parameters for date range and user. This pulls all scheduled events with UUIDs in the response. Loop through and match against your Session records to spot new bookings. ```ruby
def sync_calendly_events
api_url = “https://api.calendly.com/scheduled_events?user=#{ENV[‘CALENDLY_OWNER_URI’]}&min_start_time=#{1.day.ago.iso8601}
response = Net::HTTP.get_response(URI(api_url), auth_headers)
events = JSON.parse(response.body)[‘collection’]
events.each do |event|
uuid = event[‘uri’].split(‘/’).last
create_session_if_missing(uuid, event)
end
end

Run this as a scheduled job every few minutes to catch new bookings. Use the `min_start_time` parameter to only fetch recent events - saves you from processing the same data over and over. Store the Calendly UUID in your Session model so you don't create duplicates. Works great when webhooks aren't an option.

Been there. Chasing UUIDs after bookings complete sucks, especially when you need real-time sync between Calendly and your app.

I fixed this exact problem at work with automated workflows that handle the entire booking-to-database pipeline. No manual API calls or scheduled jobs needed.

The key is catching Calendly events instantly and processing them into your Session records automatically. No polling, no missed bookings, no duplicates.

Here’s the flow:

  1. Workflow triggers on Calendly booking
  2. Grabs event UUID and invitee details
  3. Maps Calendly data to your Session fields
  4. Creates Session record with therapist/client relationships
  5. Handles errors and prevents duplicates

You can even do smart matching - find existing clients by email or create new ones if they don’t exist. Way cleaner than custom webhook handlers or cron jobs that might miss stuff.

I built something similar for a client management system and it killed all the sync headaches. Events flow from Calendly straight to the database without touching code.

Your Session model stays perfectly synced and UUIDs get stored automatically for future API calls.

Webhooks are your friend here. Skip chasing UUIDs after the fact - set up Calendly webhooks to push event data straight to your app when bookings happen.

I hit this exact problem at my last company integrating with scheduling platforms. Polling APIs for new events is messy and you miss real-time updates.

Here’s what worked:

  1. Create a webhook endpoint in your Rails app for Calendly notifications
  2. Configure Calendly to send invitee.created events to your endpoint
  3. Extract the event UUID and invitee details from the webhook payload
  4. Use that data to create Session records automatically

Your webhook controller might look like:

class CalendlyWebhooksController < ApplicationController
  skip_before_action :verify_authenticity_token
  
  def handle_event
    event_data = JSON.parse(request.body.read)
    
    if event_data['event'] == 'invitee.created'
      create_session_from_calendly(event_data['payload'])
    end
    
    head :ok
  end
  
  private
  
  def create_session_from_calendly(payload)
    # Extract UUID and create your Session record
    event_uuid = payload['event']['uri'].split('/').last
    # Process invitee data and create session
  end
end

This kills the need to poll for UUIDs and keeps your database synced automatically. The webhook payload has all the event details you need.

I’ve built similar therapy management systems, so here’s what works: use both approaches. Webhooks give you instant notifications, but scheduled polling catches anything webhooks miss. The tricky bit is client identification since Calendly only gives you email addresses. I handle this in my webhook handler - try to match existing clients by email first, then create new Client records if there’s no match. For UUIDs, just add a calendly_event_uuid field to your Session model. Makes future API calls dead simple when you need event details. The webhook payload parsing is straightforward since the event URI has the UUID right there. Watch out for cancellations and reschedules - I got burned by this. Make sure you process invitee.canceled events to update your Session records. Otherwise your database goes out of sync with actual appointments. The scheduled events API is great as backup, but don’t use it alone. Webhooks mean sessions show up immediately after booking, which users expect.