Deals API invalid associations error

deals
developertools

#1

Having some issues trying to create a deal via the API. The error message is…

"{"status":"error","message":"one or more associations were invalid","correlationId":"3c060eb3-fc61-4326-9dcb-c73a6eeb794f","requestId":"8f92e9b9229d5eac0ec73615a99a134c"}"

I’m under the impression associatedCompanyIds is an array of INTs being the organization ID and associatedVids is an array of INTs with the contact IDs. I’ve confirmed these IDs by using the URL to the direct contact.

https://app.hubspot.com/contacts/29***84/contact/44351/

Here’s the entire JSON I’m posting to the endpoint.

{
          "associations": {
            "associatedCompanyIds": [
              29***84
            ],
            "associatedVids": [
              44351
            ]
          },
          "properties": [
            {
              "value": "Phil's Newer Deal",
              "name": "dealname"
            },
            {
              "value": "created",
              "name": "dealstage"
            },
            {
              "value": "default",
              "name": "pipeline"
            },
            {
              "value": 1409443200000,
              "name": "closedate"
            },
            {
              "value": "60000",
              "name": "amount"
            },
            {
              "value": "newbusiness",
              "name": "dealtype"
            }
          ]
        }

#2

Hi @wwwroth,

An invalid association error often means that there is no company/contact that corresponds to the companyId/vid provided. Based on the asterisks, am I correct in guessing that the number you’re including in the assocaitedCompanyIds field is the Hub ID of the portal you’re creating the deal in? The associatedCompanyIds field should instead include the companyId of a company record that the deal object should be associated with.


#3

Hi @Derek_Gervais, you’re correct. I copied the company ID and associated contact ID right from the URL of the contact I’m testing with and triple checked it.

Here’s the JSON object again and and the URL I’m getting the IDs from.

{"associations":{"associatedCompanyIds":[2980484],"associatedVids":[43251]},"properties":[{"value":"test","name":"dealname"},{"value":"open","name":"dealstage"},{"value":"default","name":"pipeline"},{"value":"","name":"hubspot_owner_id"},{"value":"1409443200000","name":"closedate"},{"value":"65.79","name":"amount"},{"value":"newbusiness","name":"dealtype"}]}

https://app.hubspot.com/contacts/2980484/contact/43251/

I’ve noticed if I remove the associations object from the request it will work and create a rogue deal not assigned to either a company or a contact. I still get the error when putting in the correct values. Is there a case when a contact or company cannot be assigned a deal within HubSpot and that may be triggering the error?

Edit: I figured it out. I have multiple HubSpot licenses and I thought associatedCompanyId was OUR portal ID instead of the actual contact’s company ID within HubSpot.