Adding a comment to a ticket via the API Follow



  • Avatar

    Where can I find examples that show how to do this ... using the ruby client or the REST API straight up?

    Right now I can do something like this to *create a new ticket* with comments using the ruby client:

    ticket = ZendeskAPI::Ticket.import(client, :subject => 'Help me, Spock', :comments => [{ :author_id => xxxxx, :value => 'Comment1' }, { :author_id => xxxxxx, :value => 'Comment2' }])

    But how do I *update* the collection of comments on a ticket using the API for an existing ticket?


    thanks- Michael

  • Avatar
    Jessie - Community Manager

    Hey Michael!

    There are a couple examples in our ticket update API documentation that I think will help you out!

  • Avatar

    Thanks Jesse.  I did look at that, and the above import code *does* work for creating a new ticket with a number of comments.  But what does not yet work for me is using the (official) ruby wrapper library to add a new comment to a ticket that has a number of comments already.  Here is what I am doing now, in ruby:

    # get a valid client

    client = do |config| ... end
    ticket = => [my existing ticket id])
    ticket.comments.length # = 10... good, that's what I created
    comment = ticket.comments.las.dup . # create a new one and null id
    comment.body = "11th comment" # or something
    comment.ticked_id = # just in case
    ticket.comments << comment . # add it! # saves ticket, doesn't show comment! # doesn't work either
  • Avatar
    Rebecca (Edited )
    Hi Michael! Sorry to hear you're having some trouble using the Ruby client. I am going to create a ticket on your behalf to troubleshoot this further. 
  • Avatar

    Hey Rebecca - thanks for the reply, but I figured it out... I wish it were better-documented, but it is very simple:  I found the answer in a GitHub issue on the project for the ruby wrapper:

    t =

    t.update(comment: {public: false, body: 'comment 2' })

    This adds a comment to the collection of comments on the ticket.  It's not obvious (to me) that this is what would happen; I was expecting something more like

    t.comments << comment


  • Avatar

    I support Michael's idea. The official ruby client's documentation should be improved or the usage of api should be changed.

  • Avatar
    Mike Martello

    Yes, please update the documentation! I had to dig quite a bit to find this info.

  • Avatar
    Paulo Delgado

    +1 on this.

    Also, is there a way to get the comment id when you create a comment using the method above?

  • Avatar

    Is there any way that I can detect if there's a new internal note of a Zendesk ticket submitted?

  • Avatar
    Nicole - Community Manager

    Hi Hoang - 

    If an internal note updates a ticket, it will send notifications the same as updating via the interface. 

    In order to receive a notification of an internal note, you would need to be an agent cc'd on the ticket, or if you have a trigger set up to notify you about ticket updates. 

Please sign in to leave a comment.

Powered by Zendesk