Skip to main content

Hi everyone, I am using a code block in zapier to add an attachment to a google calendar event that already exists. I am however getting the output_missing error and have no idea how to fix it. Can anyone help please?

 

I am trying to do everything in the code block without needing to run scripts on my own server.

 

Below is my code:

 

import os
import json
import requests

# Your Google Calendar ID
CALENDAR_ID = 'emailaddressgoeshere.com'

# Function to update Google Calendar event with file link as an attachment
def update_calendar_event(event_id, drive_file_url):
    # Replace 'your-api-key' with your actual Google API Key
    api_key = 'your-api-key'

    # Get the current event data
    response = requests.get(
        f'https://www.googleapis.com/calendar/v3/calendars/{CALENDAR_ID}/events/{event_id}?key={api_key}'
    )
    event = response.json()

    # Add the file link as an attachment
    attachment = {
        'fileUrl': drive_file_url,
        'title': 'File Attachment',
    }

    if 'attachments' in event:
        eventm'attachments'].append(attachment)
    else:
        eventm'attachments'] = lattachment]

    # Update the event
    response = requests.put(
        f'https://www.googleapis.com/calendar/v3/calendars/{CALENDAR_ID}/events/{event_id}?key={api_key}',
        headers={'Content-Type': 'application/json'},
        data=json.dumps(event)
    )

    if response.status_code == 200:
        result_message = f"Event updated with file attachment: {response.json().get('htmlLink')}"
        return {'text': result_message}
    else:
        error_message = f"Error updating event: {response.status_code} - {response.text}"
        return {'text': error_message}

# Example usage
if __name__ == '__main__':
    # Replace ‘event_id_goes_here' with the actual ID of the event you want to update
    event_id_to_update = ‘event_id_goes_here'
    
    # Replace 'your-drive-file-url' with the actual URL of the file you uploaded to Google Drive
    drive_file_url = 'your-drive-file-url'

    output_data = update_calendar_event(event_id_to_update, drive_file_url)
    print(json.dumps(output_data))
 

Hi @gldc 

Good question.

Instead, you may want to try creating a custom action with the help of AI.