Box Developer Documentation

Create comment

post
https://api.box.com/2.0
/comments

Adds a comment by the user to a specific file, or as a reply to an other comment.

Request

bearer [ACCESS_TOKEN]
application/json

Query Parameters

string arrayin queryoptional
id,type,name

A comma-separated list of attributes to include in the response. This can be used to request fields that are not normally returned in a standard response.

Be aware that specifying this parameter will have the effect that none of the standard fields are returned in the response unless explicitly specified, instead only fields for the mini representation are returned, additional to the fields requested.

Request Body

objectin body

The item to attach the comment to.

stringin bodyrequired
"11446498"

The ID of the item

stringin bodyrequired
"file"

The type of the item that this comment will be placed on.

Value is one of file,comment

stringin bodyrequired
"Review completed!"

The text of the comment.

To mention a user, use the tagged_message parameter instead.

stringin bodyoptional
"@[1234:John] Review completed!"

The text of the comment, including @[user_id:name] somewhere in the message to mention another user, which will send them an email notification, letting them know they have been mentioned.

The user_id is the target user's ID, where the name can be any custom phrase. In the Box UI this name will link to the user's profile.

If you are not mentioning another user, use message instead.

Response

application/jsonComment (Full)

Returns the newly created comment object.

Not all available fields are returned by default. Use the fields query parameter to explicitly request any specific fields.

application/jsonClient error

An unexpected client error.

post
Create comment
You can now try out some of our APIs live, right here in the documentation.
Log in

Request Example

cURL
curl -i -X POST "https://api.box.com/2.0/comments" \
     -H "authorization: Bearer <ACCESS_TOKEN>" \
     -H "content-type: application/json" \
     -d '{
       "message": "Review completed!",
       "item": {
         "type": "file",
         "id": 426436
       }
     }'
TypeScript Gen
await client.comments.createComment({
  message: message,
  item: {
    id: newComment.id!,
    type: 'comment' as CreateCommentRequestBodyItemTypeField,
  } satisfies CreateCommentRequestBodyItemField,
} satisfies CreateCommentRequestBody);
Python Gen
client.comments.create_comment(
    message,
    CreateCommentItem(id=new_comment.id, type=CreateCommentItemTypeField.COMMENT.value),
)
.NET Gen
await client.Comments.CreateCommentAsync(requestBody: new CreateCommentRequestBody(message: message, item: new CreateCommentRequestBodyItemField(id: NullableUtils.Unwrap(newComment.Id), type: CreateCommentRequestBodyItemTypeField.Comment)));
Swift Gen (Beta)
try await client.comments.createComment(requestBody: CreateCommentRequestBody(message: message, item: CreateCommentRequestBodyItemField(id: newComment.id!, type: CreateCommentRequestBodyItemTypeField.comment)))
Java
BoxFile file = new BoxFile(api, "id");
file.addComment("This file is pretty cool.");
Python
comment = client.file(file_id='11111').add_comment('When should I have this done by?')
.NET
var requestParams = new BoxCommentRequest()
{
    Item = new BoxRequestEntity()
    {
        Type = BoxType.File,
        Id = "12345"
    },
    Message = "Great work!"
};
BoxComment comment = await client.CommentsManager.AddCommentAsync(requestParams);
Node
client.comments.create('33333', 'Is this the latest version?')
    .then(comment => {
        /* comment -> {
            type: 'comment',
            id: '11111',
            is_reply_comment: false,
            message: 'Is this the latest version?',
            created_by: 
            { type: 'user',
                id: '22222',
                name: 'Example User',
                login: 'user@example.com' },
            created_at: '2012-12-12T11:25:01-08:00',
            item: { id: '33333', type: 'file' },
            modified_at: '2012-12-12T11:25:01-08:00' }
        */
    });
iOS
client.comments.create(
    itemId: "11111",
    itemType: "file",
    message: "Thanks!"
) { (result: Result<Comment, BoxSDKError>) in
    guard case let .success(comment) = result else {
        print("Error creating comment")
        return
    }

    print("Added comment to \(comment.item.name): \"\(comment.message)\"")
}

Response Example

{
  "id": "11446498",
  "type": "comment",
  "created_at": "2012-12-12T10:53:43-08:00",
  "created_by": {
    "id": "11446498",
    "type": "user",
    "login": "ceo@example.com",
    "name": "Aaron Levie"
  },
  "is_reply_comment": true,
  "item": {
    "id": "11446498",
    "type": "file"
  },
  "message": "@Aaron Levie these tigers are cool!",
  "modified_at": "2012-12-12T10:53:43-08:00",
  "tagged_message": "@[1234567:Aaron Levie] these tigers are cool!"
}