<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic Re: Python: How do I create an Email with associations in one call? in APIs &amp; Integrations</title>
    <link>https://community.hubspot.com/t5/APIs-Integrations/Python-How-do-I-create-an-Email-with-associations-in-one-call/m-p/786117#M63480</link>
    <description>&lt;P&gt;Thank you for tagging me&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/101262"&gt;@MiaSrebrnjak&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/557176"&gt;@wollivier&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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&amp;nbsp;SimplePublicObjectWithAssociations and use the kwarg&amp;nbsp;simple_public_object_input on the create method. Here is what that would more or less look like:&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;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-&amp;gt;create: %s\n" % e)
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tested this under version 7.5.0. Hope this helps, mate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Chriso&lt;/P&gt;</description>
    <pubDate>Tue, 25 Apr 2023 13:43:48 GMT</pubDate>
    <dc:creator>ChrisoKlepke</dc:creator>
    <dc:date>2023-04-25T13:43:48Z</dc:date>
    <item>
      <title>Python: How do I create an Email with associations in one call?</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Python-How-do-I-create-an-Email-with-associations-in-one-call/m-p/785005#M63478</link>
      <description>&lt;P&gt;According to the API documentation on Emails (&lt;A href="https://developers.hubspot.com/docs/api/crm/email" target="_blank"&gt;https://developers.hubspot.com/docs/api/crm/email&lt;/A&gt;), it is possible to create an email with properties AND associations in 1 call.&lt;BR /&gt;&lt;BR /&gt;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.&lt;BR /&gt;The `create` method accepts one parameter, of type `hubspot.crm.objects.emails.SimplePublicObjectInput`, but this object only accepts `properties` as a parameter, no `associations`.&lt;BR /&gt;&lt;BR /&gt;As a result, I'm having to make 1 call to create the email, then 1 call to create an association to the ticket.&lt;BR /&gt;&lt;BR /&gt;It takes a lot of time, and a lot of API calls.&lt;BR /&gt;&lt;BR /&gt;I would much rather use the email batch API, and create all my emails at a go, along with their associations.&lt;BR /&gt;&lt;BR /&gt;Could you please let me know how to do that with the official python client?&lt;BR /&gt;&lt;BR /&gt;Thanks&lt;/P&gt;</description>
      <pubDate>Fri, 21 Apr 2023 16:27:54 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Python-How-do-I-create-an-Email-with-associations-in-one-call/m-p/785005#M63478</guid>
      <dc:creator>wollivier</dc:creator>
      <dc:date>2023-04-21T16:27:54Z</dc:date>
    </item>
    <item>
      <title>Betreff: Python: How do I create an Email with associations in one call?</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Python-How-do-I-create-an-Email-with-associations-in-one-call/m-p/785706#M63479</link>
      <description>&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/557176"&gt;@wollivier&lt;/a&gt;,&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Thank you for reaching out to the Community!&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I wanted to tag in a couple of subject matter experts to see if they have any advice:&lt;/P&gt;
&lt;P&gt;Hi&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/241684"&gt;@ChrisoKlepke&lt;/a&gt;,&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/144301"&gt;@taran42&lt;/a&gt;, do you have any tips for&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/557176"&gt;@wollivier&lt;/a&gt;? Thank you!!&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers&lt;BR /&gt;Mia, Community Team&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 24 Apr 2023 17:15:28 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Python-How-do-I-create-an-Email-with-associations-in-one-call/m-p/785706#M63479</guid>
      <dc:creator>MiaSrebrnjak</dc:creator>
      <dc:date>2023-04-24T17:15:28Z</dc:date>
    </item>
    <item>
      <title>Re: Python: How do I create an Email with associations in one call?</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Python-How-do-I-create-an-Email-with-associations-in-one-call/m-p/786117#M63480</link>
      <description>&lt;P&gt;Thank you for tagging me&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/101262"&gt;@MiaSrebrnjak&lt;/a&gt;&amp;nbsp;.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Hey&amp;nbsp;&lt;a href="https://community.hubspot.com/t5/user/viewprofilepage/user-id/557176"&gt;@wollivier&lt;/a&gt;,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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&amp;nbsp;SimplePublicObjectWithAssociations and use the kwarg&amp;nbsp;simple_public_object_input on the create method. Here is what that would more or less look like:&amp;nbsp;&lt;/P&gt;
&lt;LI-CODE lang="python"&gt;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-&amp;gt;create: %s\n" % e)
&lt;/LI-CODE&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I've tested this under version 7.5.0. Hope this helps, mate.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;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.&amp;nbsp;&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Cheers,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Chriso&lt;/P&gt;</description>
      <pubDate>Tue, 25 Apr 2023 13:43:48 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Python-How-do-I-create-an-Email-with-associations-in-one-call/m-p/786117#M63480</guid>
      <dc:creator>ChrisoKlepke</dc:creator>
      <dc:date>2023-04-25T13:43:48Z</dc:date>
    </item>
    <item>
      <title>Re: Python: How do I create an Email with associations in one call?</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Python-How-do-I-create-an-Email-with-associations-in-one-call/m-p/786749#M63484</link>
      <description>&lt;P&gt;Thanks Chriso-mwx!&lt;BR /&gt;&lt;BR /&gt;I can confirm it works flawlessly, and as a result I was able to halve the number of requests.&lt;BR /&gt;&lt;BR /&gt;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!&lt;BR /&gt;&lt;BR /&gt;Good stuff!&lt;/P&gt;</description>
      <pubDate>Wed, 26 Apr 2023 16:13:26 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Python-How-do-I-create-an-Email-with-associations-in-one-call/m-p/786749#M63484</guid>
      <dc:creator>wollivier</dc:creator>
      <dc:date>2023-04-26T16:13:26Z</dc:date>
    </item>
    <item>
      <title>Re: Python: How do I create an Email with associations in one call?</title>
      <link>https://community.hubspot.com/t5/APIs-Integrations/Python-How-do-I-create-an-Email-with-associations-in-one-call/m-p/787118#M63507</link>
      <description>&lt;P&gt;Thank you for the wonderful feedback, mate!&amp;nbsp;Glad I was able to help you out.&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Have fun developing,&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Chriso&lt;/P&gt;</description>
      <pubDate>Thu, 27 Apr 2023 08:51:18 GMT</pubDate>
      <guid>https://community.hubspot.com/t5/APIs-Integrations/Python-How-do-I-create-an-Email-with-associations-in-one-call/m-p/787118#M63507</guid>
      <dc:creator>ChrisoKlepke</dc:creator>
      <dc:date>2023-04-27T08:51:18Z</dc:date>
    </item>
  </channel>
</rss>

