Adding a comment to a ticket via the API

Have more questions? Submit a request

22 Comments

  • Michael
    Comment actions Permalink

    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

    0
  • Jessie Schutz
    Comment actions Permalink

    Hey Michael!

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

    1
  • Michael
    Comment actions Permalink

    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 = ZendeskAPI::Client.new do |config| ... end
    ticket = client.tickets.find(:id => [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 = ticket.id # just in case
    ticket.comments << comment . # add it
    ticket.save! # saves ticket, doesn't show comment
    ticket.comments.save! # doesn't work either
    0
  • Rebecca
    Comment actions Permalink
    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. 
     
    0
  • Michael
    Comment actions Permalink

    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 = client.tickets.find(...)

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

    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

     

    3
  • Hbh
    Comment actions Permalink

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

    2
  • Mike Martello
    Comment actions Permalink

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

    1
  • Paulo Delgado
    Comment actions Permalink

    +1 on this.

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

    0
  • Nguyenhoang
    Comment actions Permalink

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

    0
  • Nicole - Community Manager
    Comment actions Permalink

    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. 

    0
  • Dan Ross
    Comment actions Permalink

    I too have the same question as Paulo,

    Is there a way to get the comment id when you create a comment so we can send it to an external service?

     

    0
  • Jessie Schutz
    Comment actions Permalink

    Hey Dan!

    According to our API docs, the comment ID is available via API: https://developer.zendesk.com/rest_api/docs/core/ticket_comments

    Will that work?

    0
  • Dan Ross
    Comment actions Permalink

    Hey Jessie,

    Thanks for the link:)  It could work, but not nearly as well as we'd hoped. We're trying to send the ticket comment ID to an external target for possible action. unfortunately, ticket comment ID only appears to be available via Liquid which to the best of my knowledge, isn't supported in the Notify Target feature.

    To use it via the API, we need to push the ticket ID to the target, have the target be able to come back to Zendesk with that ticket ID and request all the comments. Then we need to sort through them to find the latest comment we need. 

    It adds at least one extra unnecessary API call for each interaction and more complexity to the application.

    0
  • Kaio Cristian
    Comment actions Permalink

    Hey there.

    Using this question to ask something related to this to see if I can get help here. If not, I can submit a separate question.

    Is there any specific scope I have to specify to generate an OAuth token to be able to access (list) ticket comments?

    I mean, if I use global scopes, like `scope=read write`, I can access the comments without any issues (`/tickets/:id/comments.json`), but If I use `scope=tickets:read tickets:write` or even if I specify read and write to every other scope listed here https://developer.zendesk.com/rest_api/docs/core/oauth_tokens I am still not able to list ticket comments.

    I tried settings scopes like `comments:read comments:write`, `ticket_comments:read ticket_comments:write`, etc, but they don't seem to exist.

    The response I get when calling the endpoint without global write and read scopes is: `You are missing the following required scopes: read` or something like that.

    Thank you :)

    0
  • Dipesh Dave
    Comment actions Permalink

    Hey Kaio,

    Just wanted to follow-up again after doing some more research. It appears that you might need a global scope to fine tune the ticket comments.

    Unfortunately ticket comments is not a resource that can be fine-tuned like the other ones. The ones that can be fine tuned are listed here:

    tickets
    users
    auditlogs (read only)
    organizations
    hc
    apps
    triggers
    automations
    targets

    Since you were able to access ticket comments with read write access, I would recommend just using that since it works.

     

    0
  • mohan upadhyay
    Comment actions Permalink

    What to do when updating a ticket using API_Client_PHP, comment being added on the ticket but seems administrator submitted the comment on ticket, I need to have the name of Requester

    0
  • Brett - Community Manager
    Comment actions Permalink

    Hey Mohan,

    Any chance you'd be able to provide the API call you're making that's setting the administrator as the submitter of that comment? Feel free to omit any personal information from that call you're making. Any additional information you can provide is greatly appreciated :)

    Thanks!

    0
  • mohan upadhyay
    Comment actions Permalink

    $client->tickets()->update($zendeskTicket,
    array('comment' => array(
    'public' => true,
    'body' => $message
    )
    )
    );

    But comment on ticker being submitted as by Administrator of my Zendesk Account

    0
  • Dan Ross
    Comment actions Permalink

    Hey Mohan,

    To set a different author, try including an author_id property in the comment object.

    Hope that helps.

    1
  • mohan upadhyay
    Comment actions Permalink

    Hey Dan,

    Thank you very much. It works for me.

    0
  • Sandeep Salim
    Comment actions Permalink

    Hi,

    Can anyone please suggest me how to update a comment as an internal one using Python API.

    I tried the below one, but the comment is showing as Public answer and email is sending to the customer,I want to avoid that and whatever i'm updating would like it to be as "Internal or Private one".

    new_ticket.comment = "Commented today "
    new_ticket.Comment.public = False
    ticket_audit = zenpy_client.tickets.update(new_ticket)

    Also tried "new_ticket.Comment.public = False"

    But giving error,

    AttributeError: 'Ticket' object has no attribute 'Comment'

    0
  • Sebastiaan Wijchers
    Comment actions Permalink

    Hello Sandeep,

    I think the capitalized C is the issue here. So you could try:

    new_ticket.comment.public = False

    The text of the comment might also have to be in the body:

    new_ticket.comment.body = "Commented today "

    With kind regards,

    Sebastiaan
    Sparkly ⭐

    0

Please sign in to leave a comment.

Powered by Zendesk