Create New Ticket With Two Comments
Hello,
I want to create a new ticket with two comments via API. One public and one private. The public comment will display the request from the user. The private comment will be added by a bot that pulls information about the type of request to remind the agent of the steps to take for the given request type.
I tried doing a POST request as follows which did not work. The ticket was created but it did not have the comments.
{ "ticket": { "description": "test ticket", "tags": [ "test" ], "comments": [ { "type":"Comment", "body": "comment 1" }, { "type":"Comment", "body": "comment 2" } ], "custom_fields": [ { "id": 360022772534, "value": "test" }, { "id": 360034885213, "value": "test" } ] } }
This is the format used when doing a GET request for comments by ticket. Note I tried type: comment in all lowercase as well which did not work.
Is there a way via the API do do what I am trying to do in a single request?
Thanks in advance.
-
Hi Jackson! There is no way to accomplish this with one API call. You would need to create the ticket first and then update the newly created ticket with the other comment in a second call.
-
Jackson Atkins I don't believe this is possible 😞
Per https://developer.zendesk.com/api-reference/ticketing/tickets/ticket_comments/ The Ticket Comments API has no endpoint to create comments.
Comments are created with the Tickets API https://developer.zendesk.com/api-reference/ticketing/tickets/tickets/
which only accepts comment as an object, not array.
Some thoughts:
1. If the purpose is to remind agent about steps for a request type, perhaps you can create the Subject with a unique keyword/string for that request type. The Subject gets automatically searched with the Knowledge Capture app, which could return articles containing steps for handling this request type. Assuming you use Guide for internal knowledge.
2. Otherwise, perhaps create the ticket with public comment and some kind of tag or custom field to capture type of request, and then use that tag/field to trigger a webhook update, or ZIS, or a custom ticket app to perform the private comment and/or apply a macro...
-
Thanks for the responses. I thought this might be the case but I wanted to check and see if I missed something. Sometimes the API reference allows you to do things that are not documented.
What I'm planning to do then is create a custom field with the type of request. Then, I'll have a webhook fire on all new tickets. I'll read the custom field and have the bot post a private comment to the ticket based on the ticket type (basically your option 2).
I just wanted to make sure I couldn't handle it in one request before going through the trouble of implementing all of this.
-
Greg Katechis - I'm trying to add multiple comments to tickets through the API as well. I have first created the ticket in ZD through the API and am then trying to update the ticket to add an additional comment, but something isn't working, or maybe I just have the format of the request incorrect?
See below:
-
Hey Chris Green,
You'll just need to amend the format of the request body slightly. Here's an example that will add an additional comment to the ticket:
{
"ticket": {
"comment": {
"body": "This is an updated reply on Tuesday",
"public": true
}
}
}Here's a link to the docs that go in to more detail:
https://developer.zendesk.com/api-reference/ticketing/tickets/tickets/#update-ticket
I hope this helps! Feel free to reach out with any questions.
Tipene
-
That did it, thanks Tipene Hughes
-
I found this post when looking for similar functionality on ticket creation. While technically correct, the tickets endpoint only accepts one comment, there is a workaround for creating multiple comments upon ticket creation.
If you use the import tickets endpoint then you can add multiple comments
POST /api/v2/imports/tickets
If you follow the link above you will see the format looks like this:
{
"ticket": {
"assignee_id": 19,
"comments": [
{
"author_id": 827,
"created_at": "2009-06-25T10:15:18Z",
"value": "This is a comment"
},
{
"author_id": 19,
"public": false,
"value": "This is a private comment"
}
],
"description": "A description",
"requester_id": 827,
"subject": "Help",
"tags": [
"foo",
"bar"
]
}
}It is worth noting a couple of quirks of the endpoint. This will not activate any triggers or notifications by design. It will also add the "description" value as a comment even if there is a comment on the ticket (unlike the tickets endpoint which omits the description in favor of any comment that is present).
Hope this helps anybody that finds this ticket after the fact.
Please sign in to leave a comment.
7 Comments