Creating ticket using API with contact and company attached

So my company is beginning to use HubSpot and we want to have contact and customer information to be included in the ticket.

My thought process is that we’d pass the user back to our website from our Hubspot help/faq stuff, to have them fill out a ticket from our website post that through the api into Hubspot.

The other way is that we could pass in the contact information into hubspot or company information into hubspot ahead of time, but I’m not sure if that’d be possible. Please let me know, as that’d be the more elegant solution.

----

So if we do create the ticket from out website, how would pass in the user information / company / custom fields, into the API.

I’m working with Accounts Dashboard | HubSpot
I was able to create a basic ticket with a subject/content, but am not able to figure out how to add in more information.

So I assume in order to create contact, I’d first need to see if the contact already exist inside of HubSpot, if not then create a contact. Then do the same with the Company info.

How would I then attach that information to the ticket being created?

Also, how would I attach any custom fields info to the ticket?
Thanks!

Hey @DerekHub,

When looking to attach contact/company with a ticket, you can use the CRM API | Associations. e.g. if I’d like to associate contact 123 to ticket 456

POST crm/v3/associations/contact/ticket/batch/create?hapikey=hapikey

POST Body

{
 "inputs": [
 {
 "from": {
 "id": "123"
 },
 "to": {
 "id": "456"
 },
 "type": "contact_to_ticket"
 }
 ]
}

To your second query, if you’re looking to include custom fields on a ticket record, you would first need to create a custom ticket property, either via in-app or CRM API | Properties and assign value to the custom property when creating ticket via the CRM API | Tickets.

I getting this error.

{

“status”: “error”,

“message”: “Unable to infer object type from: fromObjectType”,

“correlationId”: “d860c050-0547-4df1-87a0-ff47014a17d2”

}

I need help, I think theirs something wrong with the API. so I have a contact with a vid of

6901

and the ticket id was

441618771

and set the type to `contact_to_ticket`

I used the endpoint

<?php
/* hubspot/api-client - Packagist.org */

$curl = curl_init();

curl_setopt_array($curl, array(
CURLOPT_URL => “https://api.hubapi.com/crm/v3/associations/fromObjectType/toObjectType/batch/create?hapikey=\”,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => “”,
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 30,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => “POST”,
CURLOPT_POSTFIELDS => “{\“inputs\”:[{\“from\”:{\“id\”:\“6901 \”},\“to\”:{\“id\”:\“441618771 \”},\“type\”:\“contact_to_ticket\”}]}”,
CURLOPT_HTTPHEADER => array(
“accept: application/json”,
“content-type: application/json”
),
));

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
echo “cURL Error #:” . $err;
} else {
echo $response;
}

but this is showing error in my end
{
“status”: “error”,
“message”: “Unable to infer object type from: fromObjectType”,
“correlationId”: “98363cdc-76ae-4d60-97de-071423a93923”
}

The ticket isn’t created yet. how do we know its ID?
We want to create a ticket with an associated contact

Hey, @DLu-ang :waving_hand: The Tickets API includes an example on how to create a Ticket and associate it to existing Objects, like a Contact or Deal, in the same call — Associations.

If you want to walk through it together using the above example, create a new post and tag me in it (as this one is old now) and I’ll add an example I created for another post.

Best,

Jaycee