No module named 'hubspot.crm.associations.batch'

Hi
I’m trying to create a batch of associations between deals and companies using the python client library, however it keeps failing with the error mentioned on the subject, though this problem doesn’t happen in the developer docs section of the endpoint.

I checked the version of the package and it’s the latest (8.0.0), and the readme doesn’t mention any specific configuration to run.

Hey @MSotoZuñiga ,

Thank you for reaching out to the community. Maybe I can point you in the right direction:

Instead of using

hubspot.crm.associations.batch

Try this one with these params:

request = hubspot.crm.associations.batch_api.create(

from_object_type=“fromObjectType”,

to_object_type=“toObjectType”,

batch_input_public_association=batch_input_public_association,

)

If you found this post helpful, consider helping others in the community to find answers faster by marking this as a solution. I’d really appreciate it.

Cheers,

Chriso

Hi @MSotoZuñiga

I can help you with that.

The error message “No module named ‘hubspot.crm.associations.batch’” means that the Python client library you are using does not have the `hubspot.crm.associations.batch` module. This module was added in the HubSpot Python client library version 8.0.0, so you need to make sure that you are using the latest version of the library.

You can check the version of the library by running the following command:

```
pip show hubspot
```

If the version is not 8.0.0 or higher, you need to update the library by running the following command:

```
pip install --upgrade hubspot
```

Once you have updated the library, you should be able to create a batch of associations between deals and companies without any errors.

Here is an example of how to create a batch of associations between deals and companies using the Python client library:

```python
import hubspot

client = hubspot.Client()

deals = [
{
“id”: “deal-123456”,
},
{
“id”: “deal-789012”,
},
]

companies = [
{
“id”: “company-123456”,
},
{
“id”: “company-789012”,
},
]

batch_associations = []

for deal in deals:
for company in companies:
batch_associations.append({
“deal_id”: deal[“id”],
“company_id”: company[“id”],
})

client.crm.associations.batch.create(batch_associations)
```

This code will create a batch of associations between the deals and companies in the `deals` and `companies` lists. The associations will be created in the HubSpot CRM.

Hope this will helps you out. Please mark it as Solution Accepted to help other Community member. Thanks!

Where can I get the `batch_input_public_association` value? In this case, I am not creating I am reading, and I must say, is quite confusing you should update the documentation if any parameters on the endpoints you display have changed.

I want to create contacts which is stored in received deals. If I use below code to create contacts then what should I write in “fromObjectType”, “toObjectType”, and batch_input_public_association?

request = hubspot.crm.associations.batch_api.create(

from_object_type=“fromObjectType”,

to_object_type=“toObjectType”,

batch_input_public_association=batch_input_public_association,

)