### Run Gradle Build for Keep API Quickstart Source: https://developers.google.com/workspace/keep/api/guides/java This command executes the Gradle build for the Google Keep API Java quickstart. It compiles and runs the Java application, initiating the process to create a new note in Google Keep after user authorization. ```bash gradle run ``` -------------------------------- ### Set up Google Keep API Quickstart in Java Source: https://developers.google.com/workspace/keep/api/guides/java This Java code snippet demonstrates how to set up the Google Keep API quickstart. It includes necessary imports, authentication using OAuth 2.0, and the creation of a new text note. The code requires a `credentials.json` file for authentication and stores authorization tokens locally. ```java import com.google.api.client.auth.oauth2.Credential; import com.google.api.client.extensions.java6.auth.oauth2.AuthorizationCodeInstalledApp; import com.google.api.client.extensions.jetty.auth.oauth2.LocalServerReceiver; import com.google.api.client.googleapis.auth.oauth2.GoogleAuthorizationCodeFlow; import com.google.api.client.googleapis.auth.oauth2.GoogleClientSecrets; import com.google.api.client.googleapis.javanet.GoogleNetHttpTransport; import com.google.api.client.http.javanet.NetHttpTransport; import com.google.api.client.json.JsonFactory; import com.google.api.client.json.gson.GsonFactory; import com.google.api.client.util.store.FileDataStoreFactory; import com.google.api.services.keep.v1.Keep; import com.google.api.services.keep.v1.model.Note; import com.google.api.services.keep.v1.model.Section; import com.google.api.services.keep.v1.model.TextContent; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.security.GeneralSecurityException; import java.util.Collections; import java.util.List; public class KeepQuickstart { private static final String APPLICATION_NAME = "Google Keep API Java Quickstart"; private static final JsonFactory JSON_FACTORY = GsonFactory.getDefaultInstance(); /** * Global instance of the scopes required by this quickstart. If modifying these scopes, delete * your previously saved tokens/ folder. */ private static final List KEEP_SCOPES = Collections.singletonList("https://www.googleapis.com/auth/keep"); private static final String CREDENTIALS_FILE_PATH = "/credentials.json"; /** * Creates an authorized Credential object. * * @param HTTP_TRANSPORT The network HTTP Transport. * @return An authorized Credential object. * @throws IOException */ private static Credential getOAuthCredentials(final NetHttpTransport HTTP_TRANSPORT) throws IOException { // Load client secrets. InputStream in = KeepQuickstart.class.getResourceAsStream(CREDENTIALS_FILE_PATH); if (in == null) { throw new FileNotFoundException("Resource not found: " + CREDENTIALS_FILE_PATH); } GoogleClientSecrets clientSecrets = GoogleClientSecrets.load(JSON_FACTORY, new InputStreamReader(in)); // Build flow and trigger user authorization request. GoogleAuthorizationCodeFlow flow = new GoogleAuthorizationCodeFlow.Builder( HTTP_TRANSPORT, JSON_FACTORY, clientSecrets, KEEP_SCOPES) .setDataStoreFactory(new FileDataStoreFactory(new java.io.File("tokens"))) .setAccessType("offline") .build(); LocalServerReceiver receiver = new LocalServerReceiver.Builder().setPort(8888).build(); return new AuthorizationCodeInstalledApp(flow, receiver).authorize("user"); } public static void main(String... args) throws IOException, GeneralSecurityException { // Build a new authorized API client service. final NetHttpTransport HTTP_TRANSPORT = GoogleNetHttpTransport.newTrustedTransport(); Keep service = new Keep.Builder(HTTP_TRANSPORT, JSON_FACTORY, getOAuthCredentials(HTTP_TRANSPORT)) .setApplicationName(APPLICATION_NAME) .build(); Section noteBody = new Section().setText(new TextContent().setText("Finish preparations by tomorrow!")); Note newNote = new Note().setTitle("Customer call next week").setBody(noteBody); // Creates a new text note. service.notes().create(newNote).execute(); } } ``` -------------------------------- ### Initialize Java Project with Gradle Source: https://developers.google.com/workspace/keep/api/guides/java Initializes a new basic Java project using Gradle and creates the standard directory structure for main Java code and resources. This sets up the foundation for the application. ```bash gradle init --type basic mkdir -p src/main/java src/main/resources ``` -------------------------------- ### Create Service Account using gcloud CLI Source: https://developers.google.com/workspace/keep/api/guides/java This command creates a new service account with a specified name and display name in your Google Cloud project. It's a prerequisite for authenticating your application. ```bash gcloud iam service-accounts create SERVICE_ACCOUNT_NAME \ --display-name="SERVICE_ACCOUNT_NAME" ``` -------------------------------- ### media.download Source: https://developers.google.com/workspace/keep/api/reference/rest/v1/media/download Gets an attachment. To download attachment media via REST requires the alt=media query parameter. Returns a 400 bad request error if attachment media is not available in the requested MIME type. ```APIDOC ## GET /v1/{name=notes/*/attachments/*} ### Description Retrieves an attachment. To download attachment media, the `alt=media` query parameter must be used. A 400 bad request error is returned if the attachment media is not available in the requested MIME type. ### Method GET ### Endpoint `https://keep.googleapis.com/v1/{name=notes/*/attachments/*}` ### Parameters #### Path Parameters - **name** (string) - Required - The name of the attachment. #### Query Parameters - **mimeType** (string) - Required - The IANA MIME type format requested. The requested MIME type must be one specified in the attachment.mime_type. Required when downloading attachment media and ignored otherwise. ### Request Body The request body must be empty. ### Response #### Success Response (200) - **Attachment** (object) - An instance of the Attachment object if successful. #### Response Example ```json { "attachment": { "fileFileName": "example.txt", "mimeType": "text/plain", "attachmentId": "attachment-id-123", "blobContentReference": { "blobId": "blob-id-456" } } } ``` ### Authorization scopes Requires one of the following OAuth scopes: - `https://www.googleapis.com/auth/keep` - `https://www.googleapis.com/auth/keep.readonly` ``` -------------------------------- ### Methods Source: https://developers.google.com/workspace/keep/api/reference/rest/v1/notes Available methods for interacting with Google Keep notes, including create, delete, get, and list operations. ```APIDOC ## Methods * `create`: Creates a new note. * `delete`: Deletes a note. * `get`: Retrieves a specific note. * `list`: Lists notes. ``` -------------------------------- ### Configure Gradle Build for Keep API Source: https://developers.google.com/workspace/keep/api/guides/java Defines the build configuration for a Java project using Gradle, specifying the main class, Java compatibility, version, repositories, and essential dependencies for interacting with the Google Keep API and OAuth client. ```gradle apply plugin: 'java' apply plugin: 'application' mainClassName = 'KeepQuickstart' version = '1.0' sourceCompatibility = 1.8 targetCompatibility = 1.8 repositories { mavenCentral() } dependencies { implementation 'com.google.api-client:google-api-client:1.23.0' implementation 'com.google.oauth-client:google-oauth-client-jetty:1.23.0' implementation 'com.google.apis:google-api-services-keep:v1-rev20210528-1.31.0' } ``` -------------------------------- ### GET /v1/{name=notes/*} Source: https://developers.google.com/workspace/keep/api/reference/rest/v1/notes/get Retrieves a specific note from Google Keep. This method allows you to fetch the content and metadata of a single note. ```APIDOC ## GET /v1/{name=notes/*} ### Description Gets a note. Stay organized with collections. Save and categorize content based on your preferences. ### Method GET ### Endpoint `https://keep.googleapis.com/v1/{name=notes/*}` ### Parameters #### Path Parameters - **name** (string) - Required - Name of the resource. Format: `notes/*` #### Query Parameters None #### Request Body The request body must be empty. ### Request Example (No request body for this GET request) ### Response #### Success Response (200) - **Note** (object) - An instance of the Note resource containing the note's details. #### Response Example ```json { "name": "notes/note-id", "textContent": "This is the content of the note.", "title": "My Note Title", "createTime": "2023-10-27T10:00:00Z", "updateTime": "2023-10-27T10:05:00Z" } ``` ### Authorization scopes Requires one of the following OAuth scopes: - `https://www.googleapis.com/auth/keep` - `https://www.googleapis.com/auth/keep.readonly` ``` -------------------------------- ### Retrieve and Download Note Attachment using Java Source: https://developers.google.com/workspace/keep/api/guides/retrieve-notes This Java code snippet demonstrates how to retrieve a note and download its first attachment. It requires the Google Keep API client library and involves two API calls: one to get the note's metadata (including attachment information) and another to download the attachment content. The `alt=media` parameter is handled implicitly by the client library. ```java /** * Gets and downloads the attachment of a note. * * @param note The note whose attachment will be downloaded. * @throws IOException */ private void getNoteAttachment(Note note) throws IOException { // First call is to get the attachment resources on the note. List attachments = keepService.notes().get(note.getName()).execute().getAttachments(); if (!attachments.isEmpty()) { Attachment attachment = attachments.get(0); String mimeType = attachment.getMimeType().get(0); // A second call is required in order to download the attachment with the specified mimeType. OutputStream outputStream = new FileOutputStream("attachmentFile." + mimeType.split("/")[1]); keepService .media() .download(attachment.getName()) .setMimeType(mimeType) .executeMediaAndDownloadTo(outputStream); } } ``` -------------------------------- ### Retrieve and Download Note Attachment Source: https://developers.google.com/workspace/keep/api/guides/retrieve-notes This section details how to retrieve a note and download its associated attachment using the Google Keep API. It explains the necessity of calling `media.download()` with the attachment's name and the `alt=media` URL parameter. It also outlines the process of first retrieving the note to get attachment details. ```APIDOC ## GET /v1/notes/{noteId} ### Description Retrieves a specific note and its associated attachments. ### Method GET ### Endpoint `/v1/notes/{noteId}` ### Parameters #### Path Parameters - **noteId** (string) - Required - The unique identifier of the note. ### Request Example ``` GET /v1/notes/12345 ``` ### Response #### Success Response (200) - **attachments** (array) - A list of attachment objects associated with the note. - **name** (string) - The resource name of the attachment. - **mimeType** (array) - The MIME type(s) of the attachment. #### Response Example ```json { "name": "notes/12345", "title": "My Note", "attachments": [ { "name": "attachments/abcdef12345", "mimeType": [ "image/jpeg" ] } ] } ``` ## POST /v1/media/{attachmentName}:download ### Description Downloads the content of a specific attachment. ### Method POST ### Endpoint `/v1/media/{attachmentName}:download` ### Parameters #### Path Parameters - **attachmentName** (string) - Required - The resource name of the attachment to download. #### Query Parameters - **alt** (string) - Required - Set to `media` to indicate a media download request. - **mimeType** (string) - Optional - The MIME type of the attachment to download. ### Request Example ``` POST /v1/media/attachments/abcdef12345?alt=media&mimeType=image/jpeg ``` ### Response #### Success Response (200) - **attachment content** (binary) - The binary content of the attachment. #### Response Example (Binary data representing the attachment file) ``` -------------------------------- ### Media API Source: https://developers.google.com/workspace/keep/api/reference/rest Manage media attachments for Google Keep notes. ```APIDOC ## GET /v1/{name=notes/*/attachments/*} ### Description Gets an attachment associated with a note. ### Method GET ### Endpoint /v1/{name=notes/*/attachments/*} ### Parameters #### Path Parameters - **name** (string) - Required - The name of the attachment to retrieve (e.g., `notes/xxxxxxxxxx/attachments/attachment_id`). ### Response #### Success Response (200) - **mimeType** (string) - The MIME type of the attachment. - **fileUrl** (string) - The URL to download the attachment. - **fileFileName** (string) - The filename of the attachment. #### Response Example ```json { "mimeType": "image/jpeg", "fileUrl": "https://storage.googleapis.com/keep-attachments/xxxxxxxxxx/attachment_id", "fileFileName": "photo.jpg" } ``` ``` -------------------------------- ### Batch Create Permissions Source: https://developers.google.com/workspace/keep/api/reference/rest/v1/notes.permissions/batchCreate Creates one or more permissions on a note. Only permissions with the `WRITER` role can be created. If any permission creation fails, the entire request is rolled back. ```APIDOC ## POST /v1/{parent=notes/*}/permissions:batchCreate ### Description Creates one or more permissions on the note. Only permissions with the `WRITER` role may be created. If adding any permission fails, then the entire request fails and no changes are made. ### Method POST ### Endpoint `https://keep.googleapis.com/v1/{parent=notes/*}/permissions:batchCreate` ### Parameters #### Path Parameters - **parent** (string) - Required - The parent resource shared by all Permissions being created. Format: `notes/{note}`. If this is set, the parent field in the CreatePermission messages must either be empty or match this field. #### Request Body - **requests** (array[object]) - Required - The request message specifying the resources to create. - **requests[].parent** (string) - Required - The parent note where this permission will be created. Format: `notes/{note}` - **requests[].permission** (object) - Required - The permission to create. One of Permission.email, User.email or Group.email must be supplied. ### Request Example ```json { "requests": [ { "parent": "notes/note-id", "permission": { "email": "user@example.com" } } ] } ``` ### Response #### Success Response (200) - **permissions** (array[object]) - Permissions created. - **permissions[].email** (string) - The email address of the user or group the permission applies to. - **permissions[].role** (string) - The role of the user or group (e.g., WRITER). #### Response Example ```json { "permissions": [ { "email": "user@example.com", "role": "WRITER" } ] } ``` ### Authorization scopes - `https://www.googleapis.com/auth/keep` ``` -------------------------------- ### List Notes with Filtering and Pagination (Java) Source: https://developers.google.com/workspace/keep/api/guides/list-notes This Java code snippet demonstrates how to list notes using the Google Keep API. It shows how to apply filters for creation time and trash status, set the page size, and retrieve paginated results using a page token. The `keepService.notes().list()` method is central to these operations. ```Java /** Lists notes using different filtering and pagination options. */ private void listNotes() throws IOException { // Lists 3 notes that were created after a specified timestamp and that are not trashed. Results // are ordered by most recently modified first. ListNotesResponse response = keepService .notes() .list() .setFilter("create_time > \"2021-01-01T00:00:00Z\"") .setFilter("-trashed") .setPageSize(3) .execute(); System.out.println("List notes response: " + response); // Lists notes using a pagination token. ListNotesResponse firstPageResponse = keepService.notes().list().setPageSize(1).execute(); String nextPageToken = firstPageResponse.getNextPageToken(); for (int i = 0; i < 5; i++) { // Uses the page token that was returned by the previous page's next page token. ListNotesResponse pagedResponse = keepService.notes().list().setPageSize(1).setPageToken(nextPageToken).execute(); System.out.println("Listing note:" + pagedResponse); nextPageToken = pagedResponse.getNextPageToken(); } } ``` -------------------------------- ### notes.list - List Notes Source: https://developers.google.com/workspace/keep/api/reference/rest/v1/notes/list Retrieves a list of notes. This method supports pagination using `nextPageToken` and filtering based on various fields. ```APIDOC ## GET /v1/notes ### Description Lists notes. Every list call returns a page of results with `pageSize` as the upper bound of returned items. A `pageSize` of zero allows the server to choose the upper bound. The ListNotesResponse contains at most `pageSize` entries. If there are more things left to list, it provides a `nextPageToken` value. To get the next page of results, copy the result's `nextPageToken` into the next request's `pageToken`. Repeat until the `nextPageToken` returned with a page of results is empty. ### Method GET ### Endpoint `https://keep.googleapis.com/v1/notes` ### Query Parameters #### Query Parameters - **pageSize** (integer) - Optional - The maximum number of results to return. - **pageToken** (string) - Optional - The previous page's `nextPageToken` field. - **filter** (string) - Optional - Filter for list results. If no filter is supplied, the `trashed` filter is applied by default. Valid fields to filter by are: `createTime`, `updateTime`, `trashTime`, and `trashed`. Filter syntax follows the Google AIP filtering spec. ### Request Body The request body must be empty. ### Response #### Success Response (200) - **notes** (array of objects) - A page of notes. - **nextPageToken** (string) - Next page's `pageToken` field. #### Response Example ```json { "notes": [ { "id": "note-id-1", "title": "Shopping List", "textContent": "Milk, Eggs, Bread", "createTime": "2023-01-01T10:00:00Z", "updateTime": "2023-01-01T10:05:00Z" }, { "id": "note-id-2", "title": "Meeting Notes", "textContent": "Discuss project roadmap.", "createTime": "2023-01-02T14:30:00Z", "updateTime": "2023-01-02T15:00:00Z" } ], "nextPageToken": "some-opaque-token" } ``` ### Authorization Scopes Requires one of the following OAuth scopes: - `https://www.googleapis.com/auth/keep` - `https://www.googleapis.com/auth/keep.readonly` ``` -------------------------------- ### Media Resource - Download Attachment Source: https://developers.google.com/workspace/keep/api/reference/rest/v1/media The 'download' method allows you to retrieve an attachment associated with a Google Keep note. This resource does not have persistent data. ```APIDOC ## GET /websites/developers_google_workspace_keep_api/media/download ### Description Gets an attachment. This resource does not have persistent data associated with it. ### Method GET ### Endpoint /websites/developers_google_workspace_keep_api/media/download ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **attachment_data** (bytes) - The content of the attachment. #### Response Example ``` (Binary data of the attachment) ``` ``` -------------------------------- ### Permissions API Source: https://developers.google.com/workspace/keep/api/reference/rest Manage sharing permissions for Google Keep notes. ```APIDOC ## POST /v1/{parent=notes/*}/permissions:batchCreate ### Description Creates one or more permissions on the note, effectively sharing the note with other users. ### Method POST ### Endpoint /v1/{parent=notes/*}/permissions:batchCreate ### Parameters #### Path Parameters - **parent** (string) - Required - The name of the note to add permissions to (e.g., `notes/xxxxxxxxxx`). ### Request Body - **permissions** (array) - Required - A list of permissions to create. - **email** (string) - Required - The email address of the user to share with. - **role** (string) - Optional - The role to grant (e.g., `READER`, `WRITER`). Defaults to `WRITER`. ### Request Example ```json { "permissions": [ { "email": "user1@example.com", "role": "WRITER" }, { "email": "user2@example.com", "role": "READER" } ] } ``` ### Response #### Success Response (200) - **permissions** (array) - A list of the created permissions. - **name** (string) - The unique identifier for the permission. - **email** (string) - The email address of the user. - **role** (string) - The role granted. #### Response Example ```json { "permissions": [ { "name": "notes/xxxxxxxxxx/permissions/permission_id_1", "email": "user1@example.com", "role": "WRITER" }, { "name": "notes/xxxxxxxxxx/permissions/permission_id_2", "email": "user2@example.com", "role": "READER" } ] } ``` --- ## POST /v1/{parent=notes/*}/permissions:batchDelete ### Description Deletes one or more permissions on the note, effectively revoking access for users. ### Method POST ### Endpoint /v1/{parent=notes/*}/permissions:batchDelete ### Parameters #### Path Parameters - **parent** (string) - Required - The name of the note from which to delete permissions (e.g., `notes/xxxxxxxxxx`). ### Request Body - **names** (array) - Required - A list of the full resource names of the permissions to delete (e.g., `["notes/xxxxxxxxxx/permissions/permission_id_1", "notes/xxxxxxxxxx/permissions/permission_id_2"]`). ### Request Example ```json { "names": [ "notes/xxxxxxxxxx/permissions/permission_id_1", "notes/xxxxxxxxxx/permissions/permission_id_2" ] } ``` ### Response #### Success Response (200) An empty response body indicates successful deletion. ``` -------------------------------- ### POST /v1/notes Source: https://developers.google.com/workspace/keep/api/reference/rest/v1/notes/create Creates a new note in Google Keep. This endpoint allows users to save and categorize content based on their preferences. ```APIDOC ## POST /v1/notes ### Description Creates a new note. Stay organized with collections. Save and categorize content based on your preferences. ### Method POST ### Endpoint `https://keep.googleapis.com/v1/notes` ### Parameters #### Request Body - **Note** (object) - Required - An instance of the Note object representing the note to be created. ### Request Example ```json { "title": "My First Note", "content": "This is the content of my first note.", "labels": [ { "name": "Important" } ] } ``` ### Response #### Success Response (200) - **Note** (object) - A newly created instance of the Note object. #### Response Example ```json { "name": "notes/xxxxxxxxxxxx", "title": "My First Note", "content": "This is the content of my first note.", "labels": [ { "name": "Important" } ], "createdAt": "2023-10-27T10:00:00Z", "updatedAt": "2023-10-27T10:00:00Z" } ``` ### Authorization scopes Requires the following OAuth scope: - `https://www.googleapis.com/auth/keep` ``` -------------------------------- ### Create Text Note using Google Keep API (Java) Source: https://developers.google.com/workspace/keep/api/guides/create-notes This snippet demonstrates how to create a simple text note using the Google Keep API. It requires the `keepService` object and constructs a `Note` resource with `TextContent` in its `Section`. ```java /** * Creates a new text note. * * @throws IOException * @return The newly created text note. */ private Note createTextNote(String title, String textContent) throws IOException { Section noteBody = new Section().setText(new TextContent().setText(textContent)); Note newNote = new Note().setTitle(title).setBody(noteBody); return keepService.notes().create(newNote).execute(); } ``` -------------------------------- ### Notes API Source: https://developers.google.com/workspace/keep/api/reference/rest Manage Google Keep notes. This includes creating, retrieving, listing, and deleting notes. ```APIDOC ## POST /v1/notes ### Description Creates a new note. ### Method POST ### Endpoint /v1/notes ### Request Body - **title** (string) - Optional - The title of the note. - **textContent** (string) - Optional - The plain text content of the note. - **listContent** (array) - Optional - A list of list items for a checklist note. - **text** (string) - The text of the list item. - **checked** (boolean) - Whether the list item is checked. - **colorId** (string) - Optional - The color of the note, specified as a hex string (e.g., "#FFFFFF"). - **labels** (array) - Optional - A list of label IDs associated with the note. - **attachments** (array) - Optional - A list of attachments for the note. - **mimeType** (string) - The MIME type of the attachment. - **fileUrl** (string) - The URL of the attachment. - **fileFileName** (string) - The filename of the attachment. ### Request Example ```json { "title": "Shopping List", "listContent": [ { "text": "Milk", "checked": false }, { "text": "Bread", "checked": true }, { "text": "Eggs", "checked": false } ], "colorId": "#FDCF3E" } ``` ### Response #### Success Response (200) - **name** (string) - The unique identifier for the note. - **title** (string) - The title of the note. - **textContent** (string) - The plain text content of the note. - **listContent** (array) - A list of list items for a checklist note. - **colorId** (string) - The color of the note. - **labels** (array) - A list of label IDs associated with the note. - **attachments** (array) - A list of attachments for the note. - **createTime** (string) - The timestamp when the note was created. - **updateTime** (string) - The timestamp when the note was last updated. #### Response Example ```json { "name": "notes/xxxxxxxxxx", "title": "Shopping List", "listContent": [ { "text": "Milk", "checked": false }, { "text": "Bread", "checked": true }, { "text": "Eggs", "checked": false } ], "colorId": "#FDCF3E", "createTime": "2023-10-27T10:00:00Z", "updateTime": "2023-10-27T10:05:00Z" } ``` --- ## DELETE /v1/{name=notes/*} ### Description Deletes a note. ### Method DELETE ### Endpoint /v1/{name=notes/*} ### Parameters #### Path Parameters - **name** (string) - Required - The name of the note to delete (e.g., `notes/xxxxxxxxxx`). ### Response #### Success Response (200) An empty response body indicates successful deletion. --- ## GET /v1/{name=notes/*} ### Description Gets a note. ### Method GET ### Endpoint /v1/{name=notes/*} ### Parameters #### Path Parameters - **name** (string) - Required - The name of the note to retrieve (e.g., `notes/xxxxxxxxxx`). ### Response #### Success Response (200) - **name** (string) - The unique identifier for the note. - **title** (string) - The title of the note. - **textContent** (string) - The plain text content of the note. - **listContent** (array) - A list of list items for a checklist note. - **colorId** (string) - The color of the note. - **labels** (array) - A list of label IDs associated with the note. - **attachments** (array) - A list of attachments for the note. - **createTime** (string) - The timestamp when the note was created. - **updateTime** (string) - The timestamp when the note was last updated. #### Response Example ```json { "name": "notes/xxxxxxxxxx", "title": "Meeting Notes", "textContent": "Discussed project roadmap and deadlines.", "colorId": "#FFFFFF", "createTime": "2023-10-26T09:00:00Z", "updateTime": "2023-10-26T09:30:00Z" } ``` --- ## GET /v1/notes ### Description Lists notes. ### Method GET ### Endpoint /v1/notes ### Query Parameters - **pageSize** (integer) - Optional - The maximum number of notes to return per page. - **pageToken** (string) - Optional - A page token, received from a previous `list` call. - **filter** (string) - Optional - A filter for the notes to return (e.g., `label:"label_id"`, `isPinned:true`). ### Response #### Success Response (200) - **notes** (array) - A list of notes. - **name** (string) - The unique identifier for the note. - **title** (string) - The title of the note. - **createTime** (string) - The timestamp when the note was created. - **updateTime** (string) - The timestamp when the note was last updated. - **nextPageToken** (string) - A token to retrieve the next page of results. #### Response Example ```json { "notes": [ { "name": "notes/xxxxxxxxxx", "title": "To-Do List", "createTime": "2023-10-25T14:00:00Z", "updateTime": "2023-10-25T14:15:00Z" }, { "name": "notes/yyyyyyyyyy", "title": "Ideas for Blog Post", "createTime": "2023-10-24T11:00:00Z", "updateTime": "2023-10-24T11:00:00Z" } ], "nextPageToken": "nextPageTokenString" } ``` ``` -------------------------------- ### notes.permissions.batchDelete Source: https://developers.google.com/workspace/keep/api/reference/rest/v1/notes.permissions/batchDelete Deletes one or more permissions on a note. Specified entities will immediately lose access. Permissions with the OWNER role cannot be removed. If any permission deletion fails, the entire request fails. ```APIDOC ## POST /v1/{parent=notes/*}/permissions:batchDelete ### Description Deletes one or more permissions on the note. The specified entities will immediately lose access. A permission with the `OWNER` role can't be removed. If removing a permission fails, then the entire request fails and no changes are made. Returns a 400 bad request error if a specified permission does not exist on the note. ### Method POST ### Endpoint `https://keep.googleapis.com/v1/{parent=notes/*}/permissions:batchDelete` ### Parameters #### Path Parameters - **parent** (string) - Required - The parent resource shared by all permissions being deleted. Format: `notes/{note}`. If this is set, the parent of all of the permissions specified in the DeletePermissionRequest messages must match this field. #### Request Body - **names** (array of strings) - Required - The names of the permissions to delete. Format: `notes/{note}/permissions/{permission}` ### Request Example ```json { "names": [ "notes/noteId/permissions/permissionId1", "notes/noteId/permissions/permissionId2" ] } ``` ### Response #### Success Response (200) An empty JSON object indicates success. #### Response Example ```json {} ``` ### Authorization scopes - `https://www.googleapis.com/auth/keep` ``` -------------------------------- ### Create List Note using Google Keep API (Java) Source: https://developers.google.com/workspace/keep/api/guides/create-notes This snippet shows how to create a list note with various item types (checked, unchecked, and nested) using the Google Keep API. It utilizes `ListItem` and `ListContent` within the `Note` resource. ```java /** * Creates a new list note. * * @throws IOException * @return The newly created list note. */ private Note createListNote() throws IOException { // Create a checked list item. ListItem checkedListItem = new ListItem().setText(new TextContent().setText("Send meeting invites")).setChecked(true); // Create a list item with two children. ListItem uncheckedListItemWithChildren = new ListItem() .setText(new TextContent().setText("Prepare the presentation")) .setChecked(false) .setChildListItems( Arrays.asList( new ListItem().setText(new TextContent().setText("Review metrics")), new ListItem().setText(new TextContent().setText("Analyze sales projections")), new ListItem().setText(new TextContent().setText("Share with leads")))); // Creates an unchecked list item. ListItem uncheckedListItem = new ListItem().setText(new TextContent().setText("Send summary email")).setChecked(true); Note newNote = new Note() .setTitle("Marketing review meeting") .setBody( new Section() .setList( new ListContent() .setListItems( Arrays.asList( checkedListItem, uncheckedListItemWithChildren, uncheckedListItem)))); return keepService.notes().create(newNote).execute(); } ``` -------------------------------- ### Add Collaborators using Batch Create Permissions Source: https://developers.google.com/workspace/keep/api/guides/modify-permissions This endpoint allows you to add collaborators (users or groups) to a note by granting them 'WRITER' role. It uses the `notes.permissions.batchCreate()` method. ```APIDOC ## POST /v1/notes.permissions.batchCreate ### Description Grants write access to a user and/or a Google group for a given note. ### Method POST ### Endpoint `https://keep.googleapis.com/v1/notes.permissions.batchCreate` ### Parameters #### Path Parameters None #### Query Parameters - **parent** (string) - Required - The name of the note to which permissions will be added. Format: `notes/{noteId}`. #### Request Body - **requests** (array of objects) - Required - A list of `CreatePermissionRequest` objects. - **permission** (object) - Required - The permission to create. - **email** (string) - Required - The email address of the user or group. - **role** (string) - Required - The role to grant. Must be 'WRITER'. ### Request Example ```json { "requests": [ { "permission": { "email": "user@example.com", "role": "WRITER" } }, { "permission": { "email": "group@example.com", "role": "WRITER" } } ] } ``` ### Response #### Success Response (200) - **createdPermissions** (array of objects) - A list of the permissions that were created. - **name** (string) - The resource name of the permission. - **email** (string) - The email address of the user or group. - **role** (string) - The role granted. #### Response Example ```json { "createdPermissions": [ { "name": "notes/noteId/permissions/permissionId1", "email": "user@example.com", "role": "WRITER" }, { "name": "notes/noteId/permissions/permissionId2", "email": "group@example.com", "role": "WRITER" } ] } ``` ``` -------------------------------- ### Resource: Permission Source: https://developers.google.com/workspace/keep/api/reference/rest/v1/notes Defines a single permission on a note, associating a member with a role. It can represent a user, group, or family. ```APIDOC ## Resource: Permission A single permission on the note. Associates a `member` with a `role`. ### JSON Representation ```json { "name": string, "role": enum (Role), "email": string, "deleted": boolean, "member": { "user": { "object": "User" }, "group": { "object": "Group" }, "family": { "object": "Family" } } } ``` ### Fields * `name` (string) - Output only. The resource name. * `role` (enum) - The role granted by this permission (e.g., OWNER, WRITER). * `email` (string) - The email associated with the member. * `deleted` (boolean) - Output only. Whether this member has been deleted. * `member` (object) - Union field. Specifies the identity granted the role. Can be one of `user`, `group`, or `family`. ``` -------------------------------- ### Resource: Note Source: https://developers.google.com/workspace/keep/api/reference/rest/v1/notes Represents a single note in Google Keep. It includes fields for title, body, creation/update times, and associated attachments and permissions. ```APIDOC ## Resource: Note A single note. ### JSON Representation ```json { "name": string, "createTime": string, "updateTime": string, "trashTime": string, "trashed": boolean, "attachments": [ { "object": "Attachment" } ], "permissions": [ { "object": "Permission" } ], "title": string, "body": { "object": "Section" } } ``` ### Fields * `name` (string) - Output only. The resource name of this note. * `createTime` (string) - Output only. When this note was created (Timestamp format). * `updateTime` (string) - Output only. When this note was last modified (Timestamp format). * `trashTime` (string) - Output only. When this note was trashed (Timestamp format). * `trashed` (boolean) - Output only. `true` if this note has been trashed. * `attachments` (array of objects) - Output only. The attachments attached to this note. * `permissions` (array of objects) - Output only. The list of permissions set on the note. * `title` (string) - The title of the note. Max length: 1,000 characters. * `body` (object) - The body of the note (Section object). ``` -------------------------------- ### CreatePermissionRequest JSON Structure Source: https://developers.google.com/workspace/keep/api/reference/rest/v1/notes.permissions/batchCreate This snippet illustrates the JSON structure for a single permission creation request within the batchCreate method. It specifies the parent note and the permission details to be added. ```JSON { "parent": "notes/{note}", "permission": { "email": "user@example.com" } } ``` -------------------------------- ### Keep API Methods Source: https://developers.google.com/workspace/keep/api/reference/rest/v1/notes This section outlines the core methods provided by the Google Workspace Keep API for managing notes. ```APIDOC ## Keep API Methods ### `create` #### Description Creates a new note. #### Method POST #### Endpoint `/v1/notes` ### `delete` #### Description Deletes a note. #### Method DELETE #### Endpoint `/v1/notes/{noteId}` ### `get` #### Description Gets a note. #### Method GET #### Endpoint `/v1/notes/{noteId}` ### `list` #### Description Lists notes. #### Method GET #### Endpoint `/v1/notes` ``` -------------------------------- ### Resource: Family Source: https://developers.google.com/workspace/keep/api/reference/rest/v1/notes Describes a single Google Family. This type has no fields. ```APIDOC ## Resource: Family Describes a single Google Family. ### JSON Representation ```json { // This type has no fields. } ``` ``` -------------------------------- ### Resource: User Source: https://developers.google.com/workspace/keep/api/reference/rest/v1/notes Describes a single user with their email address. ```APIDOC ## Resource: User Describes a single user. ### JSON Representation ```json { "email": string } ``` ### Fields * `email` (string) - The user's email. ``` -------------------------------- ### Batch Create Permissions Response Body Source: https://developers.google.com/workspace/keep/api/reference/rest/v1/notes.permissions/batchCreate This snippet shows the expected JSON response body upon successful creation of permissions using the batchCreate method. It contains a list of the permissions that were successfully created. ```JSON { "permissions": [ { "id": "permission-id", "email": "user@example.com", "role": "WRITER" } ] } ``` -------------------------------- ### Add Collaborators to a Note using Permissions (Java) Source: https://developers.google.com/workspace/keep/api/guides/modify-permissions This Java code snippet demonstrates how to grant 'WRITER' access to a user and a Google group for a specific note using the `notes.permissions.batchCreate()` method. It requires the note object, user email, and group email as input. ```java /** * Grants write access to a user and to a Google group for the given note. * * @param note The note whose permissions will be updated. * @param userEmail Email address of the user that will be added to the permissions of the note. * @param groupEmail Email address of the Google group that will be added to the permissions of * the note. * @throws IOException * @return The response of the create permissions request. */ private BatchCreatePermissionsResponse addPermissions( Note note, String userEmail, String groupEmail) throws IOException { String noteName = note.getName(); CreatePermissionRequest userPermission = new CreatePermissionRequest() .setParent(noteName) .setPermission(new Permission().setEmail(userEmail).setRole("WRITER")); CreatePermissionRequest groupPermission = new CreatePermissionRequest() .setParent(noteName) .setPermission(new Permission().setEmail(groupEmail).setRole("WRITER")); BatchCreatePermissionsRequest batchCreatePermissionsRequest = new BatchCreatePermissionsRequest() .setRequests(Arrays.asList(userPermission, groupPermission)); return keepService .notes() .permissions() .batchCreate(noteName, batchCreatePermissionsRequest) .execute(); } ``` -------------------------------- ### Note Resource Structure (JSON) Source: https://developers.google.com/workspace/keep/api/reference/rest/v1/notes Defines the structure of a single note resource in the Google Keep API. It includes fields for name, timestamps, trash status, attachments, permissions, title, and body content. ```json { "name": string, "createTime": string, "updateTime": string, "trashTime": string, "trashed": boolean, "attachments": [ { object (Attachment) } ], "permissions": [ { object (Permission) } ], "title": string, "body": { object (Section) } } ``` -------------------------------- ### Batch Create Permissions HTTP Request Source: https://developers.google.com/workspace/keep/api/reference/rest/v1/notes.permissions/batchCreate This snippet shows the structure of an HTTP POST request to the Google Keep API for batch creating permissions on a note. It includes the endpoint and the expected JSON request body format. ```HTTP POST https://keep.googleapis.com/v1/{parent=notes/*}/permissions:batchCreate { "requests": [ { "parent": "notes/{note}", "permission": { "email": "user@example.com" } } ] } ``` -------------------------------- ### List Content Structure Source: https://developers.google.com/workspace/keep/api/reference/rest/v1/notes Details the structure for list-based note content, including list items and nesting. ```APIDOC ## List Content ### `ListContent` Represents the list of items for a single list note. #### Fields - **`listItems`** (`array` of `ListItem`): The items in the list. The number of items must be less than 1,000. ### `ListItem` Represents a single list item in a note's list. #### Fields - **`childListItems`** (`array` of `ListItem`): If set, contains a list of list items nested under this list item. Only one level of nesting is allowed. - **`text`** (`object` of `TextContent`): The text of this list item. The length must be less than 1,000 characters. - **`checked`** (`boolean`): Indicates whether this list item has been checked off or not. ``` -------------------------------- ### Note Content Structure Source: https://developers.google.com/workspace/keep/api/reference/rest/v1/notes Defines the structure for the content of a note, which can be either text or a list. ```APIDOC ## Note Content ### `Content` (Union Field) Represents the content of a note section. It can be one of the following types: - **`text`** (`object` of `TextContent`): Used for plain text content. The length of the text content must be less than 20,000 characters. - **`list`** (`object` of `ListContent`): Used for list content. ### `TextContent` Represents a block of text for a single text section or list item. #### Fields - **`text`** (`string`): The text content. The limits on this vary with the specific field using this type. ```