Skip to content

Instantly share code, notes, and snippets.

@erickoledadevrel
Created February 19, 2016 14:38
Show Gist options
  • Save erickoledadevrel/79ee7799485bec141ee4 to your computer and use it in GitHub Desktop.
Save erickoledadevrel/79ee7799485bec141ee4 to your computer and use it in GitHub Desktop.
Create a Google Calendar event with an attachment in Apps Script
function createEventWithAttachment() {
var driveFileId = '...';
var file = DriveApp.getFileById(driveFileId);
var event = {
summary: 'Test Event with Attachments',
description: 'Woot!',
attachments: [{
fileId: driveFileId,
fileUrl: file.getUrl(),
mimeType: file.getMimeType(),
title: file.getName()
}],
start: {
dateTime: '2016-02-18T17:00:00',
timeZone: 'America/New_York'
},
end: {
dateTime: '2016-02-18T18:00:00',
timeZone: 'America/New_York'
}
};
Calendar.Events.insert(event, 'primary', {
supportsAttachments: true
});
}
@oshliaer
Copy link

Like Gmail API

@zphdude
Copy link

zphdude commented Mar 11, 2019

How would you create an event that would have an unknown amount of attachments? I have been searching for a loop for the attachment field. and have been unlucky in my inquiry.

@kngwizrd
Copy link

i have a problem with this,
in line 22 i get the following error: GoogleJsonResponseException: API call to calendar.events.insert failed with error:.
any input on what that could be? i've no clue honestly

@erickoledadevrel
Copy link
Author

Make you you've enabled the Calendar advanced service and have toggled it on in your Cloud project.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment