Skip to content

Latest commit

 

History

History
157 lines (111 loc) · 5.65 KB

comments.md

File metadata and controls

157 lines (111 loc) · 5.65 KB

Comments

Comments allow integrations to read and create comments on pages and blocks within Notion. Comments support rich text content and are associated with discussion threads.

Find out more here: https://developers.notion.com/reference/comment-object

CommentsApi commentsApi = client.getCommentsApi();

Class Name

CommentsApi

Methods

List Comments

Retrieves a list of unresolved comments from a page or block. Requires the integration to have read comment capabilities.

Find out more here: https://developers.notion.com/reference/list-comments

CompletableFuture<ApiResponse<PaginatedList>> listCommentsAsync(
    final String notionVersion,
    final UUID blockId,
    final String startCursor,
    final Integer pageSize)

Authentication

This endpoint requires bearerAuth

Parameters

Parameter Type Tags Description
notionVersion String Header, Required The version of the Notion API to use. The current version is 2022-06-28. This header is required for all API requests.
blockId UUID Query, Required The ID of the block or page to retrieve comments for.
startCursor String Query, Optional Pagination cursor to continue fetching results.
pageSize Integer Query, Optional Maximum number of comments to return (max 100).

Constraints: <= 100

Response Type

200: Comments successfully retrieved.

This method returns an ApiResponse instance. The getResult() getter of this instance returns the response data which is of type PaginatedList.

Example Usage

String notionVersion = "2022-06-28";
UUID blockId = UUID.fromString("00000abc-0000-0000-0000-000000000000");

commentsApi.listCommentsAsync(notionVersion, blockId, null, null).thenAccept(result -> {
    // TODO success callback handler
    System.out.println(result);
}).exceptionally(exception -> {
    Throwable cause = exception.getCause();

    if (cause instanceof ErrorException) {
        ErrorException errorException = (ErrorException) cause;
        errorException.printStackTrace();
    } else {
        // fallback for unexpected errors
        exception.printStackTrace();
    }

    return null;
});

Errors

HTTP Status Code Error Description Exception Class
401 The bearer token is missing, invalid, or the integration lacks access. ErrorException
404 The requested resource does not exist or the integration lacks access to it. ErrorException
429 The request has been rate limited. Notion enforces rate limits of 3 requests per second for integrations. Retry after the specified delay. ErrorException

Create Comment

Creates a comment on a page or in an existing discussion thread. The integration must have comment capabilities to use this endpoint.

Find out more here: https://developers.notion.com/reference/create-a-comment

CompletableFuture<ApiResponse<Comment>> createCommentAsync(
    final String notionVersion,
    final CommentsRequest body)

Authentication

This endpoint requires bearerAuth

Parameters

Parameter Type Tags Description
notionVersion String Header, Required The version of the Notion API to use. The current version is 2022-06-28. This header is required for all API requests.
body CommentsRequest Body, Required -

Response Type

200: Comment successfully created.

This method returns an ApiResponse instance. The getResult() getter of this instance returns the response data which is of type Comment.

Example Usage

String notionVersion = "2022-06-28";
CommentsRequest body = new CommentsRequest.Builder(
    Arrays.asList(
        new RichText.Builder(
            Type2.EQUATION,
            "plain_text4"
        )
        .build()
    )
)
.build();

commentsApi.createCommentAsync(notionVersion, body).thenAccept(result -> {
    // TODO success callback handler
    System.out.println(result);
}).exceptionally(exception -> {
    Throwable cause = exception.getCause();

    if (cause instanceof ErrorException) {
        ErrorException errorException = (ErrorException) cause;
        errorException.printStackTrace();
    } else {
        // fallback for unexpected errors
        exception.printStackTrace();
    }

    return null;
});

Errors

HTTP Status Code Error Description Exception Class
400 The request was invalid or malformed. ErrorException
401 The bearer token is missing, invalid, or the integration lacks access. ErrorException
404 The requested resource does not exist or the integration lacks access to it. ErrorException
429 The request has been rate limited. Notion enforces rate limits of 3 requests per second for integrations. Retry after the specified delay. ErrorException