Post Comments
Users can participate in community discussions by adding comments tocommunity postsin the help center. The user must have a Zendesk account and their requests must be authenticated. Anonymous users can't add comments. For more information, seeAnatomy of the help center.
JSON format
Post Comments are represented as JSON objects with the following properties:
Name | Type | Read-only | Mandatory | Description |
---|---|---|---|---|
author_id | integer | false | false | The id of the author of the comment. Writable on create by Help Center managers. SeeCreate Post Comment |
body | string | false | true | The comment made by the author. SeeUser content |
created_at | string | false | false | When the comment was created. Writable on create by Help Center managers. SeeCreate Post Comment |
html_url | string | true | false | The community url of the comment |
id | integer | true | false | Automatically assigned when the comment is created |
non_author_editor_id | integer | true | false | The user id of whoever performed the most recent (if any) non-author edit. A non-author edit consists of an edit make by a user other than the author that creates or updates thebody . Note that only edits made after May 17, 2021 will be reflected in this field. If no non-author edits have occured since May 17, 2021, then this field will benull . |
non_author_updated_at | string | true | false | When the comment was last edited by a non-author user |
official | boolean | false | false | Whether the comment is marked as official |
post_id | integer | true | false | The id of the post on which the comment was made |
updated_at | string | true | false | When the comment was last updated |
url | string | true | false | The API url of the comment |
vote_count | integer | true | false | The total number of upvotes and downvotes |
vote_sum | integer | true | false | The sum of upvotes (+1) and downvotes (-1), which may be positive or negative |
User content
End users can add their own contents in the form of community posts, post comments, or article comments. Collectively, this is calleduser content. The format of user content is HTML-based.
Content may contain the following standard HTML tags:
- Paragraphs and blocks:
,
,,
- Text formatting:
,
,
,
,
,
,
- Links and dividers:
,
- Images:
(where the
src
attribute has to reference a user-uploaded image)- Headers:
,
,
,
,
,
- Bullet lists:
,
,- Description lists:
,,
- Tables:
<表>
,,
,
,
, , ,
,- Quotes and code snippets:
,
- Semantics:
,
,
,
,
,
,
,
,
,
In addition, the content may contain these non-standard HTML tags:
- @mentions:
, where the contents of the tag should be the user ID of the mentioned user. Example:
to mention the user whose ID is 1234.1234
Even if the content is validated, the body that's output may not be identical to the request body. For example, adjustments may be made for security or standards-compliance reasons.
Example
{
"author_id":89567,
"body":"My printer is on fire!",
“id”:35467,
"official":false,
"vote_count":15,
"vote_sum":10
}
List Comments
GET /api/v2/community/posts/{post_id}/comments
GET /api/v2/community/users/{user_id}/comments
Lists all comments on a specific post or all the comments created by a specific user. When listing comments by specific user, the comments of the user making the request can be listed by specifying
me
as the id.Allowed for
- Agents
- End users
Sideloads
You can sideload related records with the
include
query string parameter. The following sideloads are supported:Name Will sideload users authors posts posts SeeSideloading related records.
Parameters
Name Type In Required Description post_id integer Path true The unique ID of the post Code Samples
curl
curlhttps://{subdomain}.zendesk.com/api/v2/community/posts/{post_id}/comments.json\
-v -u{email_address}:{password}
Go
import(
"fmt"
"io"
"net/http"
)
funcmain(){
url:="https://support.zendesk.com/api/v2/community/posts/360039436873/comments"
方法:="GET"
req,err:=http.NewRequest(方法,url,nil)
iferr!=nil{
fmt.Println(err)
return
}
req.Header.Add("Content-Type","application/json")
req.Header.Add("Authorization","Basic
" )// Base64 encoded "username:password"client:=&http.Client{}
res,err:=client.Do(req)
iferr!=nil{
fmt.Println(err)
return
}
deferres.Body.Close()
body,err:=io.ReadAll(res.Body)
iferr!=nil{
fmt.Println(err)
return
}
fmt.Println(string(body))
}
Java
importcom.squareup.okhttp.*;
OkHttpClientclient=newOkHttpClient();
HttpUrl.BuilderurlBuilder=HttpUrl.parse("https://support.zendesk.com/api/v2/community/posts/360039436873/comments")
.newBuilder();
Requestrequest=newRequest.Builder()
.url(urlBuilder.build())
.方法("GET",null)
.addHeader("Content-Type","application/json")
.addHeader("Authorization",Credentials.basic("your-email","your-password"))
.build();
Responseresponse=client.newCall(request).execute();
Nodejs
弗吉尼亚州raxios=require('axios');
弗吉尼亚州rconfig={
方法:'GET',
url:'https://support.zendesk.com/api/v2/community/posts/360039436873/comments',
headers:{
'Content-Type':'application/json',
'Authorization':'Basic
' ,// Base64 encoded "username:password"},
};
axios(config)
.then(function(response){
console.log(JSON.stringify(response.data));
})
.抓(function(error){
console.log(error);
});
Python
importrequests
url="https://support.zendesk.com/api/v2/community/posts/360039436873/comments"
headers={
"Content-Type":"application/json",
}
response=requests.request(
"GET",
url,
auth=('
' ,'' ),headers=headers
)
print(response.text)
Ruby
require"net/http"
uri=URI("https://support.zendesk.com/api/v2/community/posts/360039436873/comments")
request=Net::HTTP::Get.new(uri,"Content-Type":"application/json")
request.basic_auth"username","password"
response=Net::HTTP.start uri.hostname,uri.port,use_ssl:truedo|http|
http.request(request)
end
Example response(s)
200 OK
// Status 200 OK
{
"comments":[
{
"author_id":89567,
"body":"My printer is on fire!",
“id”:35467
},
{
"author_id":89589,
"body":"My printer is on fire too!",
“id”:36221
}
]
}
显示评论
GET /api/v2/community/posts/{post_id}/comments/{post_comment_id}
Shows information about the specified comment.
Allowed for
- Agents
- End users
Sideloads
The following sideloads are supported:
Name Will sideload users The comment's author posts The comment's post Parameters
Name Type In Required Description post_comment_id integer Path true The unique ID of the post comment post_id integer Path true The unique ID of the post Code Samples
curl
curlhttps://{subdomain}.zendesk.com/api/v2/community/posts/{post_id}/comments/{post_comment_id}.json\
-v -u{email_address}:{password}
Go
import(
"fmt"
"io"
"net/http"
)
funcmain(){
url:="https://support.zendesk.com/api/v2/community/posts/360039436873/comments/360010837133"
方法:="GET"
req,err:=http.NewRequest(方法,url,nil)
iferr!=nil{
fmt.Println(err)
return
}
req.Header.Add("Content-Type","application/json")
req.Header.Add("Authorization","Basic
" )// Base64 encoded "username:password"client:=&http.Client{}
res,err:=client.Do(req)
iferr!=nil{
fmt.Println(err)
return
}
deferres.Body.Close()
body,err:=io.ReadAll(res.Body)
iferr!=nil{
fmt.Println(err)
return
}
fmt.Println(string(body))
}
Java
importcom.squareup.okhttp.*;
OkHttpClientclient=newOkHttpClient();
HttpUrl.BuilderurlBuilder=HttpUrl.parse("https://support.zendesk.com/api/v2/community/posts/360039436873/comments/360010837133")
.newBuilder();
Requestrequest=newRequest.Builder()
.url(urlBuilder.build())
.方法("GET",null)
.addHeader("Content-Type","application/json")
.addHeader("Authorization",Credentials.basic("your-email","your-password"))
.build();
Responseresponse=client.newCall(request).execute();
Nodejs
弗吉尼亚州raxios=require('axios');
弗吉尼亚州rconfig={
方法:'GET',
url:'https://support.zendesk.com/api/v2/community/posts/360039436873/comments/360010837133',
headers:{
'Content-Type':'application/json',
'Authorization':'Basic
' ,// Base64 encoded "username:password"},
};
axios(config)
.then(function(response){
console.log(JSON.stringify(response.data));
})
.抓(function(error){
console.log(error);
});
Python
importrequests
url="https://support.zendesk.com/api/v2/community/posts/360039436873/comments/360010837133"
headers={
"Content-Type":"application/json",
}
response=requests.request(
"GET",
url,
auth=('
' ,'' ),headers=headers
)
print(response.text)
Ruby
require"net/http"
uri=URI("https://support.zendesk.com/api/v2/community/posts/360039436873/comments/360010837133")
request=Net::HTTP::Get.new(uri,"Content-Type":"application/json")
request.basic_auth"username","password"
response=Net::HTTP.start uri.hostname,uri.port,use_ssl:truedo|http|
http.request(request)
end
Example response(s)
200 OK
// Status 200 OK
{
"comment":{
"author_id":89567,
"body":"
I love my new non-flammable printer!
",“id”:35467
}
}
Create Post Comment
POST /api/v2/community/posts/{post_id}/comments
Adds a comment to the specified post.
Allowed for
- Agents
- End users
Agents with the Help Center manager role can optionally supply an
author_id
as part of thecomment
object. If it is provided, the comment's author will be set to the value of theauthor_id
key.Supplying a
notify_subscribers
property with a value of false will prevent subscribers to the comment's post from receiving a comment creation email notification. This can be helpful when creating many comments at a time. Specify the property in the root of the JSON object, not in the "comment" object.Parameters
Name Type In Required Description post_id integer Path true The unique ID of the post Code Samples
curl
curlhttps://{subdomain}.zendesk.com/api/v2/community/posts/{post_id}/comments.json\
-d'{"comment": {"body": "I love my new non-flammable printer!"}, "notify_subscribers": false}'\
-v -u{email_address}:{password}-X POST -H"Content-Type: application/json"
# Setting the comment's author:
curlhttps://{subdomain}.zendesk.com/api/v2/community/posts/{post_id}/comments.json\
-d'{"comment": {"body": "I love my new non-flammable printer!", "author_id": 10056}}'\
-v -u{email_address}:{password}-X POST -H"Content-Type: application/json"
Go
import(
"fmt"
"io"
"net/http"
)
funcmain(){
url:="https://support.zendesk.com/api/v2/community/posts/360039436873/comments"
方法:="POST"
req,err:=http.NewRequest(方法,url,nil)
iferr!=nil{
fmt.Println(err)
return
}
req.Header.Add("Content-Type","application/json")
req.Header.Add("Authorization","Basic
" )// Base64 encoded "username:password"client:=&http.Client{}
res,err:=client.Do(req)
iferr!=nil{
fmt.Println(err)
return
}
deferres.Body.Close()
body,err:=io.ReadAll(res.Body)
iferr!=nil{
fmt.Println(err)
return
}
fmt.Println(string(body))
}
Java
importcom.squareup.okhttp.*;
OkHttpClientclient=newOkHttpClient();
HttpUrl.BuilderurlBuilder=HttpUrl.parse("https://support.zendesk.com/api/v2/community/posts/360039436873/comments")
.newBuilder();
RequestBodybody=RequestBody.create(MediaType.parse("application/json"),
"""
""");
Requestrequest=newRequest.Builder()
.url(urlBuilder.build())
.方法("POST",body)
.addHeader("Content-Type","application/json")
.addHeader("Authorization",Credentials.basic("your-email","your-password"))
.build();
Responseresponse=client.newCall(request).execute();
Nodejs
弗吉尼亚州raxios=require('axios');
弗吉尼亚州rconfig={
方法:'POST',
url:'https://support.zendesk.com/api/v2/community/posts/360039436873/comments',
headers:{
'Content-Type':'application/json',
'Authorization':'Basic
' ,// Base64 encoded "username:password"},
};
axios(config)
.then(function(response){
console.log(JSON.stringify(response.data));
})
.抓(function(error){
console.log(error);
});
Python
importrequests
url="https://support.zendesk.com/api/v2/community/posts/360039436873/comments"
headers={
"Content-Type":"application/json",
}
response=requests.request(
"POST",
url,
auth=('
' ,'' ),headers=headers
)
print(response.text)
Ruby
require"net/http"
uri=URI("https://support.zendesk.com/api/v2/community/posts/360039436873/comments")
request=Net::HTTP::Post.new(uri,"Content-Type":"application/json")
request.basic_auth"username","password"
response=Net::HTTP.start uri.hostname,uri.port,use_ssl:truedo|http|
http.request(request)
end
Example response(s)
201 Created
// Status 201 Created
{
"comment":{
"author_id":89567,
"body":"
I love my new non-flammable printer!
",“id”:35467
}
}
Update Comment
PUT /api/v2/community/posts/{post_id}/comments/{post_comment_id}
Updates the specified comment.
Allowed for
- Agents
- 最终用户创建的评论
Parameters
Name Type In Required Description post_comment_id integer Path true The unique ID of the post comment post_id integer Path true The unique ID of the post Code Samples
curl
curlhttps://{subdomain}.zendesk.com/api/v2/community/posts/{post_id}/comments/{post_comment_id}.json\
-d'{"comment": {"body": "The new, non-flammable printer is on fire too!"}}'\
-v -u{email_address}:{password}- x将- h"Content-Type: application/json"
Go
import(
"fmt"
"io"
"net/http"
)
funcmain(){
url:="https://support.zendesk.com/api/v2/community/posts/360039436873/comments/360010837133"
方法:="PUT"
req,err:=http.NewRequest(方法,url,nil)
iferr!=nil{
fmt.Println(err)
return
}
req.Header.Add("Content-Type","application/json")
req.Header.Add("Authorization","Basic
" )// Base64 encoded "username:password"client:=&http.Client{}
res,err:=client.Do(req)
iferr!=nil{
fmt.Println(err)
return
}
deferres.Body.Close()
body,err:=io.ReadAll(res.Body)
iferr!=nil{
fmt.Println(err)
return
}
fmt.Println(string(body))
}
Java
importcom.squareup.okhttp.*;
OkHttpClientclient=newOkHttpClient();
HttpUrl.BuilderurlBuilder=HttpUrl.parse("https://support.zendesk.com/api/v2/community/posts/360039436873/comments/360010837133")
.newBuilder();
RequestBodybody=RequestBody.create(MediaType.parse("application/json"),
"""
""");
Requestrequest=newRequest.Builder()
.url(urlBuilder.build())
.方法("PUT",body)
.addHeader("Content-Type","application/json")
.addHeader("Authorization",Credentials.basic("your-email","your-password"))
.build();
Responseresponse=client.newCall(request).execute();
Nodejs
弗吉尼亚州raxios=require('axios');
弗吉尼亚州rconfig={
方法:'PUT',
url:'https://support.zendesk.com/api/v2/community/posts/360039436873/comments/360010837133',
headers:{
'Content-Type':'application/json',
'Authorization':'Basic
' ,// Base64 encoded "username:password"},
};
axios(config)
.then(function(response){
console.log(JSON.stringify(response.data));
})
.抓(function(error){
console.log(error);
});
Python
importrequests
url="https://support.zendesk.com/api/v2/community/posts/360039436873/comments/360010837133"
headers={
"Content-Type":"application/json",
}
response=requests.request(
"PUT",
url,
auth=('
' ,'' ),headers=headers
)
print(response.text)
Ruby
require"net/http"
uri=URI("https://support.zendesk.com/api/v2/community/posts/360039436873/comments/360010837133")
request=Net::HTTP::Put.new(uri,"Content-Type":"application/json")
request.basic_auth"username","password"
response=Net::HTTP.start uri.hostname,uri.port,use_ssl:truedo|http|
http.request(request)
end
Example response(s)
200 OK
// Status 200 OK
{
"comment":{
"author_id":89567,
"body":"
I love my new non-flammable printer!
",“id”:35467
}
}
删除Comment
DELETE /api/v2/community/posts/{post_id}/comments/{post_comment_id}
删除s the specified comment.
Allowed for
- Agents
- 最终用户创建的评论
Parameters
Name Type In Required Description post_comment_id integer Path true The unique ID of the post comment post_id integer Path true The unique ID of the post Code Samples
curl
curlhttps://{subdomain}.zendesk.com/api/v2/community/posts/{post_id}/comments/{post_comment_id}.json\
-v -u{email_address}:{password}-X DELETE
Go
import(
"fmt"
"io"
"net/http"
)
funcmain(){
url:="https://support.zendesk.com/api/v2/community/posts/360039436873/comments/360010837133"
方法:="DELETE"
req,err:=http.NewRequest(方法,url,nil)
iferr!=nil{
fmt.Println(err)
return
}
req.Header.Add("Content-Type","application/json")
req.Header.Add("Authorization","Basic
" )// Base64 encoded "username:password"client:=&http.Client{}
res,err:=client.Do(req)
iferr!=nil{
fmt.Println(err)
return
}
deferres.Body.Close()
body,err:=io.ReadAll(res.Body)
iferr!=nil{
fmt.Println(err)
return
}
fmt.Println(string(body))
}
Java
importcom.squareup.okhttp.*;
OkHttpClientclient=newOkHttpClient();
HttpUrl.BuilderurlBuilder=HttpUrl.parse("https://support.zendesk.com/api/v2/community/posts/360039436873/comments/360010837133")
.newBuilder();
Requestrequest=newRequest.Builder()
.url(urlBuilder.build())
.方法("DELETE",null)
.addHeader("Content-Type","application/json")
.addHeader("Authorization",Credentials.basic("your-email","your-password"))
.build();
Responseresponse=client.newCall(request).execute();
Nodejs
弗吉尼亚州raxios=require('axios');
弗吉尼亚州rconfig={
方法:'DELETE',
url:'https://support.zendesk.com/api/v2/community/posts/360039436873/comments/360010837133',
headers:{
'Content-Type':'application/json',
'Authorization':'Basic
' ,// Base64 encoded "username:password"},
};
axios(config)
.then(function(response){
console.log(JSON.stringify(response.data));
})
.抓(function(error){
console.log(error);
});
Python
importrequests
url="https://support.zendesk.com/api/v2/community/posts/360039436873/comments/360010837133"
headers={
"Content-Type":"application/json",
}
response=requests.request(
"DELETE",
url,
auth=('
' ,'' ),headers=headers
)
print(response.text)
Ruby
require"net/http"
uri=URI("https://support.zendesk.com/api/v2/community/posts/360039436873/comments/360010837133")
request=Net::HTTP::删除.new(uri,"Content-Type":"application/json")
request.basic_auth"username","password"
response=Net::HTTP.start uri.hostname,uri.port,use_ssl:truedo|http|
http.request(request)
end
Example response(s)
204 No Content
// Status 204 No Content
null
- Text formatting: