Iterate through API response for attachments

7 Comments

  • Chris Porter

    NOTE: The application that reads the POST from Zendesk is written in C# with .Net Core

    0
  • Peter Hochstrasser

    Hi Chris Porter

    I implemented a kind of backup job in PS, so on top of .Net.

    I went for the audit api, and used the event in audit to get the attachments. This has been rather straightforward, with the exception of the inline attachments (images etc. in the text).

    1
  • Chris Porter

    Thanks for the tip on the audit API. Are you scheduling a job on your app or are you using a trigger to POST to your app?

    0
  • Peter Hochstrasser

    The thing you get from the post is an array of two attachment descriptors.

    With the attachment IDs you can get them via API.

    If you insert line breaks at the commas, it is pretty simple to figure out - an

    [array of <#objects consisting of comma separated key - value pairs>].

    So, you don't need to do another call, it's all there in one go; wouldn't trust this for large numbers of attachments (say, 100 or more).

    Also, as said above, check inline attachments (images in text) as well, as they are stored a bit differently. If you get them in the same unified way, great.

     

    1
  • Peter Hochstrasser

    My job has been done so you can backup periodically.

    It takes a start point in time in the past and backups until the start of the current run.

    Then, it saves its own start time as the start point for the next run.  

    1
  • Peter Hochstrasser

    Back to your original question: I would submit the ticket ID in the post, and then use the API to get all attachments of the ticket in question.

    This will also work for a single comment, however, if your API application is listening for work, it will be able to process things quick enough to get the last comment added from the ticket itself.

    If you expect high loads, you will have to implement a listener that sends workers off to process tickets. It might also be a good idea to use the time of the trigger call just to make sure that a ticket that is "hammered" with comments gets treated correctly and completely.

    1
  • Chris Porter

    Thanks for your help!

    0

Please sign in to leave a comment.

Powered by Zendesk