Attaching files to tickets via API

Return to top
Have more questions? Submit a request

32 Comments

  • Clare Lo

    Hello Chris,

    Can we attach other file formats to a ticket? For example, users can attach documents and videos to a ticket. 

    0
  • Phil

    This resource is rather sparse! Might as well go straight to https://developer.zendesk.com/rest_api/docs/core/attachments#uploading-files :p

    0
  • Becca
    Zendesk team member

    Hi Clare- 

    You can use the upload attachment API to upload the same type of files as you can via the agent interface. 

    0
  • Vaishali

    I am using attachment API to upload any files to create ticket.When I check ticket and download that attachemnt , it is not download.

    Note : filename like abc.png is in my system .

    const url = "https://fyttest.zendesk.com/api/v2/uploads.json?filename="+filename;

    Request json :

    {
    "attachment": {
    "size": size
    }
    };

     

    Ques : Is there anything missing in Request json fields?

    0
  • Dwight Bussman
    Zendesk team member

    Hi Vaishali,

    I'm afraid I'm not understanding your question. It looks like you've already reached out to support@zendesk.com with a very similar question. I'll see that someone reaches out to you on that ticket as we may need to get more clarification/examples to see what's going on here.

    Thanks,

    0
  • Ricardo Marquez

    Does this work creating ticket as requester? because i am trying to do it and image is not showing on my support zendesk.

    {
      "ticket": {
        "comment":  { "body": "See screenshot.", "uploads":  ["vz7ll9ud8oofowy"] }
      }
    }

    0
  • Dwight Bussman
    Zendesk team member

    Hi Ricardo,

    The syntax you sent there looks correct to me! Is it possible that the upload-token has already been consumed? If it's already been used in a given ticket-comment, it's attached to that ticket and subsequent requests using that same token will not attach it to tickets. In that case, it should be possible to reference the attachment URL from the original comment, but this requires permission to access the original location.

    If you'd like us to look into your case more closely, please feel free to reach out to support@zendesk.com or I'd be happy to take this conversation into a ticket for privacy.

    0
  • Chinmay Narwane

    Hi Folks,

    I am trying to post an attachment through API to a newly created ticket. I read all the material on the Support but still could not find how this can be done without an ID. 

    Can anyone please help ? My Use Case is as below.

    Get Comment and Attachment from DW 

    Create a ticket in Zendesk with Attachment

    Thanks in Advance,

    Chinmay

    0
  • Dylan Tragjasi

    Hi Chinmay,

    It is currently only possible to include attachments to tickets via the API by first uploading the required attachment using the Uploading files API
    Once uploaded, you can use the resulting token ID to include this in any ticket where required.

    In your particular use case, you'd need to follow these steps for this to work:

    1. Get Comment and Attachment from DW 
    2. Upload attachment using the Upload Files API Endpoint
    3. Create a ticket in Zendesk with newly uploaded file

    It is not currently possible to create a ticket and upload a new file as an attachment in a single request.

    Hope this helps clarify!

    - Dylan

    0
  • Chinmay Narwane

    Hi Dylan,

    Thank you for the quick response.

    Could you please share the syntax to upload a file followed by getting the token? I am new to this and I could not find anything where we can directly upload a file without ID and then get the token number ? 

    Thanks in advance.

    Chinmay

    0
  • Dylan Tragjasi

    Hey Chinmay,

    I'm going to take this into a ticket and email you directly to help troubleshoot any issues you're currently having uploading files to then use as attachments. 

    Look out for an email from me shortly!

    - Dylan

    0
  • Vyacheslav Meshkov

    Hi, Dylan,

    I used your ZDKRequestAttachment API and it's OK. But I have some  questions:

    - How to find out that it's a first request message (support conversations just started); maybe message count in support session could be requested

    - Is it possible to attach just URL (or maybe initialize request message text with initial text data)

    - How to use static method HelpCenterActivity::isShowingHelp and is it possible to do the same on iOS?

    Best regards,

    Vyacheslav

    0
  • Bryan - Community Manager
    Zendesk Developer Support

    Hello Vyacheslav Meshkov -- this looks like a mobile development question. This article is focused just on the REST attachment APIs. For mobile specific community questions, please post here:

    https://develop.zendesk.com/hc/en-us/community/topics/360000018828-Zendesk-Mobile-SDKs

    If you don't get a timely response, feel free to submit a ticket.

    0
  • raghees

    Hi Bryan,

    I am upload a picture through API and it uploaded successfully but when I see that attachment on agent portal it does not show. It seems like a corrupted image.  

    0
  • Bryan - Community Manager
    Zendesk Developer Support

    Hi raghees. Can you give a detailed example of the command you're using to upload the file? Know that when uploading an image file, make sure Content-Type: application/binary is used. 

    Also, if you happen to be writing an Apps framework app, files and binary content cannot be uploaded or downloaded via the client.request command.

    0
  • raghees

    Thanks Bryan, I am using  'POST /api/v2/uploads.json' command for uploading files which is allowed for end users. I am using a node server to upload images with request client called 'request-promise'  with the header Content-type: application/binary 

    As you have mentioned that binary content cannot be uploaded via client.request command. Is their any example with javascript or any workaround ?

    0
  • Bryan - Community Manager
    Zendesk Developer Support

    Moved above attachment upload conversation to other community post: https://support.zendesk.com/hc/en-us/community/posts/360038177733-Attach-images-are-broken-in-agent-s-portal?page=1#community_comment_360010148893

    0
  • Vijay Kumar

    Hi Bryan,

    What is the API URL to attach file to ticket. I am trying this api/v2/tickets/{id}/related.json, but couldn't see attachment in ticket. I have followed the sequence like first to upload an attachment and then using the token received, i am calling above mention API.

    0
  • Greg - Community Manager
    Zendesk Developer Support

    Hi Vijay Kumar! The endpoint that you're using there is only available for a GET, so you can not attach the attachment token to the ticket with that. You would need to use a create or update type of endpoint, such as this one.

    0
  • Antoine Morel

    Hi,

    Is it possible to add an attachment to an internal note - comment ?

    This is my case :

    I have a python program which scans ticket and attachment when a ticket is created. There are files that need to be converted in order for us to work on it. I would like to automate the conversion of the original file by adding a function in the python program which converts the original file and add the converted file to an internal note.

    Is it possible with the API "upload files" ? : https://developer.zendesk.com/rest_api/docs/support/attachments#upload-files

    Is there another way to do it ?

    0
  • Bryan - Community Manager
    Zendesk Developer Support

    Hi Antoine Morel -- check out this other community post. It talks about file uploads using Python. Perhaps this would help get you to your next step: Python file upload

    0
  • Gemma Garcias

    Hi Bryan - Community Manager,
    I could attach the file which is an image but when I go to the support there is a png file attached and when I click it doesn't show anything...
    I uploaded the file via upload.json API, and then I call requests.json API like this:
    {
     "request": {
            "subject": "test",
            "comment": {
                   "body": "testing",
                   "uploads": ["O5wcPtlQLMy7vUklJF2sz6BEO"]
          },
             "requester": {
             "name": "test",
             "email": "test@test.com",
            "locale": "en-GB",
            "locale_id": 1
      }
    }

    Thanks

    0
  • Dwight Bussman
    Zendesk team member

    Hi Gemma,

    This sounds like a misbehavior to me. Please raise a ticket with our Support team to look into this further as I suspect they'll want to look through logs and settings specific to your account.

    Thanks!

    0
  • Brett Bowser
    Zendesk Community Team

    Hey Gemma,

    Looks like you already have a ticket open related to this issue. We will continue working with you there to troubleshoot further.

    Thanks for taking the time to share this with us!

    1
  • Ganesh Kumar

    Hi Brett,

    Any update regarding this issue. As i am also facing the same issue, Unable to view the attachment same as Gemma.Garcias. When can i expect the fix for this ?

     

    1
  • Devan - Community Manager
    Zendesk Community Team

    Hello Ganesh Kumar,

    Right now, we don't have an estimate on a fix for this issue, but I would recommend reaching out to our Advocacy team via Chat so they can look into this issue for you.

    Best regards. 

    0
  • Chris

    I also am not able to view uploaded images when attaching tokens in `comment.uploads` array.

    Looked through a ton or articles and can't find the answer as to why the attachment doesn't show up in the ticket. I do not have auth required to view the images either.

    Can anyone point me in the right direction here?

    2
  • Brett Bowser
    Zendesk Community Team

    Hey Chris,

    Looks like you haven't received a response yet. Are you still running into issues uploading images? If so, I'll need to create a ticket on your behalf so our team can look into this further with you.

    Let me know!

    0
  • Holly C

    Hello,

    Is it possible to upload files using jQuery AJAX Http post method? If yes, can anyone help with a code sample?

    Thank you,

    Holly

    0
  • Bryan - Community Manager
    Zendesk Developer Support

    Hi Holly C,

    If you want to upload a file using POST /api/v2/uploads.json in an Apps framework app (aka "ZAF app"), here's example ticket_sidebar code. This is a slightly modified version of a great comment from this older community post.

    Example/unsupported code:

    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
    </head>
    <body>
    <h2>Test Binary File Upload</h2>
    </br>
    <label for="data">Select file:</label>
    <input type="file" name="data[]" id="data" multiple>
    <button type="button" onclick="doit()">Upload file now...</button>
    </br></br>
    <label>Token value:</label>
    <input type="text" id='token_value_from_upload' style="width: 220px;">
    </br></br>
    <button type="button" onclick="doattach()">Attach file to ticket...</button>
    <script src="https://static.zdassets.com/zendesk_app_framework_sdk/2.0/zaf_sdk.min.js"></script>
    <script>
    var client = ZAFClient.init()
    client.invoke('resize', { width: '100%', height: '300px' })

    // upload selected file
    function doit() {
    //retrieve the uploaded file
    var file = data.files[0]

    $.ajax({
    url: "https://YOUR_SUBDOMAIN.zendesk.com/api/v2/uploads.json?filename=" + file.name,
    type: 'POST',
    data: file,
    dataType: 'json',
    processData: false,
    contentType: 'application/binary',
    // If "Admin > Settings/Tickets > Customers can attach files" is *unchecked*, you need this:
    // headers: {
    // "Authorization": "Bearer OAUTH_TOKEN",
    // },
    success: function(response) {
    console.log(response)
    document.getElementById('token_value_from_upload').value = response.upload.token
    }
    })
    }

    // attach uploaded file to ticket
    function doattach() {

    var ticket_update = '{"ticket": {"comment": { "body": "New comment here", "uploads": ["'
    + document.getElementById('token_value_from_upload').value + '"] }}}'

    client.get('ticket.id').then(function(response_for_id) {

    var options = {
    url: "/api/v2/tickets/" + response_for_id["ticket.id"].toString(),
    type: 'PUT',
    data: ticket_update,
    dataType: 'json',
    processData: false,
    contentType: 'application/json'
    }

    client.request(options).then(
    function(response_to_update_ticket) {
    console.log("Successful ticket update response here:", response_to_update_ticket)
    },
    function(error_updating_ticket){
    console.log("Error ticket update response here:", error_updating_ticket)
    })
    })
    }
    </script>
    </body>
    </html>

    Know that file uploading is affected by this setting:

    If you have this *unchecked*, you'll need to provide an Authorization header with an OAuth/Bearer token as mentioned in the example code above.

    Hope this helps get you to your next step!

    0

Please sign in to leave a comment.

Powered by Zendesk