Bookmarks

Overview

The API includes built-in support for bookmarking activities. Here's a quick example of how to use the bookmark API.

Adding Bookmarks

// Adding a bookmark to a new folder
AddBookmarkResponse bookmark = feeds.addBookmark("activity_123",
    AddBookmarkRequest.builder()
        .userID("<user_id>")
        .build()).execute().getData();

// Adding to an existing folder
AddBookmarkResponse bookmarkWithFolder = feeds.addBookmark("activity_123",
    AddBookmarkRequest.builder()
        .folderID("folder_456")
        .userID("<user_id>")
        .build()).execute().getData();

// Update a bookmark (without a folder initially) - add custom data and move it to a new folder
UpdateBookmarkResponse updatedBookmark = feeds.updateBookmark("activity_123",
    UpdateBookmarkRequest.builder()
        .newFolder(AddFolderRequest.builder()
            .name("New folder name")
            .custom(Map.of("icon", "📂"))
            .build())
        .custom(Map.of("color", "blue"))
        .userID("<user_id>")
        .build()).execute().getData();

// Update a bookmark - move it from one existing folder to another existing folder
UpdateBookmarkResponse movedBookmark = feeds.updateBookmark("activity_123",
    UpdateBookmarkRequest.builder()
        .folderID("<old folder id>")
        .newFolderID("<new folder id>")
        .userID("<user_id>")
        .build()).execute().getData();

Removing Bookmarks

// Removing a bookmark
feeds.deleteBookmark(activityId,
    DeleteBookmarkRequest.builder()
        .UserID(testUserId2)
        .build()).execute();

// When you read a feed we include the bookmark
Feed feed = new Feed("user", "sara", feeds);
GetOrCreateFeedResponse response = feed.getOrCreate(GetOrCreateFeedRequest.builder()
    .userID("sara")
    .build()).getData();
System.out.println(response.getActivities().get(0).getOwnBookmarks());
System.out.println(response.getActivities().get(0).getBookmarkCount());

Querying Bookmarks

// Query bookmarks
QueryBookmarksResponse firstPage = feeds.queryBookmarks(QueryBookmarksRequest.builder()
    .filter(Map.of("user_id", "<user id>"))
    .limit(2)
    .build()).execute().getData();

// Get next page
QueryBookmarksResponse secondPage = feeds.queryBookmarks(QueryBookmarksRequest.builder()
    .filter(Map.of("user_id", "<user id>"))
    .limit(2)
    .next(firstPage.getNext())
    .build()).execute().getData();

// Query by activity ID
QueryBookmarksResponse response = feeds.queryBookmarks(QueryBookmarksRequest.builder()
    .filter(Map.of(
        "user_id", "<user id>",
        "activity_id", "activity_123"))
    .build()).execute().getData();

// Query by folder ID
QueryBookmarksResponse folderResponse = feeds.queryBookmarks(QueryBookmarksRequest.builder()
    .filter(Map.of(
        "user_id", "<user id>",
        "folder_id", "folder_456"))
    .build()).execute().getData();

Bookmarks Queryable Built-In Fields

name type description supported operations example
user_id string or list of strings The ID of the user who owns the bookmark $in, $eq { user_id: { $eq: 'user_123' } }
activity_id string or list of strings The ID of the activity that was bookmarked $in, $eq { activity_id: { $eq: 'activity_123' } }
folder_id string or list of strings The ID of the folder containing the bookmark $eq, $in, $exists { folder_id: { $exists: true } }
created_at string, must be formatted as an RFC3339 timestamp The time the bookmark was created $eq, $gt, $gte, $lt, $lte { created_at: { $gte: '2023-12-04T09:30:20.45Z' } }
updated_at string, must be formatted as an RFC3339 timestamp The time the bookmark was last updated $eq, $gt, $gte, $lt, $lte { updated_at: { $gte: '2023-12-04T09:30:20.45Z' } }

Querying Bookmark Folders

// Query bookmark folders
QueryBookmarkFoldersResponse firstPage = feeds.queryBookmarkFolders(QueryBookmarkFoldersRequest.builder()
    .filter(Map.of("user_id", "<user id>"))
    .limit(2)
    .build()).execute().getData();

// Get next page
QueryBookmarkFoldersResponse secondPage = feeds.queryBookmarkFolders(QueryBookmarkFoldersRequest.builder()
    .filter(Map.of("user_id", "<user id>"))
    .limit(2)
    .next(firstPage.getNext())
    .build()).execute().getData();

QueryBookmarkFoldersResponse response = feeds.queryBookmarkFolders(QueryBookmarkFoldersRequest.builder()
    .filter(Map.of(
        "user_id", "<user id>",
        "folder_name", Map.of("$contains", "project")))
    .limit(2)
    .build()).execute().getData();

Bookmark Folders Queryable Built-In Fields

name type description supported operations example
user_id string or list of strings The ID of the user who owns the folder $in, $eq { user_id: { $eq: 'user_123' } }
folder_name string or list of strings The name of the bookmark folder $eq, $in, $contains { folder_name: { $contains: 'work' } }
created_at string, must be formatted as an RFC3339 timestamp The time the folder was created $eq, $gt, $gte, $lt, $lte { created_at: { $gte: '2023-12-04T09:30:20.45Z' } }
updated_at string, must be formatted as an RFC3339 timestamp The time the folder was last updated $eq, $gt, $gte, $lt, $lte { updated_at: { $gte: '2023-12-04T09:30:20.45Z' } }

Managing Bookmark Folders

Update bookmark folder

The endpoint performs a partial update: only the fields you include in the request are changed, and each of those fields is completely overwritten.

Updating a bookmark folder sends feeds.bookmark_folder.updated event to the clients of the user who owns the folder. There are no default client-side SDK handlers for this event, but you can add a custom handler if your UI needs to be updated.

Delete bookmark folder

Use the delete bookmark folder endpoint to remove a folder by ID. All bookmarks in that folder are removed.

Deleting a bookmark folder sends feeds.bookmark_folder.deleted event to the clients of the user who owns the folder. There are no default client-side SDK handlers for this event, but you can add a custom handler if your UI needs to be updated.

// Add a bookmark with a new folder
AddBookmarkResponse addResponse = feeds.addBookmark(activityId,
    AddBookmarkRequest.builder()
        .userID(testUserId)
        .newFolder(AddFolderRequest.builder()
            .name("Breakfast recipes")
            .custom(Map.of("icon", "🍳"))
            .build())
        .build()).execute().getData();

String folderId = addResponse.getBookmark().getFolder().getId();

// Update the folder
UpdateBookmarkFolderResponse updateResponse = feeds.updateBookmarkFolder(folderId,
    UpdateBookmarkFolderRequest.builder()
        .name("Sweet Breakfast Recipes")
        .custom(Map.of("icon", "🥞"))
        .build()).execute().getData();

// Delete the folder (and all bookmarks in it)
feeds.deleteBookmarkFolder(updateResponse.getBookmarkFolder().getId()).execute();