Add_file_to_column API

Hey guys,

I am trying to build up a query to upload a file into a certain column. However I am having trouble.

Any help is highly appreciated.

ERROR:app:File upload failed: {“status_code”:400,“error_message”:“Unsupported query”,“errors”:[{“message”:“Unsupported query”,“extensions”:{“status_code”:400}}]}

if file and allowed_file(file.filename):
                
                filename = secure_filename(file.filename)
                logger.info(f"Uploading file: {filename} to item: {item_id}")
                # Use the same API_KEY that's already defined at the top of the file
                try:
                    # Save file temporarily
                    temp_dir = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'temp')
                    os.makedirs(temp_dir, exist_ok=True)
                    temp_path = os.path.join(temp_dir, filename)
                    file.save(temp_path)
                    
                    # First upload the file to Monday.com's file storage
                    headers = {"Authorization": API_KEY, 'API-version':'2023-10'}
                    url = "https://api.monday.com/v2/file"
                    mutation_query = f"""
                        mutation ($file: File!){{
                            add_file_to_column (
                                item_id: 7815005218,
                                column_id: "file_mkp3rd8p",
                                file: $file
                            ) {{
                                id
                            }},
                            "map": "{{\\"file\\":\\"variables.file\\"}}"
                        }}
                    """
                    files = {
                        'query': (None, mutation_query),
                        'variables': (None, '{"file": null}'),
                        'file': (filename, open(temp_path, 'rb'), 'multipart/form-data')
                    }
                    response = requests.post(url, headers=headers, files=files)                               
                    
                    ```
1 reply