Skip to content

v1.11.0

Choose a tag to compare

@mrashed-dev mrashed-dev released this 20 Jan 19:06
· 188 commits to main since this release

This release of the Nylas Java SDK brings forward a handful of new features, including support for our Scheduler API.

New Features

  • Added support for Scheduler API
  • Added support for calendar availability
  • Added support for Event to ICS file generation
  • Added support for modifying Folder
  • Expanded metadata support for Calendar, Account, Message, and Draft

New Contributors

This is a new section that will be used to highlight all the wonderful people who have provided their first contribution to this project!

  • @TDtianzhenjiu made their first contribution with Add metadata field for message (#43)

Using New Features

Scheduler API

To create a new Scheduler page:

Scheduler scheduler = new Scheduler();
scheduler.addAccessTokens("access.token");
scheduler.setName("Java SDK Example");
scheduler.setSlug("java_example");
nylas.schedulers().save(scheduler);

To return all Scheduler pages:

List<Scheduler> schedulerList = nylas.schedulers().list();

To return a single Scheduler page:

Scheduler scheduler = nylas.schedulers().get("SCHEDULER_ID");

To update a Scheduler page:

Scheduler scheduler = nylas.schedulers().get("SCHEDULER_ID");
scheduler.name = "Updated page name"
nylas.schedulers().save(scheduler);

To delete a Scheduler page:

nylas.schedulers().delete("SCHEDULER_ID");

To get available calendars for a Scheduler page:

Scheduler scheduler = nylas.schedulers().get("SCHEDULER_ID");
List<AvailableCalendars> availableCalendars = nylas.schedulers().getAvailableCalendars(scheduler.getId());

To upload an image:

Scheduler scheduler = nylas.schedulers().get("SCHEDULER_ID");
UploadImageResponse uploadImageResponse = nylas.schedulers().uploadImage(scheduler.getId(), "image/png", "test.png");

Checking Provider Availability

// Google Availability
List<ProviderAvailability> googleAvailability = nylas.schedulers().getGoogleAvailability();

// Office 365 Availability
List<ProviderAvailability> office365Availability = nylas.schedulers().getOffice365Availability();

Get page information/configuration

Scheduler page = nylas.schedulers().getPageBySlug(scheduler.getSlug());

Retrieve available time slots

List<TimeSlot> timeSlots = nylas.schedulers().getAvailableTimeSlots(scheduler.getSlug());

Book a time slot

TimeSlot slot = new TimeSlot();
slot.setAccountId("test-account-id");
slot.setCalendarId("test-calendar-id");
slot.setEmails(Collections.singletonList("[email protected]"));
slot.setHostName("Host");
slot.setStart(1636728347L);
slot.setEnd(1636728347L);

BookingRequest bookingRequest = new BookingRequest();
Map<String, Object> additionalValues = new HashMap<>();
additionalValues.put("important", true);
bookingRequest.setAdditionalValues(additionalValues);
bookingRequest.setEmail("[email protected]");
bookingRequest.setLocale("en_US");
bookingRequest.setName("John Doe");
bookingRequest.setTimezone("America/New_York");
bookingRequest.setSlot(slot);

BookingConfirmation bookingConfirmation = nylas.schedulers().bookTimeSlot("slug", bookingRequest);

Confirm a booking

BookingConfirmation bookingConfirmation = nylas.schedulers().confirmBooking("slug", "edit-hash");

Cancel a booking

nylas.schedulers().cancelBooking("slug", "edit-hash", "reason");

Checking Calendar Availability

To check availability for a single meeting

NylasClient nylas = new NylasClient();
NylasAccount account = nylas.account("{ACCESS_TOKEN}");
Calendars calendars = account.calendars();

// Prepare OpenHours for availability request
OpenHours openHours = new OpenHours();
openHours.setEmails(Collections.singletonList("[email protected]"));
openHours.setDays(Collections.singletonList(0));
openHours.setTimezone("America/Chicago");
openHours.setStart("10:00");
openHours.setEnd("14:00");

// Build availability request
SingleAvailabilityQuery query = new SingleAvailabilityQuery()
		.durationMinutes(30)
		.buffer(30)
		.startTime(Instant.now())
		.endTime(Instant.now().plus(1, ChronoUnit.HOURS))
		.emails(Collections.singletonList("[email protected]"));
		.intervalMinutes(5);

// Get availability
Availability availability = calendars.availability(query);

To check availability for a multiple meetings

NylasClient nylas = new NylasClient();
NylasAccount account = nylas.account("{ACCESS_TOKEN}");
Calendars calendars = account.calendars();

// Prepare emails for availability request
List<List<String>> emails = new ArrayList<>();
emails.add(Collections.singletonList("[email protected]"));
emails.add(Collections.singletonList("[email protected]"));

// Prepare OpenHours for availability request
OpenHours openHours = new OpenHours();
List<String> openHoursEmails = new ArrayList<>();
openHoursEmails.add("[email protected]");
openHoursEmails.add("[email protected]");
openHours.setEmails(openHoursEmails);
openHours.setDays(Collections.singletonList(0));
openHours.setTimezone("America/Chicago");
openHours.setStart("10:00");
openHours.setEnd("14:00");

// Build availability request
MultipleAvailabilityQuery consecutiveQuery = new MultipleAvailabilityQuery()
		.durationMinutes(30)
		.buffer(30)
		.startTime(Instant.now())
		.endTime(Instant.now().plus(1, ChronoUnit.HOURS))
		.emails(emails)
		.openHours(Collections.singletonList(openHours))
		.intervalMinutes(5);

// Get consecutive availability
List<List<ConsecutiveAvailability>> consecutiveAvailability = calendars.consecutiveAvailability(consecutiveQuery);

Generating an ICS from an Event

NylasClient nylas = new NylasClient();
NylasAccount account = nylas.account("{ACCESS_TOKEN}");
Events events = account.events();
Event event = events.get("{eventId}");

// You can make an ICS file from an event ID
String icsFromEventID = events.generateICS(event.getId());

// You can make an ICS file from an Event object
String icsFromEvent = events.generateICS(event);

// You can also pass ICS Options for more configuration
ICSOptions icsOptions = new ICSOptions();
icsOptions.setIcal_uid("test_uuid");
icsOptions.setMethod(ICSMethod.ADD);
icsOptions.setProdid("test_prodid");

String icsFromEventWithOptions = events.generateICS(event, icsOptions);

Modifying a Folder

NylasClient nylas = new NylasClient();
NylasAccount account = nylas.account("{ACCESS_TOKEN}");
Folders folders = account.folders();
Folder folder = folders.get("{folderId}");

folder.setDisplayName("Updated name");
folder.setName("sent");

Folder updated = folders.update(folder);

Expanded Metadata

Adding Metadata to Calendar

Calendar newCal = new Calendar();
newCal.setName("New Test Calendar");
newCal.setDescription("Testing calendar creation");
newCal.setLocation("far, far away");
newCal.setTimezone("America/Los_Angeles");

Map<String, String> metadata = new HashMap<>();
metadata.put("calendar_type", "test");
newCal.setMetadata(metadata);

Calendar created = calendars.create(newCal);

// Or you can update a calendar with metadata

Map<String, String> metadata = new HashMap<>();
metadata.put("calendar_type", "test");
calendar.setMetadata(metadata);
Calendar updatedCalendar = account.calendars().update(calendar);

Query Calendars by Metadata

CalendarQuery metadataQuery = new CalendarQuery().metadataKey("calendar_type");
List<Calendar> calendarsWithMetadata = account.calendars().list(metadataQuery).fetchAll();
Calendar calendar = calendarsWithMetadata.get(0);

Adding Metadata to Draft

Draft draft = new Draft();
Map<String, String> metadata = new HashMap<>();
metadata.put("message_type", "test");
draft.setMetadata(metadata);

Adding Metadata to Message

Map<String, String> metadata = new HashMap<>();
metadata.put("message_type", "test");
Message message = account.messages().setMetadata("{EXISTING_MESSAGE_ID}", metadata);

Adding Metadata to Account

Map<String, String> metadata = new HashMap<>();
metadata.put("account_type", "test");
Account account = account.accounts().setMetadata("{EXISTING_ACCOUNT_ID}", metadata);

Query Account by Metadata

AccountQuery metadataQuery = new AccountQuery().metadataKey("account_type");
List<Account> accountsWithMetadata = account.accounts().list(metadataQuery).fetchAll();
Account account = accountsWithMetadata.get(0);