Created
September 3, 2024 12:49
-
-
Save addisonschultz/ea4b50e2dc57947751dc9a9b3803fa1f to your computer and use it in GitHub Desktop.
An example of Syncly's Node.js SDK
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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