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
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.
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.
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:
But the problem i am facing how to create email, if using this API reference and test Accounts Dashboard | HubSpot , 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.