APIs & Integrations

kundan_ziplyne
Member

How can I upload file to a ticket using API.

SOLVE

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='

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
0 Upvotes
1 Accepted solution
jackcoldrick
Solution
HubSpot Employee
HubSpot Employee

How can I upload file to a ticket using API.

SOLVE

Hi @kundan_ziplyne,

 

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" 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" 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:

 

{
    "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!

Jack Coldrick
Solutions Engineer @ HubSpot
Add me on LinkedIn

View solution in original post

5 Replies 5
MGo2Partners
Member

How can I upload file to a ticket using API.

SOLVE

How can we acheive this using private App?

0 Upvotes
jackcoldrick
Solution
HubSpot Employee
HubSpot Employee

How can I upload file to a ticket using API.

SOLVE

Hi @kundan_ziplyne,

 

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" 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" 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:

 

{
    "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!

Jack Coldrick
Solutions Engineer @ HubSpot
Add me on LinkedIn
DiegoCisneros
Participant

How can I upload file to a ticket using API.

SOLVE

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)

 

 

 

<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

0 Upvotes
Treasurechic
Member

How can I upload file to a ticket using API.

SOLVE

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

0 Upvotes
kundan_ziplyne
Member

How can I upload file to a ticket using API.

SOLVE

thanks @jackcoldrick 

0 Upvotes