#Updating associations programmatically via python SDK

3 messages · Page 1 of 1 (latest)

keen jungle
#

I'm trying to update an existing database document's many-to-many assocation via a function but keep getting a Server Error whenever I attempt this code:

def associate_video_to_playlist(playlist_url, video_id):
    playlist_document_id = get_appwrite_playlist_document(playlist_url)['$id']
    video_document = get_appwrite_youtube_video_document(video_id)
    result = documents.update_document(
        APPWRITE_DATABASE_ID,
        YOUTUBE_PLAYLIST_COLLECTION_ID,
        playlist_document_id,
        {
            'youtubeVideo': video_document
        }
    )
    # print(f'playlist document: {playlist_document["youtubeVideo"]}')

    return playlist_document_id

I'm not sure whether to provide the ID of the associated document, the object itself, or what. I've checked permissions for all associated content.

keen jungle
#

Nm, I was not wrapping the associations into a [] list - it'd be great if server errors were a little more verbose to assist with debugging

maiden grove