Skip to content

Instantly share code, notes, and snippets.

@addisonschultz
Created September 3, 2024 12:49
Show Gist options
  • Save addisonschultz/ea4b50e2dc57947751dc9a9b3803fa1f to your computer and use it in GitHub Desktop.
Save addisonschultz/ea4b50e2dc57947751dc9a9b3803fa1f to your computer and use it in GitHub Desktop.
An example of Syncly's Node.js SDK
// Import the Syncly SDK
const Syncly = require('syncly');
// Initialize Syncly client with authentication (example)
const client = new Syncly.Client({
apiKey: 'your-api-key-here'
});
// Function to create a new calendar and event
async function createCalendarAndEvent(calendarName, eventTitle, eventStart, eventEnd) {
try {
// Create a new calendar
const newCalendar = await client.calendar.create({
name: calendarName
});
console.log('Calendar created:', newCalendar);
// Create a new event in the newly created calendar
const newEvent = await client.event.create({
calendarId: newCalendar.id,
title: eventTitle,
startTime: eventStart,
endTime: eventEnd
});
console.log('Event created:', newEvent);
return { newCalendar, newEvent };
} catch (error) {
console.error('Error creating calendar or event:', error);
throw error;
}
}
// Usage example
createCalendarAndEvent(
'Team Meetings',
'Syncly Product Update',
'2024-09-05T10:00:00Z',
'2024-09-05T11:00:00Z'
).then(response => {
console.log('Success:', response);
}).catch(err => {
console.error('Failed:', err);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment