Instructions to Send Files to the HubSpot File System

Guidelines to send files to HubSpot

File Naming Convention

  • File Naming Convention: {object-type}-{date/time}.csv
  • Object type to be the primary object in the CSV
  • Date to be in this format YYYY-MM-DD
  • Example: deal-2025-02-27

Guidelines

  • Set the Access to Private
    • PRIVATE access is important so that the files can only be accessed by HubSpot users with the required permissions
  • Set Overwrite to True
    • overwrite=True is helpful so that if an upload is triggered twice it just replaces the file instead of failing
  • JSON dumps (Python)
    • json.dumps is important here too. options should be a json string when sent to the API, not a dictionary

Instructions

import json

import httpx

folder_id = 123
# file names should be dynamic but programatic, would suggest it being something like {object-type}-{relevant date/datetime}.csv

file_name = "{object-type}-{relevant date/datetime}.csv"
file_bytes = b''
auth_token = "<token>"

payload = {
    "fileName": file_name,
    "folderId": folder_id,
    "options": json.dumps(
        {
            "access": "PRIVATE",
            "overwrite": True,

        }
    ),
}
# PRIVATE access is important so that the files can only be accessed by HubSpot users with the required permissions
# overwrite=True is helpful so that if an upload is triggered twice it just replaces the file instead of failing
# json.dumps is important here too. options should be a json string when sent to the API not a dictionary


response = httpx.post(
    url="https://api.hubapi.com/files/v3/file",
    headers={"Authorization": f"Bearer {auth_token}"},
    data=payload,
    files={"file": file_bytes},
)