Skip to content

Conversation

@NoamGitHub
Copy link
Collaborator

@NoamGitHub NoamGitHub commented Dec 18, 2025

🎯 Summary

This PR adds the ability to upload files to file columns on monday.com items using the SDK. It implements the multipart/form-data upload mechanism required by the Monday.com file upload API.

✨ Changes

New Features

  • ItemModule.upload_file_to_column() - New method to upload files to a file column on an item
  • MondayGraphQL.execute_multipart() - New method for executing GraphQL mutations with file uploads using multipart/form-data
  • FileInput dataclass - New type for encapsulating file upload parameters

Implementation Details

  • Added dedicated file upload endpoint constant (FILE_UPLOAD_URL = "https://api.monday.com/v2/file")
  • Follows the GraphQL multipart request specification
  • Automatic MIME type detection from file extension (with manual override option)
  • Debug mode support for multipart requests
  • Proper error handling with FileNotFoundError for missing files

📦 Files Changed

File Description
src/monday_sdk/modules/items.py Added upload_file_to_column() method
src/monday_sdk/graphql_handler.py Added execute_multipart() method
src/monday_sdk/types/file_input.py New FileInput dataclass
src/monday_sdk/types/__init__.py Export FileInput
src/monday_sdk/constants.py Added FILE_UPLOAD_URL constant

📖 Usage Example

import os
from datetime import datetime
from monday_sdk import MondayClient

# Initialize the client
client = MondayClient(os.getenv("MONDAY_TOKEN"))

# Configuration
BOARD_ID = 18392575661
FILE_COLUMN_ID = "file_mkyr6m1h"

# First, create an item (or use an existing item_id)
create_response = client.items.create_item(
    board_id=BOARD_ID,
    group_id="your_group_id",
    item_name="My Track",
    column_values={
        "text_column": "Artist Name",
        "date_column": {
            "date": datetime.now().strftime("%Y-%m-%d"),
            "time": datetime.now().strftime("%H:%M:%S")
        }
    }
)
item_id = create_response.data.create_item.id

# Upload a file to the file column
upload_response = client.items.upload_file_to_column(
    item_id=item_id,
    column_id=FILE_COLUMN_ID,
    file_path="https://github.com/path/to/your/file.mp4",
    mimetype="audio/mp4"  # Optional - auto-detected if not provided
)

print(f"File uploaded successfully!")
print(f"Asset ID: {upload_response['data']['add_file_to_column']['id']}")
print(f"File URL: {upload_response['data']['add_file_to_column']['url']}")

🔧 API Response

The upload_file_to_column() method returns a dictionary containing the uploaded asset information:

{
  "data": {
    "add_file_to_column": {
      "id": "123456789",
      "name": "file.mp4",
      "url": "https://files.monday.com/...",
      "file_extension": "mp4",
      "file_size": 1048576
    }
  }
}

⚠️ Notes

  • This feature uses a different API endpoint (/v2/file) than other SDK methods
  • The board_id is not required for file uploads - only item_id and column_id
  • MIME type is automatically detected from the file extension if not explicitly provided
  • Large files are streamed to avoid memory issues

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants