CRM

SLear
Member

Lead to Primary Company Association - Creating leads via the API

SOLVE

Hi,

 

I need to bulk import some leads into HubSpot as part of moving over our B2B sales team. There is no import option on the front end so I'm looking to sort this via the API.

 

I've got a script setup to loop through some names etc and I have the company_id for each lead I want to create. So far, my main function is as follows. 

def create_lead(lead_name, company_id):
    headers = {
        'Content-Type': 'application/json',
        'Authorization': f'Bearer {HUBSPOT_API_KEY}'
    }
    data = {
        'associations': [
            {
                'types': [
                    {
                        'associationCategory': 'HUBSPOT_DEFINED',
                        'associationTypeId': 610
                    }
                ],
                'to': {
                    'id': company_id
                }
            }
        ],
        'properties': {
            'hs_lead_name': lead_name,
            'hs_pipeline': 'b2b leads',
        }
    }

 The association I'm using is the only reference I can find in the docs for Lead-to-Object and is for the lead-to-company association. However, when this runs, I'm getting the error:

Status Code: 400, Response: {"status":"error","message":"A LEAD_TO_PRIMARY_CONTACT or LEAD_TO_PRIMARY_COMPANY association is required to create a LEAD object.","correlationId":"dc9bd360-d52f-4a8a-b692-0394a6b5d427","category":"VALIDATION_ERROR"}

 

I can't find any reference to LEAD_TO_PRIMARY_COMPANY in the docs or in the admin/ setting pages in our HubSpot so really at a loss on how to solve.

 

Does anyone have any ideas?

0 Upvotes
2 Accepted solutions
dsmarion
Solution
Top Contributor | Gold Partner
Top Contributor | Gold Partner

Lead to Primary Company Association - Creating leads via the API

SOLVE

There is an API endpoint to find association types - if I use this to ask for association types for a lead to a company it returns this:

HTTP 200

{
"results": [
{
"id": "610",
"name": "lead_to_company"
},
{
"id": "580",
"name": "lead_to_primary_company"
}
]
}

This endpoint is very useful when you need the ID of an assocation type.

https://developers.hubspot.com/beta-docs/reference/api/crm/associations/associations-schema/v3#get-%...

Scott Marion
Senior Developer @ Thread Connected Marketing

View solution in original post

aviafriat26
Solution
Participant | Diamond Partner
Participant | Diamond Partner

Lead to Primary Company Association - Creating leads via the API

SOLVE

@SLearIt looks like HubSpot requires a specific "LEAD_TO_PRIMARY_COMPANY" association to create a lead via the API. The associationTypeId you’re using (610) might not match this requirement.

 

Try replacing associationTypeId: 610 with the correct ID for LEAD_TO_PRIMARY_COMPANY. Unfortunately, HubSpot doesn’t always document these IDs clearly. You might need to retrieve the association types via the API (/crm/v4/associations) to confirm the correct ID.

 

Another option is to contact HubSpot support to confirm the exact association ID needed for "LEAD_TO_PRIMARY_COMPANY."

 

Let me know if this helps!

 

Best,

 

Meet with Michael

Avi Afriat

View solution in original post

2 Replies 2
aviafriat26
Solution
Participant | Diamond Partner
Participant | Diamond Partner

Lead to Primary Company Association - Creating leads via the API

SOLVE

@SLearIt looks like HubSpot requires a specific "LEAD_TO_PRIMARY_COMPANY" association to create a lead via the API. The associationTypeId you’re using (610) might not match this requirement.

 

Try replacing associationTypeId: 610 with the correct ID for LEAD_TO_PRIMARY_COMPANY. Unfortunately, HubSpot doesn’t always document these IDs clearly. You might need to retrieve the association types via the API (/crm/v4/associations) to confirm the correct ID.

 

Another option is to contact HubSpot support to confirm the exact association ID needed for "LEAD_TO_PRIMARY_COMPANY."

 

Let me know if this helps!

 

Best,

 

Meet with Michael

Avi Afriat
dsmarion
Solution
Top Contributor | Gold Partner
Top Contributor | Gold Partner

Lead to Primary Company Association - Creating leads via the API

SOLVE

There is an API endpoint to find association types - if I use this to ask for association types for a lead to a company it returns this:

HTTP 200

{
"results": [
{
"id": "610",
"name": "lead_to_company"
},
{
"id": "580",
"name": "lead_to_primary_company"
}
]
}

This endpoint is very useful when you need the ID of an assocation type.

https://developers.hubspot.com/beta-docs/reference/api/crm/associations/associations-schema/v3#get-%...

Scott Marion
Senior Developer @ Thread Connected Marketing