# Create a ticket from API

**URL:** <https://community.hubspot.com/t/create-a-ticket-from-api/88429>\
**Category:** APIs & Integrations\
**Tags:** help-desk\
**Created:** [August 28, 2023, 12:37pm UTC](https://community.hubspot.com/t/create-a-ticket-from-api/88429 "2023-08-28T12:37:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![karkaletsis](https://avatars.discourse-cdn.com/v4/letter/k/3da27b/32.png) [@karkaletsis](https://community.hubspot.com/u/karkaletsis)\
**Post date:** [August 28, 2023, 12:37pm UTC](https://community.hubspot.com/t/create-a-ticket-from-api/88429/1 "2023-08-28T12:37:44Z")

</div>

I am using API to create a ticket by posting the following JSON to [https://api.hubapi.com/crm/v3/objects/tickets](https://api.hubapi.com/crm/v3/objects/tickets)

{

“properties”: {

“hs\_pipeline”: “0”,

“hs\_pipeline\_stage”: “1”,

“hs\_ticket\_priority”: “HIGH”,

“subject”: “troubleshoot report”,

“content”: “test email content τεστ”,

“project”: “TEST POSTMAN”

}

}

How can I pass in JSON the creator email to automatically create the assosiation with contact?

---

<div class="post-metadata">

**Author:** ![coldrickjack](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/coldrickjack/32/6684_2.png) [@coldrickjack](https://community.hubspot.com/u/coldrickjack)\
**Post date:** [August 28, 2023, 3:51pm UTC](https://community.hubspot.com/t/create-a-ticket-from-api/88429/2 "2023-08-28T15:51:22Z")

</div>

HI @karkaletsis,

You need to include an association array in your request. This contains the ID of the CRM object that you’d like to associate to the ticket. For instance if I had a contact with ID “951” I could create the ticket and associate using the following request:

```lia-code-sample
POST https://api.hubapi.com/crm/v3/objects/tickets
HEADER AUTHORIZATION: BEARER TOKEN
BODY
{
 "properties": {
 "hs_pipeline": "0",
 "hs_pipeline_stage": "1",
 "hs_ticket_priority": "HIGH",
 "subject": "troubleshoot report"
 },
 "associations": [
 {
 "to": {
 "id": 951
 },
 "types": [
 {
 "associationCategory": "HUBSPOT_DEFINED",
 "associationTypeId": 16
 }
 ]
 }
 ]
}
RESPONSE
{
 "id": "1685582803",
 "properties": {
 "createdate": "2023-08-28T15:48:35.312Z",
 "hs_helpdesk_sort_timestamp": "2023-08-28T15:48:35.312Z",
 "hs_last_message_from_visitor": "false",
 "hs_lastmodifieddate": "2023-08-28T15:48:35.312Z",
 "hs_object_id": "1685582803",
 "hs_object_source": "INTEGRATION",
 "hs_object_source_id": "1914406",
 "hs_pipeline": "0",
 "hs_pipeline_stage": "1",
 "hs_ticket_id": "1685582803",
 "hs_ticket_priority": "HIGH",
 "subject": "troubleshoot report"
 },
 "createdAt": "2023-08-28T15:48:35.312Z",
 "updatedAt": "2023-08-28T15:48:35.312Z",
 "archived": false
}

```

You can use the [CRM Search API](https://developers.hubspot.com/docs/api/crm/search) to check to see if the contact exists in the CRM prior to making the above request. If they do their ID will be returned which you can use for the association. If they do not you can [create a contact](https://developers.hubspot.com/docs/api/crm/contacts) and use the returned ID to create the association.

Good luck with the project!

---

<div class="post-metadata">

**Author:** ![Rkc](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/rkc/32/200145_2.png) [@Rkc](https://community.hubspot.com/u/Rkc)\
**Post date:** [October 8, 2023, 4:43am UTC](https://community.hubspot.com/t/create-a-ticket-from-api/88429/3 "2023-10-08T04:43:57Z")

</div>

Thank you. i Got exactly what i want KaBoom
