# How can I upload file to a ticket using API.

**URL:** <https://community.hubspot.com/t/how-can-i-upload-file-to-a-ticket-using-api/17113>\
**Category:** APIs & Integrations\
**Tags:** developer-tools\
**Created:** [November 8, 2019, 7:42am UTC](https://community.hubspot.com/t/how-can-i-upload-file-to-a-ticket-using-api/17113 "2019-11-08T07:42:36Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![kundan\_ziplyne](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kundan_ziplyne/32/102945_2.png) [@kundan\_ziplyne](https://community.hubspot.com/u/kundan_ziplyne)\
**Post date:** [November 8, 2019, 7:42am UTC](https://community.hubspot.com/t/how-can-i-upload-file-to-a-ticket-using-api/17113/1 "2019-11-08T07:42:36Z")

</div>

I have integrated ticket API to create a ticket from NodeJS and trying to add attachment as well.

API : ‘[https://api.hubapi.com/crm-objects/v1/objects/tickets?hapikey=](https://api.hubapi.com/crm-objects/v1/objects/tickets?hapikey=)’

POST json: [

```
            {

              "name": "subject",

              "value": "subject"

            },

            {

              "name": "content",

              "value": comment

            },

            {

              "name": "hs\_pipeline",

              "value": "0"

            },

            {

              "name": "hs\_pipeline\_stage",

              "value": "1"

            },

            {

                "name": "hs\_file\_upload",

                "file": file.png

            }

          ]

```

what I am missing here or how can I add an attachment. Plz help

---

<div class="post-metadata">

**Author:** ![jackcoldrick](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jackcoldrick/32/5119_2.png) [@jackcoldrick](https://community.hubspot.com/u/jackcoldrick)\
**Post date:** [November 8, 2019, 12:09pm UTC](https://community.hubspot.com/t/how-can-i-upload-file-to-a-ticket-using-api/17113/2 "2019-11-08T12:09:13Z")

</div>

Hi [@kundan\_ziplyne](https://community.hubspot.com/t5/user/viewprofilepage/user-id/110047),

To associate a file with a ticket or any object for that matter you would need to do the following:

1) Upload a file to the file manager using the “[upload a new file](https://developers.hubspot.com/docs/methods/files/post_files)” endpoint. This will return a response containing meta data for the file. The most important of which is the “id” of the file. We need to use that in the next step.

2) Create an engagement using the “[create an engagement](https://developers.hubspot.com/docs/methods/engagements/create_engagement)” endpoint and use the file ID returned previously in the “associations” array in your request. This will result in a file being associated to the specific object. Below is an example of the payload:

```auto
{
 "engagement": {
 "active": true,
 "ownerId": 1,
 "type": "NOTE", 
 "timestamp": 1409172644778
 },
 "associations": {
 "contactIds": [],
 "companyIds": [],
 "dealIds": [],
 "ownerIds": [],
 "ticketIds": [28164303] <-- ID OF THE OBJECT IN HUBSPOT
 },
 "attachments": [
 {
 "id": 4964093251 <-- ID OF THE FILE IN HUBSPOT
 }
 ],
 "metadata": {
 "body": ""
 }
}

```

I hope this helps!

---

<div class="post-metadata">

**Author:** ![kundan\_ziplyne](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/kundan_ziplyne/32/102945_2.png) [@kundan\_ziplyne](https://community.hubspot.com/u/kundan_ziplyne)\
**Post date:** [November 14, 2019, 3:13pm UTC](https://community.hubspot.com/t/how-can-i-upload-file-to-a-ticket-using-api/17113/3 "2019-11-14T15:13:33Z")

</div>

thanks @jackcoldrick

---

<div class="post-metadata">

**Author:** ![Treasurechic](https://avatars.discourse-cdn.com/v4/letter/t/5f8ce5/32.png) [@Treasurechic](https://community.hubspot.com/u/Treasurechic)\
**Post date:** [June 17, 2022, 2:30pm UTC](https://community.hubspot.com/t/how-can-i-upload-file-to-a-ticket-using-api/17113/4 "2022-06-17T14:30:37Z")

</div>

@jackcoldrick Please can you show the sample of your payload to upload a new file on the frontend using javascript?

---

<div class="post-metadata">

**Author:** ![DiegoCisneros](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/diegocisneros/32/29368_2.png) [@DiegoCisneros](https://community.hubspot.com/u/DiegoCisneros)\
**Post date:** [March 15, 2023, 6:54pm UTC](https://community.hubspot.com/t/how-can-i-upload-file-to-a-ticket-using-api/17113/5 "2023-03-15T18:54:09Z")

</div>

Hello @jackcoldrick thanks for your answerbut actually that solution is not working, I can upload a file with the endpoint v3/files/upload, but the engagement doesn’t work, making the request as you suggest I’ve got this response:

(I’m trying to attach an image to the ticket)

```lia-code-sample
<html>
<head>
<meta http-equiv="Content-Type" content="text/html;charset=utf-8"/>
<title>Error 415 Unsupported Media Type</title>
</head>
<body><h2>HTTP ERROR 415</h2>
<p>Reason:
<pre> Unsupported Media Type</pre></p>
</body>
</html>

```

do you have any other solution or suggestion

thanks

---

<div class="post-metadata">

**Author:** ![MGo2Partners](https://avatars.discourse-cdn.com/v4/letter/m/59ef9b/32.png) [@MGo2Partners](https://community.hubspot.com/u/MGo2Partners)\
**Post date:** [August 31, 2022, 2:45pm UTC](https://community.hubspot.com/t/how-can-i-upload-file-to-a-ticket-using-api/17113/6 "2022-08-31T14:45:05Z")

</div>

How can we acheive this using private App?
