How can I upload file to a ticket using API.

SOLVE
Highlighted
New Contributor

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
Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
HubSpot Employee

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!

2 Replies 2
HubSpot Employee

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!

New Contributor

thanks @jackcoldrick 

Reply
0 Upvotes