# Problem Associating Email with Ticket

**URL:** <https://community.hubspot.com/t/problem-associating-email-with-ticket/128057>\
**Category:** Tickets & Conversations\
**Tags:** help-desk\
**Created:** [March 17, 2025, 8:51am UTC](https://community.hubspot.com/t/problem-associating-email-with-ticket/128057 "2025-03-17T08:51:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![MWebb5](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@MWebb5](https://community.hubspot.com/u/MWebb5)\
**Post date:** [March 17, 2025, 8:51am UTC](https://community.hubspot.com/t/problem-associating-email-with-ticket/128057/1 "2025-03-17T08:51:23Z")

</div>

I integrated hubspot api to custom help form within our app. it successfully creating contacts, tickets, associate contact with ticket, but throw error when trying to associate email with ticket.

Here is code I am using for email association

```lia-code-sample
var emailData = new
{
 properties = new
 {
 hs_timestamp = DateTime.UtcNow.ToString("o"), // ISO 8601 format
 hs_email_subject = "Retry 02 - Resolving Ticket Issue",
 hs_email_html = "<p>Ignore - Working on Tickes -> Contacts -> Email association in Hubspot.</p>",
 hs_email_status = "SENT",
 hs_email_direction = "EMAIL" // Use "EMAIL" for outgoing emails
 },
 associations = new[]
 {
 new
 {
 to = new
 {
 id = "21479416916", // Ticket ID
 },
 types = new[]
 {
 new
 {
 associationCategory = "HUBSPOT_DEFINED",
 associationTypeId = 26 // 26 is the association type ID for email to ticket
 }
 }
 }
 }
};

 await HubSpotHelper.SendEmailAsync(emailData);

 // sending post requests to
 https://api.hubapi.com/crm/v3/objects/emails

In result get the following error

{
 "status": "error",
 "message": "invalid from object type 0-49 for associations to be created. expected: 0-5",
 "correlationId": "029ffd0d-0356-487c-9052-43b8a2c7d152",
 "category": "VALIDATION_ERROR"
}

```

Can someone help how to correctly associate email with ticket / contact via hubspot api.

---

<div class="post-metadata">

**Author:** ![PamCotton](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/pamcotton/32/47916_2.png) [@PamCotton](https://community.hubspot.com/u/PamCotton)\
**Post date:** [March 17, 2025, 9:15pm UTC](https://community.hubspot.com/t/problem-associating-email-with-ticket/128057/2 "2025-03-17T21:15:54Z")

</div>

Hey @MWebb5, thank you for posting in our Community!

First, ensure the email record is successfully created by retrieving it via the API. If it exists, update your request to correctly reference the email as the “from” object before associating it with the ticket.

To our top experts, @Anton and @RSchweighart do you have any recommendations for @MWebb5 matter?

Thank you,

Pam

---

<div class="post-metadata">

**Author:** ![MWebb5](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@MWebb5](https://community.hubspot.com/u/MWebb5)\
**Post date:** [March 18, 2025, 12:28am UTC](https://community.hubspot.com/t/problem-associating-email-with-ticket/128057/3 "2025-03-18T00:28:04Z")

</div>

The main issue i am facing creating email when I created new ticket. I am using engagement API but it doesn’t work [Accounts Dashboard | HubSpot](https://developers.hubspot.com/docs/reference/api/crm/engagements/email#post-%2Fcrm%2Fv3%2Fobjects%2Femails)

Can guide some reference code who to create email and then later associate with ticket.

---

<div class="post-metadata">

**Author:** ![RSchweighart](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/rschweighart/32/28924_2.png) [@RSchweighart](https://community.hubspot.com/u/RSchweighart)\
**Post date:** [March 17, 2025, 9:29pm UTC](https://community.hubspot.com/t/problem-associating-email-with-ticket/128057/4 "2025-03-17T21:29:47Z")

</div>

Hi @MWebb5,

I recommend making a PUT request to associate the ticket to the email: /crm/v4/objects/{fromObjectType}/{fromObjectId}/associations/default/{toObjectType}/{toObjectId}  
So, you’re call might look something like this:

[https://api.hubapi.com/crm/v4/objects/tickets/12345/associations/default/emails/678910](https://api.hubapi.com/crm/v4/objects/tickets/12345/associations/default/emails/678910)

where the fromObjectID (ticket id) is 12345 and the toObjectID (email id) is 678910.

I hope this helps. More robust coding will likely need @Anton’s expertise.  
Thanks for the tag, @PamCotton.

All the Best,

_ **Ryan Schweighart** _

Whole Hart Impact, LLC

[whimpact.co](https://www.whimpact.co?utm_source=hubspot&utm_medium=community_post&utm_content=1123537)

_I help organizations use HubSpot and Zapier._

---

<div class="post-metadata">

**Author:** ![MWebb5](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@MWebb5](https://community.hubspot.com/u/MWebb5)\
**Post date:** [March 18, 2025, 12:26am UTC](https://community.hubspot.com/t/problem-associating-email-with-ticket/128057/5 "2025-03-18T00:26:16Z")

</div>

But the problem i am facing how to create email, if using this API reference and test [Accounts Dashboard | HubSpot](https://developers.hubspot.com/docs/reference/api/crm/engagements/email#post-%2Fcrm%2Fv3%2Fobjects%2Femails) , it asked for association. if using code still having problem creating email.

Can guide where to get proper resource

I need to create email and associate with ticket whenever new ticket created in the system.

---

<div class="post-metadata">

**Author:** ![MWebb5](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@MWebb5](https://community.hubspot.com/u/MWebb5)\
**Post date:** [March 18, 2025, 1:18am UTC](https://community.hubspot.com/t/problem-associating-email-with-ticket/128057/6 "2025-03-18T01:18:44Z")

</div>

I tried creating email via api end point

[https://api.hubapi.com/marketing-emails/v1/emails](https://api.hubapi.com/marketing-emails/v1/emails)

It created email successfully with emailId returned. when I sent request to API endpoint you shared

/crm/v4/objects/tickets/{ticketId}/associations/default/emails/{emailId}

It throw error response

One or more associations are invalid, “INVALID\_OBJECT\_IDS”:[“EMAIL=187471576381 is not valid”],“objectId”:[“187471576381”]

---

<div class="post-metadata">

**Author:** ![MWebb5](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@MWebb5](https://community.hubspot.com/u/MWebb5)\
**Post date:** [March 18, 2025, 5:39am UTC](https://community.hubspot.com/t/problem-associating-email-with-ticket/128057/7 "2025-03-18T05:39:38Z")

</div>

I somehow succeeded creating email using hubspot API ([https://api.hubapi.com/crm/v4/objects/emails](https://api.hubapi.com/crm/v4/objects/emails)) and associate it with ticket.

Now trying to associate email with From / To Contacts using API but it failed (Not Found) throw

[https://api.hubapi.com/crm/v4/objects/emails/{emailId}/associations/contacts/{fromContactId}/{associationType}](https://api.hubapi.com/crm/v4/objects/emails/%7BemailId%7D/associations/contacts/%7BfromContactId%7D/%7BassociationType%7D)

WHERE emailID =\> Newly created email

contactID =\> ID of contact retrieved via hubspot contact api

associationType =\> I tried ‘FROM’ / ‘TO’ or ‘EMAIL\_FROM’ , / ‘EMAIL\_TO’

---

<div class="post-metadata">

**Author:** ![RSchweighart](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/rschweighart/32/28924_2.png) [@RSchweighart](https://community.hubspot.com/u/RSchweighart)\
**Post date:** [March 18, 2025, 5:42pm UTC](https://community.hubspot.com/t/problem-associating-email-with-ticket/128057/8 "2025-03-18T17:42:54Z")

</div>

Hi @MWebb5,

If you’re [associating records without a label using v4](https://developers.hubspot.com/docs/guides/api/crm/associations/associations-v4#associate-records-without-a-label), I don’t think you need the ‘associationType’ at the end of the URL. Also, try ‘contact’ instead of contacts.

It should be very similar to however you associated the email with the ticket.

All the Best,

_ **Ryan Schweighart** _

---

<div class="post-metadata">

**Author:** ![MWebb5](https://avatars.discourse-cdn.com/v4/letter/m/bc8723/32.png) [@MWebb5](https://community.hubspot.com/u/MWebb5)\
**Post date:** [March 20, 2025, 7:31am UTC](https://community.hubspot.com/t/problem-associating-email-with-ticket/128057/9 "2025-03-20T07:31:53Z")

</div>

Thank you for hints, using same code as used for associating email with tickets. it worked.

Email to Contact

Object

var association = new  
{  
emailID,  
objectId = contactID,  
objectType = “CONTACT”  
};

End Point

/crm/v4/objects/contact/{contactID}/associations/default/emails/{emailID}

Email to Ticket

Object

var association = new  
{  
emailID,  
objectId = ticketId,  
objectType = “TICKET”  
};

/crm/v4/objects/tickets/{ticketId}/associations/default/emails/{emailID}
