You can upload a file and attach it to a ticket comment. The attachment appears as a link in the ticket comment in the agent interface in Zendesk. If ticket notifications are enabled, the attachment appears as a link in the notification email.

Use the Attachments API to upload a file you want to attach. However, you can only attach the uploaded file to a ticket comment with the Tickets API when adding the comment to a ticket you're creating or updating.

For details and examples, see Adding ticket attachments with the API.

This API is for tickets attachments. To attach files to articles in your help center, see Article Attachments in the Help Center API documentation.

JSON Format

Attachments are represented as JSON objects with the following properties:

Name Type Read-only Mandatory Description
content_type string true false The content type of the image. Example value: "image/png"
content_url string true false A full URL where the attachment image file can be downloaded. The file may be hosted externally so take care not to inadvertently send Zendesk authentication credentials. See Working with url properties
deleted boolean true false If true, the attachment has been deleted
file_name string true false The name of the image file
height string true false The height of the image file in pixels. If height is unknown, returns null
id integer true false Automatically assigned when created
inline boolean true false If true, the attachment is excluded from the attachment list and the attachment's URL can be referenced within the comment of a ticket. Default is false
mapped_content_url string true false The URL the attachment image file has been mapped to
size integer true false The size of the image file in bytes
thumbnails array true false An array of attachment objects. Note that photo thumbnails do not have thumbnails
url string true false A URL to access the attachment details
width string true false The width of the image file in pixels. If width is unknown, returns null

A file represented as an Attachment object

Example

{  "content_type": "image/png",  "content_url": "https://company.zendesk.com/attachments/my_funny_profile_pic.png",  "file_name": "my_funny_profile_pic.png",  "id": 928374,  "size": 166144,  "thumbnails": [    {      "content_type": "image/png",      "content_url": "https://company.zendesk.com/attachments/my_funny_profile_pic_thumb.png",      "file_name": "my_funny_profile_pic_thumb.png",      "id": 928375,      "size": 58298    }  ]}

Upload Files

  • POST /api/v2/uploads

Uploads a file that can be attached to a ticket comment. It doesn't attach the file to the comment. For details and examples, see Attaching ticket comments with the API.

The endpoint has a required filename query parameter. The parameter specifies what the file will be named when attached to the ticket comment (to give the agent more context about the file). The parameter does not specify the file on the local system to be uploaded. While the two names can be different, their file extensions must be the same. If they don't match, the agent's browser or file reader could give an error when attempting to open the attachment.

Adding multiple files to the same upload is handled by splitting requests and passing the API token received from the first request to each subsequent request. The token is valid for 3 days.

Note: Even if private attachments are enabled in the Zendesk Support instance, uploaded files are visible to any authenticated user at the content_URL specified in the JSON response until the upload token is consumed. Once a file is associated with a ticket or post, visibility is restricted to users with access to the ticket or post with the attachment.

Allowed For

  • End users

Using curl

curl "https://{subdomain}.zendesk.com/api/v2/uploads?filename=user_crash.log&token={optional_token}" \  --data-binary @crash.log \  -H "Content-Type: application/binary" \  -v -u {email_address}:{password} \  -X POST

Example Response

Status 201 Created
{  "upload": {    "attachment": {      "content_type": "image/png",      "content_url": "https://company.zendesk.com/attachments/token/tyBq1ms40dFaHefSIigxZpwGg/?name=crash.png",      "deleted": false,      "file_name": "crash.png",      "height": "62",      "id": 1503729607981,      "inline": false,      "mapped_content_url": "https://company.zendesk.com/attachments/token/tyBq1ms40dFaHefSIigxZpwGg/?name=crash.png",      "size": 5172,      "thumbnails": [],      "url": "https://company.zendesk.com/api/v2/attachments/1503729607981.json",      "width": "80"    },    "attachments": [      {        "content_type": "image/png",        "content_url": "https://company.zendesk.com/attachments/token/tyBq1ms40dFaHefSIigxZpwGg/?name=crash.png",        "deleted": false,        "file_name": "crash.png",        "height": "62",        "id": 1503729607981,        "inline": false,        "mapped_content_url": "https://company.zendesk.com/attachments/token/tyBq1ms40dFaHefSIigxZpwGg/?name=crash.png",        "size": 5172,        "thumbnails": [],        "url": "https://company.zendesk.com/api/v2/attachments/1503729607981.json",        "width": "80"      }    ],    "token": "LXJdriewLBP8JrtzzkN7Ne4k6"  }}

Delete Upload

  • DELETE /api/v2/uploads/{token}

Allowed for

  • End Users

Parameters

Name Type In Required Description
token string Path true The token of the uploaded attachment

Using curl

curl https://{subdomain}.zendesk.com/api/v2/uploads/{token} \  -v -u {email_address}:{password} -X DELETE

Example Response

Status 204 No Content

Show Attachment

  • GET /api/v2/attachments/{attachment_id}

Shows attachment details. You can get the value of the attachment_id parameter by listing the ticket's comments. See List Comments. Each comment in the list has an attachments list that specifies an id for each attachment.

Allowed for

  • Agents

Parameters

Name Type In Required Description
attachment_id integer Path true The ID of the attachment

Using curl

curl https://{subdomain}.zendesk.com/api/v2/attachments/{attachment_id} \  -v -u {email_address}:{password}

Example Response

Status 200 OK
{  "attachment": {    "content_type": "application/binary",    "content_url": "https://company.zendesk.com/attachments/myfile.dat",    "file_name": "myfile.dat",    "id": 498483,    "size": 2532,    "thumbnails": [],    "url": "https://company.zendesk.com/api/v2/attachments/498483.json"  }}

Redact Comment Attachment

  • PUT /api/v2/tickets/{ticket_id}/comments/{comment_id}/attachments/{attachment_id}/redact

Redaction allows you to permanently remove attachments from an existing comment on a ticket. Once removed from a comment, the attachment is replaced with an empty "redacted.txt" file.

The redaction is permanent. It is not possible to undo redaction or see what was removed. Once a ticket is closed, redacting its attachments is no longer possible.

Also, if you want to redact an inline attachment, you can use the include_inline_images parameter in the List Comments operation to obtain the inline attachment ID, and use it in the request URL.

Allowed For

Parameters

Name Type In Required Description
attachment_id integer Path true The ID of the attachment
comment_id integer Path true The ID of the comment
ticket_id integer Path true The ID of the ticket

Using curl

curl https://{subdomain}.zendesk.com/api/v2/tickets/{ticket_id}/comments/{comment_id}/attachments/{attachment_id}/redact \  -H "Content-Type: application/json" -v -u {email_address}:{password} -X PUT -d '{}'

Example Response

Status 200 OK
{  "attachment": {    "content_type": "application/binary",    "content_url": "https://company.zendesk.com/attachments/myfile.dat",    "file_name": "myfile.dat",    "id": 498483,    "size": 2532,    "thumbnails": [],    "url": "https://company.zendesk.com/api/v2/attachments/498483.json"  }}