Issue with Uploading Images to HubSpot via API - FOLDER_DUPLICATE and Validation Errors
Background: I'm working on a Python script that automates the uploading of images to specific folders in HubSpot. The process involves creating folders (if they don't exist) and uploading images into these folders.
Problem: During the image upload process, I encounter a recurring issue where the API returns a 409 FOLDER_DUPLICATE error when attempting to upload multiple images to a folder that already exists. Even when I handle the existing folder case by retrying the upload without re-creating the folder, the process fails with various errors, including:
409 FOLDER_DUPLICATE: This occurs even after attempting to handle the folder's existence and retrying the upload without folder creation.
400 VALIDATION_ERROR: When omitting the folderPath to avoid the duplicate error, the API returns a 400 error indicating that either folderId or folderPath is required.
Key Errors Encountered:
1. 409 FOLDER_DUPLICATE Error:
{
"status": "error",
"message": "A folder already exists at this path",
"errorType": "FOLDER_DUPLICATE",
"errorTokens": {
"fullPath": ["/library/docs_media/FolderName"],
"id": ["176092833175"]
},
"correlationId": "9a28b68e-781c-491f-a527-8ff8fc19dd6f"
}
2. 400 VALIDATION_ERROR:
{
"status": "error",
"message": "Either folderId or folderPath is required",
"correlationId": "3f5a6a78-9917-4489-81c8-cb34bcc902dc",
"context": {
"folderId or folderPath": ["false"]
},
"category": "VALIDATION_ERROR"
}
What I’ve Tried:
Retrying Upload Without Folder Creation: After receiving the 409 FOLDER_DUPLICATE error, I attempted to retry the upload without specifying the folderPath, expecting the API to upload directly into the existing folder. However, this led to the 400 VALIDATION_ERROR, indicating that either folderId or folderPath is required.
Duplicate Validation Strategy: I tried using duplicateValidationScope: "EXACT_FOLDER" and duplicateValidationStrategy: "RETURN_EXISTING" options, but these didn't resolve the issue.
Skipping folderPath on Retry: Attempted to omit folderPath on the retry to prevent re-triggering the folder creation logic, but this also led to errors.
Questions:
Is there a reliable way to manage folder existence and subsequent file uploads in HubSpot via the API?
How can I correctly manage the folderPath to avoid FOLDER_DUPLICATE errors while ensuring all images are uploaded?
Are there best practices for handling such scenarios where multiple files need to be uploaded to the same folder in HubSpot?
Any insights or suggestions from the community would be greatly appreciated!
Additional Context:
The script's goal is to upload a series of images to HubSpot, placing them in a designated folder structure.
Ensuring that all images are accessible and correctly placed in the specified folder is crucial for the process.