I’m trying to upload a text file (UTF-8) using the Powershell Invoke-RestMethod, but I am getting the “(415) Unsupported Media Type” error. This is my first time trying to interact with the Hubspot API.
I’m guessing this is related to a mismatch in what the endpoint is expecting and what you’re sending it. The 2 links you’ve provided in your question are for 2 separate API endpoints. You’ll need to craft your request body based on the endpoint you’re using. Here’s an example I successfully tested a while back using the v3 legacy docs endpoint. Note it’s in Python, but hopefully it’ll give you a template to translate from and do some further testing with:
import requests
import json
endpoint = 'https://api.hubapi.com/filemanager/api/v3/files/upload'
headers = {'Authorization': 'Bearer {{bearer_token}}'} # alternatively you could use your hapikey in the request URL query string for authentication
filename = 'test1.jpg'
file_options = {
'access': 'PRIVATE',
'ttl': 'P1M',
"overwrite": False,
'duplicateValidationStrategy': 'REJECT',
'duplicateValidationScope': 'EXACT_FOLDER'
}
files_data = {
'file': (filename, open(filename, 'rb'), 'application/octet-stream'),
'options': (None, json.dumps(file_options), 'text/strings'),
'folderPath': (None, '/parcelhub-attachments', 'text/strings')
}
response = requests.post(endpoint, headers=headers, files=files_data)
If you’d prefer to use POST /files/v3/files from the new API docs, you’ll need to craft your request body based on the “parameters” outlined under the relevant endpoint. Let me know how you get on.