- Products
- Solutions Use casesBy industry
- Developers
- Resources Connect
- Pricing
When your app’s user is a manager overseeing a team that meets with external clients and prospects regularly, it’s her job to ensure the workload is spread evenly across the team. However, she doesn’t always have insight into how often and when her team is on calls and in meetings because this information is scattered across multiple calendars. The Nylas Calendar API makes it easy to centralize all of this data and to streamline the scheduling process within your app.
With Nylas, you can streamline the scheduling process and give your users key insights into team bandwidth and customer lifecycle stage with a full-featured scheduling & analytics system within your app. This data gives managers key insights into workload capacity so they can identify who might have the bandwidth to take additional meetings. It’s also useful to keep tabs on the stage the prospects or clients are at within the customer lifecycle; new prospects need different support than prospects who are on the verge of making a buy.
from nylas import APIClient import os import datetime CLIENT_ID = os.environ['CLIENT_ID'] CLIENT_SECRET = os.environ['CLIENT_SECRET'] ACCESS_TOKEN = os.environ['ACCESS_TOKEN'] # Initialize a Nylas client object that uses your user's access token nylas = APIClient( CLIENT_ID, CLIENT_SECRET, ACCESS_TOKEN )
# Retun all calendars for a user account calendars = nylas.calendars.all() # Get the ID of the "Prospect Meetings" calendar calendar_id = [ calendar['id'] for calendar in calendars if 'Prospect Meetings' in calendar['name'] ][0]
{ "description": "A shared team calendar to keep track of meetings with external prospects", "id": "67qmz3fuk9wf***", "name": "Calendar", "account_id": "bh1vu31mw9ap***", "object": "calendar", "read_only": false }
today = datetime.date.today() # Get Monday's datetime and convert it to a unix timestamp monday = today + datetime.timedelta(days=-today.weekday(), weeks=1) monday_unix = monday.strftime("%s") # Get Friday's datetime and convert it to a unix timestamp friday = monday + datetime.timedelta(days=5) friday_unix = friday.strftime("%s")
# Find all events on the Prospect Meetings calendar between this Monday and Friday events = nylas.events.where( calendar_id=calendar_id, starts_after=monday_unix, ends_before=friday_unix )
{ "title": "New Kite Technology", "description": "Let's discuss the newest kite technology.", "participants": [ { "comment": "This would be great for my experiments!", "email": "[email protected]", "name": "Benjamin Franklin", "status": "yes" }, { "comment": null, "email": "susan@my_company.com", "name": "Susan Seller", "status": "yes" } ], "read_only": false, "status": "confirmed", "when": { "start_time": 1478565000, "end_time": 1478568600, "object": "timespan" }, "calendar_id": "412pwfsq3k7uklj1zkq5", "id": "c7n5vl6dhbdeqwjaxk29", ... }
internal_employees = [] external_prospects = [] this_meeting = {} for event in events: for participant in event["participants"]: # If our company domain is in the participant's email, they're our employee if '@my_company.com' in participant["email"]: if participant["email"] not in internal_employees: internal_employees.append(participant["email"]) # Anyone who isn't in our company should be appended to external_prospects else: if participant["email"] not in external_prospects: external_prospects.append(participant["email"]) this_meeting[participant["email"]] = event["when"]["start_time"]
for employee in internal_employees: total_hours = 0 for event in events: if employee in [participant["email"] for participant in event["participants"]]: # Nylas represents time as seconds since epoch time, we need to convert this to hours total_seconds = event["when"]["end_time"] - event["when"]["start_time"] total_hours += total_seconds / 60 / 60 print("{} is spending {}% of their time in meetings this week".format( employee, ( total_hours / 25 ) * 100 ))
for prospect in external_prospects: contacts = nylas.contacts.where(email=prospect).all() if contacts: contact = contacts[0] # A contact can have multiple email addresses and phone numbers phone_number = next(iter(list(contact['phone_numbers'].values())), None) email = next(iter(list(contact['emails'].values())), None) print("Full Name: {} | Email: {} | Company Name: {} | Job Title: {} | Phone Number: {}".format( contact['given_name'] + " " + contact['surname'], email, contact['company_name'], contact['job_title'], phone_number, ))
{ "given_name": "Marie", "surname": "Curie", "job_title": "Physicist", "notes": "Status: Prospect", "office_location": "Warsaw, Poland", "company_name": "Radioactivity Inc.", "emails": [ { "email": "[email protected]", "type": "work" } ], "phone_numbers": [ { "number": "1 040 719 3466", "type": "mobile" } ], "picture_url": "https://api.nylas.com/contacts/abcd1234***/picture", "web_pages": [{ "type": "homepage", "url": "https://radioactivity.com" }], ... }
for prospect in external_prospects: # Search the user's contact book for any that have the email address of the event participant contacts = nylas.contacts.where(email=prospect).all() if contacts: contact = contacts[0] # Check to see if the contact already has a status statement in the notes field. if contact["notes"] and 'Status: ' in contact["notes"]: calendar_id = [ calendar['id'] for calendar in calendars if 'Prospect Meetings' in calendar['name'] ][0] all_events = nylas.events.where(calendar_id=calendar_id).all() for event in all_events: # Look for events on the calendar that include the prospect as a participant if prospect in [participant["email"] for participant in event["participants"]]: # Return the dates we previously met with the prospect in a human-readable format print("Met with {} on {}".format( prospect, datetime.datetime.fromtimestamp(event["when"]["start_time"]).strftime("%B %d, %Y - %H:%M:%S") )) else: # If we've never met with this prospect before, record our upcoming meeting as the first meeting we've had with them. contact.notes = "Status: Prospect\nFirst Meeting: {}".format( datetime.datetime.fromtimestamp(this_meeting[prospect]).strftime("%B %d, %Y - %H:%M:%S") ) contact.save()
Ben is the Developer Advocate for Nylas. He is a triathlete, musician, avid gamer, and loves to seek out the best breakfast tacos in Austin, Texas.