# Python: How do I create an Email with associations in one call?

**URL:** <https://community.hubspot.com/t/python-how-do-i-create-an-email-with-associations-in-one-call/79837>\
**Category:** APIs & Integrations\
**Tags:** free\
**Created:** [April 21, 2023, 4:27pm UTC](https://community.hubspot.com/t/python-how-do-i-create-an-email-with-associations-in-one-call/79837 "2023-04-21T16:27:54Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![wollivier](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/wollivier/32/198408_2.png) [@wollivier](https://community.hubspot.com/u/wollivier)\
**Post date:** [April 21, 2023, 4:27pm UTC](https://community.hubspot.com/t/python-how-do-i-create-an-email-with-associations-in-one-call/79837/1 "2023-04-21T16:27:54Z")

</div>

According to the API documentation on Emails ([Accounts Dashboard | HubSpot](https://developers.hubspot.com/docs/api/crm/email)), it is possible to create an email with properties AND associations in 1 call.  
I’m using the official python client (latest version as of 21 Apr 2023), and using the `hs.crm.objects.emails.basic_api.create(input)` call to create my emails.  
The `create` method accepts one parameter, of type `hubspot.crm.objects.emails.SimplePublicObjectInput`, but this object only accepts `properties` as a parameter, no `associations`.  
As a result, I’m having to make 1 call to create the email, then 1 call to create an association to the ticket.  
It takes a lot of time, and a lot of API calls.  
I would much rather use the email batch API, and create all my emails at a go, along with their associations.  
Could you please let me know how to do that with the official python client?  
Thanks

---

<div class="post-metadata">

**Author:** ![MiaSrebrnjak](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/miasrebrnjak/32/10_2.png) [@MiaSrebrnjak](https://community.hubspot.com/u/MiaSrebrnjak)\
**Post date:** [April 24, 2023, 5:15pm UTC](https://community.hubspot.com/t/python-how-do-i-create-an-email-with-associations-in-one-call/79837/2 "2023-04-24T17:15:28Z")

</div>

Hi @wollivier,

Thank you for reaching out to the Community!

I wanted to tag in a couple of subject matter experts to see if they have any advice:

Hi @ChrisoKlepke, @taran42, do you have any tips for @wollivier? Thank you!!

Cheers  
Mia, Community Team

---

<div class="post-metadata">

**Author:** ![ChrisoKlepke](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/chrisoklepke/32/11213_2.png) [@ChrisoKlepke](https://community.hubspot.com/u/ChrisoKlepke)\
**Post date:** [April 25, 2023, 1:43pm UTC](https://community.hubspot.com/t/python-how-do-i-create-an-email-with-associations-in-one-call/79837/3 "2023-04-25T13:43:48Z")

</div>

Thank you for tagging me @MiaSrebrnjak .

Hey @wollivier,

it took me a minute, but I was able to test this successfully. The documentation apparently is a bit old in that regard. What you want to use is SimplePublicObjectWithAssociations and use the kwarg simple\_public\_object\_input on the create method. Here is what that would more or less look like:

```lia-code-sample
properties = {
 "hs_timestamp": "2019-10-30T03:30:17.883Z",
 "hs_email_direction": "EMAIL",
 "hs_email_status": "SENT",
 "hs_email_subject": "Let's talk",
 "hs_email_text": "Thanks for taking your interest let's find a time to connect",
}

associations = [
 {
 "to": {"id": "3301"},
 "types": [{"associationCategory": "HUBSPOT_DEFINED", "associationTypeId": 10}],
 }
]
foo = SimplePublicObjectWithAssociations(
 properties=properties, associations=associations
)

try:
 api_response = client.crm.objects.emails.basic_api.create(
 simple_public_object_input=foo
 )
 pprint(api_response)
except ApiException as e:
 print("Exception when calling basic_api->create: %s\n" % e)

```

I’ve tested this under version 7.5.0. Hope this helps, mate.

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

---

<div class="post-metadata">

**Author:** ![wollivier](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/wollivier/32/198408_2.png) [@wollivier](https://community.hubspot.com/u/wollivier)\
**Post date:** [April 26, 2023, 4:13pm UTC](https://community.hubspot.com/t/python-how-do-i-create-an-email-with-associations-in-one-call/79837/4 "2023-04-26T16:13:26Z")

</div>

Thanks Chriso-mwx!  
I can confirm it works flawlessly, and as a result I was able to halve the number of requests.  
As a matter of fact, this also applies to the `batch_api` as well, so I was able to leverage creating emails and notes in batches, already associated to the correct tickets!  
Good stuff!

---

<div class="post-metadata">

**Author:** ![ChrisoKlepke](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/chrisoklepke/32/11213_2.png) [@ChrisoKlepke](https://community.hubspot.com/u/ChrisoKlepke)\
**Post date:** [April 27, 2023, 8:51am UTC](https://community.hubspot.com/t/python-how-do-i-create-an-email-with-associations-in-one-call/79837/5 "2023-04-27T08:51:18Z")

</div>

Thank you for the wonderful feedback, mate! Glad I was able to help you out.

Have fun developing,

Chriso
