How do you add deal collaborator through the API

Hi,

It seems undocumented amd I looked in the postman collection with no success.

How do you add deal collaborator to a deal using the REST API ?
I have tried something like

from hubspot import HubSpot 

hubspot_client = HubSpot(access_token="UNDISCOLED") 

hubspot_client.api_request({"method": "PUT", "path": "/deal-execution/v1/deal-collaborators/32736363846", "body": {"ownerIds":["75017528","76146015"]}}) 

But I have the following error:

{
 "status": "error",
 "message": "Any of the listed authentication credentials are missing",
 "correlationId": "ea604e58-fd68-6a64-b41a-85a519c6c029",
 "engagement": {
 "service-to-service": "service-to-service not engaged. Metadata for service-to-service request not found.",
 "internal-cookie": "internal-cookie not engaged. You can get a new internal auth cookie for host 'api.hubapi.com' by visiting following link from your current browser window: https://tools.hubteam.com/login/host/api.hubapi.com .",
 "app-cookie": "app-cookie not engaged. App cookie is not present on the request."
 }
}

Hey @DavidM3 where did you get that endpoint from? I can’t find any documentation to say this is a public endpoint, the error message would point me to believing this endpoint is internal auth only (IE only HubSpot internal tools can use) and I can’t see this endpoint on the developer docs to say adding collaborators is a supported feature to update externally.

Thanks for your quick reply. I had found at that some endpoints are not perfectly documented, so I had to look into the actual call in the hubspot app.
But in this case you are right, it must an internal api that is used.

Theoritically there is a way to add collaborators through the public API, using the imports API (there is section in the knowledge base with a case mentioning the deal collaborator use case).
Here is some useful sample code

import tempfile
import os
import csv
import hubspot

hubspot_client = hubspot.HubSpot(access_token="REDACTED") 
import_request_metadata = {
 "name": "test.csv",
 "importOperations": {"0-1": "UPSERT"},
 "dateFormat": "DAY_MONTH_YEAR",
 "files": [
 {
 "fileName": "test.csv",
 "fileFormat": "CSV",
 "dateFormat": "YEAR_MONTH_DAY",
 "fileImportPage": {
 "hasHeader": True,
 "columnMappings": [
 {
 "columnObjectTypeId": "0-3",
 "columnName": "Record ID",
 "propertyName": "hs_object_id",
 "columnType": "HUBSPOT_OBJECT_ID",
 },
 {
 "columnObjectTypeId": "0-3",
 "columnName": "Deal Collaborator ID",
 "propertyName": "hs_all_collaborator_owner_ids",
 },
 ],
 }
 }
 ],
 }
# Create a temporary file with a unique name
temp_dir = tempfile.gettempdir()
# Use the first ID for the filename to keep it simple
filename = "testcsv"
filepath = os.path.join(temp_dir, filename)

with open(filepath, "w", newline="") as csvfile:
 writer = csv.writer(csvfile)
 # Write header
 writer.writerow(["Record ID", "Deal Collaborator"])
 # Join all IDs with semicolons
 # Write data
 writer.writerow(["279939983", "123;123"])

logger.debug(f"Created CSV file at {filepath}")
hubspot_client.crm.imports.core_api.create(files=filepath, import_request=import_request_metadata)
# Uncomment to delete the file
# os.remove(filepath)