Skip to content

v5.3.0

Compare
Choose a tag to compare
@mrashed-dev mrashed-dev released this 26 Nov 18:47
· 122 commits to main since this release

This new release of the Nylas Python SDK brings a slew of new features with support to many new Nylas APIs as well as new features to enhance existing models.

New Features

  • Add support for Scheduler API
  • Add support for Event notifications
  • Add support for Component CRUD
  • Add metadata support for Calendar, Message and Account

Enhancements

  • Improve error details returned from the API

Usage

Scheduler API

To create a new Scheduler page:

scheduler = nylas.scheduler.create()
scheduler.access_tokens = ["ACCESS_TOKEN"]
scheduler.name = "Python SDK Example"
scheduler.slug = "py_example_1"
scheduler.save()

To return all Scheduler pages:

scheduler_list = nylas.scheduler.all()

To return a single Scheduler page:

scheduler = nylas.scheduler.get('SCHEDULER_ID')

To update a Scheduler page:

scheduler = nylas.scheduler.get('SCHEDULER_ID')
scheduler.name = "Updated page name"
scheduler.save()

To delete a Scheduler page:

nylas.scheduler.delete('SCHEDULER_ID')

To get available calendars for a Scheduler page:

scheduler = nylas.scheduler.get('SCHEDULER_ID')
calendars = scheduler.get_available_calendars()

To upload an image:

scheduler = nylas.scheduler.get('SCHEDULER_ID')
scheduler.upload_image(content_type: "image/png", object_name: "test.png")

Checking Provider Availability

# Google Availability
google_availability = nylas.scheduler.get_google_availability()

# Office 365 Availability
o365_availability = nylas.scheduler.get_office_365_availability()

Get page information/configuration

page_config = nylas.scheduler.get_page_slug('slug')

Retrieve available time slots

available_timeslots = nylas.scheduler.get_available_time_slots('slug')

Book a time slot

slot = SchedulerTimeSlot.create(nylas)
slot.account_id = "test-account-id"
slot.calendar_id = "test-calendar-id"
slot.emails = ["[email protected]"]
slot.host_name = "Host"
slot.start = datetime.utcfromtimestamp(1636728347)
slot.end = datetime.utcfromtimestamp(1636731958)

timeslot_to_book = SchedulerBookingRequest.create(nylas)
timeslot_to_book.additional_values = {
    "test": "yes",
}
timeslot_to_book.email = "[email protected]"
timeslot_to_book.locale = "en_US"
timeslot_to_book.name = "Recipient Doe"
timeslot_to_book.timezone = "America/New_York"
timeslot_to_book.slot = slot

booking_confirmation = nylas.scheduler.book_time_slot("slug", timeslot_to_book)

Confirm a booking

booking_confirmation = nylas.scheduler.confirm_booking('slug', 'edit-hash');

Cancel a booking

nylas.scheduler.cancel_booking('slug', 'edit-hash', 'reason');

Event Notifications

To create a notification for an event:

from nylas import APIClient
nylas = APIClient(
    CLIENT_ID,
    CLIENT_SECRET,
    ACCESS_TOKEN
)

# Create a new event
event = nylas.events.create()

# Add notification details to the event
event.notifications = [
  {
    body: "Reminding you about our meeting.",
    minutes_before_event: 600,
    subject: "Test Event Notification",
    type: "email"
  },
  {
    type: "webhook",
    minutes_before_event: 600,
    url: "https://hooks.service.com/services/T01A03EEXDE/B01TBNH532R/HubIZu1zog4oYdFqQ8VUcuiW",
    payload: json.dumps({
      text: "Your reminder goes here!"
    })
  },
  {
    type: "sms",
    minutes_before_event: 60,
    message: "Test Event Notfication"
  }
]

To retrieve event notification details of an event:

# Get an event
event = nylas.events.get("EVENT_ID")

# Add notification details to the event
minutes_before_event = event.notifications[0].["minutes_before_event"]
type = event.notifications[0].["type"]
body = event.notifications[0].["body"]
url = event.notifications[0].["url"]
subject = event.notifications[0].["subject"]
payload = event.notifications[0].["payload"]
message = event.notifications[0].["message"]

To update an event with a notification:

# Get an event
event = nylas.events.get("EVENT_ID")

event.notifications = [{
    body: "Reminding you about our meeting.",
    minutes_before_event: 600,
    subject: "Test Event Notification",
    type: "email"
  }]
event.save()

To delete a notification from an event:

# Get an event
event = nylas.events.get("EVENT_ID")

event.notifications = []
event.save()

Component CRUD

To create a new component:

component = nylas.components.create()
component.name = "Python Component"
component.type = "agenda"
component.public_account_id = "ACCOUNT_PUBLIC_ID"
component.access_token = "ACCOUNT_ACCESS_TOKEN"
component.save()

To get all components:

components = nylas.components.all()

To get a specific component:

component = nylas.components.get("{COMPONENT_ID}")

To update a component:

component = nylas.components.get("{COMPONENT_ID}")
component.name = "Updated"
component.save()

To delete a component:

nylas.components.delete("{COMPONENT_ID}")

Expanded Metadata support

Adding Metadata to Calendar

calendar = nylas.calendars.create()
calendar.name = "My New Calendar"
calendar.description = "Description of my new calendar"
calendar.location = "Location description"
calendar.timezone = "America/Los_Angeles"
calendar.metadata = {
  "event_type": "gathering"
}
calendar.save()

# Or you can update a calendar with metadata

calendar = nylas.calendars.first()

calendar.metadata = {
  "event_type": "gathering"
}
calendar.save()

Query Calendars by Metadata

calendars = nylas.calendars.where(metadata_pair={event_type: "gathering"})

Adding Metadata to Message

message = nylas.messages.first()

message.metadata = {
  "test": "true"
}
message.save()

Adding Metadata to Account

account = api.accounts[0]

account.metadata = {
  "test": "true"
}
account.save()

Query Account by Metadata

accounts = api.accounts.where(metadata_key="test");