Post a Comment to a Node

You can use this request to post a comment to a node.

/services/v2/node/[nodeId]/comment.json

The following parameters can be used in your post a comment to a node request:

Other options: wrap, v1

🚧

Permissions & Notes:

You must have the Comment under Other Standard Roles, View answers in the question page under Anonymous Roles, and View the question page permissions under Anonymous Roles** under the Advanced Editor.

  • The location response header will contain the URL for the newly created comment.
  • The data describing the comment to be posted can be specified both in the body of the request, or as request parameter with the same names as the fields in the body.
    • When data is sent in the body of the request, the format should match the URL extension or the value of the site's HTTP request header content-type.
    • If data values for the same field are specified both on the request body and as a request or query parameters, the value of the parameters takes precedence over the value in the body.
  • You must have the Use Private Comments and one or more of the following permissions Send private comments to orginal poster, Send private comments to moderators, Send private comments to own groups when making use of the visibility and recipients fields. These capabilities were introduced in 2.16.0*

Sample Request

The comment api has been extended to include the following fields:

visibility: the visibility of the comment.
recipients: the recipients of the comment if visibility value is “recipient”.

Both fields are available when retrieving a comment (GET request) and when posting a comment (POST request).

Example POST samples outlining different situations:

Case 1: API post of a new comment on a question without any privacy information

Request
POST /services/v2/node/{nodeId}/comment.json
{
"body":"Testing API. Node comment text goes here."
}
Response
201

Verification

API get of the created comment should contain the default privacy information currently used (full visibility with no recipients)

Case 2: API post of a new private comment on a question

**Request
POST /services/v2/node/{question_node_Id}/comment.json
{
"body":"Testing API. Node comment text goes here.",
"visibility": "recipients",
"recipients": [ { "id": 101 }, { "id": "102"}]
}

Response
201

Verification
API get of the created comment should contain the defined privacy information

Case 3: API post of a reply on a private comment

Request
POST /services/v2/node/{comment_node_Id}/comment.json
{
"body":"Testing API. Node comment text goes here.",
"visibility": "recipients",
"recipients": [ { "id": 101 }, { "id": "102"}]
}

Response
201

Verification
API get of the created comment should contain the inherited privacy information

Case 4: API post of a reply on a private comment with different privacy information that the replied comment

Request
POST /services/v2/node/{comment_node_Id}/comment.json
{
"body":"Testing API. Node comment text goes here.",
"visibility": "op"
}

Response
400 - Visibility on comment can't be defined since it's inherited

Verification
POST should produce a 400 error

Case 5: API post of a reply on a public comment with different privacy information that the replied comment

Request
POST /services/v2/node/{comment_node_Id}/comment.json
{
"body":"Testing API. Node comment text goes here.",
"visibility": "recipients",
"recipients": [ { "id": 101 }, { "id": "102"}]
}

Response
201

Verification
API get of the created comment should contain the defined privacy information

Case 6: API post of a new private comment on a question without RolesManager.USE_PRIVATE_COMMENTS

Request
POST /services/v2/node/{comment_node_Id}/comment.json
{
"body":"Testing API. Node comment text goes here.",
"visibility": "recipients",
"recipients": [ { "id": 101 }, { "id": "102"}]
}

Response
403 - Forbidden

Verification
POST should produce a 403 response

A POST post a comment to a node request to post a comment ("Customer Success should be able to answer your question.") to a node (nodeId: 845) sent to https://apidocs.cloud.answerhub.com using a human-readable username and password (answerhub/test123), would look like this:

curl 
-u "answerhub:test123" 
-H "Accept: application/json" 
-H "Content-type: application/json" 
-X POST 
-d '{"body":"Customer Success should be able to answer your question."}' "https://apidocs.cloud.answerhub.com/services/v2/node/845/comment.json" -v

Expected Response

Successful Response
If your request was successfully fulfilled, you will see a 201 - Created HTTP Status.

Unsuccessful Response
HTTP Status 400 - In cases where the visibility of the comment is set to something different than the inherited one (visibility for comments replying to other comments cannot be changed if they parent comment has limited visibility. In this case, the reply comment will inherit the visibility of the parent)
-HTTP Status 400 - In case the recipients list is set and visibility is not set to recipients
-HTTP Status 403 - In case the visibility is set to one of the 3 private options and the user lacks permission to use private comments or lacks permission for the option in use

Community User Interface Result

Comment on Question 845

Language
Authentication
Basic
base64
:
Click Try It! to start a request and see the response here!