Skip to content

Instantly share code, notes, and snippets.

@khancyr
Created January 9, 2025 10:56
Show Gist options
  • Save khancyr/8dbe2ce521075fce75a568114be92cbb to your computer and use it in GitHub Desktop.
Save khancyr/8dbe2ce521075fce75a568114be92cbb to your computer and use it in GitHub Desktop.
calendy
import requests
import time
from datetime import datetime, timedelta
from faker import Faker
# we'll use Faker to generate fake names, emails, etc
fake = Faker()
starting_url = "https://calendly.com/tanguy-12/1-reunion-presentation-30min-clone/"
scheduling_link_uuid="3g3-bw9-g7j"
phone_number=None
scheduling_url = "https://calendly.com/api/booking/invitees"
# generate today's date for use in range later
today = datetime.today() + timedelta(days=1)
today_formatted = today.strftime("%Y-%m-%d")
# generate the date 30 days from today for use in range later
one_year_from_today = today + timedelta(days=30)
one_year_from_today_formatted = one_year_from_today.strftime("%Y-%m-%d")
# GET request to get event types
username = starting_url.split("/")[3]
event_types_url = f"https://calendly.com/api/booking/profiles/{username}/event_types"
response = requests.get(event_types_url)
event_types = response.json()
# event types have the URL paths we need (i.e. /30min)
# we need to get the UUID in the API call
for event_type in event_types:
uuid = event_type["uuid"]
# GET request to get the dates available for the event type
time_zone = "Europe/Paris"
range_start = today_formatted
range_end = one_year_from_today_formatted
booking_dates_url = (
f"https://calendly.com/api/booking/event_types/{uuid}/calendar/range"
)
query_string = (
f"?timezone={time_zone}&range_start={range_start}&range_end={range_end}"
)
booking_dates_url += query_string
response = requests.get(booking_dates_url)
booking_dates = response.json()
booking_dates = booking_dates["days"] # we only need the days
# check if the user is available on each date
for booking_date in booking_dates:
if booking_date["status"] == "available":
# get open spots for each available date
open_spots = booking_date["spots"]
for open_spot in open_spots:
# we need the starting time for each open spot
start_time = open_spot["start_time"]
# we use data we've gathered to generate a payload
payload = {
"event": {
"start_time": start_time,
"location_configuration": {
"location": None,
"phone_number": phone_number,
"additional_info": None,
},
},
"event_type_uuid": uuid,
"invitee": {
"full_name": fake.simple_profile()["name"],
"email": fake.simple_profile()["mail"],
"timezone": time_zone,
"time_notation": "24h",
},
"remember_device":False,
"scheduling_link_uuid":scheduling_link_uuid,
}
headers = {
"Host": "calendly.com",
"User-Agent": fake.chrome(),
"Accept": "application/json, text/plain, */*",
"Accept-Language": "en-US,en;q=0.5",
"Accept-Encoding": "gzip, deflate, br",
"Referer": starting_url,
"X-Requested-With": "XMLHttpRequest",
"Content-Type": "application/json",
"Content-Length": "3924",
"Origin": "https://calendly.com",
"DNT": "1",
"Sec-GPC": "1",
"Connection": "keep-alive",
"Sec-Fetch-Dest": "empty",
"Sec-Fetch-Mode": "cors",
"Sec-Fetch-Site": "same-origin",
"Pragma": "no-cache",
"Cache-Control": "no-cache",
"TE": "trailers",
}
# finally, send a POST request with our payload to schedule an appointment
response = requests.post(scheduling_url, json=payload, headers=headers)
if response.status_code != 200:
# for debugging
print(f"Status Code: {response.status_code}")
try:
print(response.json())
except:
pass
print(f"Payload sent: {payload}")
else:
print("Successful request.")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment