Bookmarks
Bookmark tweets, manage bookmark folders, and search your bookmarks.
bookmarks.create(tweetId)
Bookmark a tweet. Uses the GraphQL BookmarkAdd mutation.
await client.bookmarks.create("1234567890");bookmarks.remove(tweetId)
Remove a tweet from your bookmarks. Uses the GraphQL BookmarkDelete mutation.
await client.bookmarks.remove("1234567890");bookmarks.deleteAll()
Delete all your bookmarks. Uses the GraphQL historyClearMutation mutation.
await client.bookmarks.deleteAll();Warning
This action is irreversible. All bookmarks will be permanently removed.
bookmarks.get(opts?)
Fetch your bookmarked tweets. Uses the GraphQL BookmarkTimeline query. Ads are left out unless you pass opts.ads.
| Option | Type | Description |
|---|---|---|
opts.count | number | Number of results (default 20) |
opts.cursor | string | Pagination cursor |
opts.variables | object | Additional GraphQL variables |
const { tweets, nextCursor } = await client.bookmarks.get();
console.log(tweets[0].text);
// Paginate
const page2 = await client.bookmarks.get({ cursor: nextCursor });
// Fetch more
const more = await client.bookmarks.get({ count: 50 });bookmarks.search(query, opts?)
Search within your bookmarks. Uses the GraphQL bookmarkSearchQuery query.
| Option | Type | Description |
|---|---|---|
query | string | Search query |
opts.count | number | Number of results (default 20) |
opts.cursor | string | Pagination cursor |
opts.variables | object | Additional GraphQL variables |
const { tweets } = await client.bookmarks.search("javascript");bookmarks.folders(opts?)
Get your bookmark folders, one slice at a time. Uses the GraphQL bookmarkFolderPagesQuery query. Folders need Premium.
const { items, cursor } = await client.bookmarks.folders();bookmarks.foldersFor(tweetId?, opts?)
List your folders with whether a tweet is in each one. Uses the GraphQL bookmarksAddToFolderQuery query, or bookmarksAddToFolderFoldersQuery without a tweet.
bookmarks.createFolder(name)
Create a new bookmark folder. Uses the GraphQL bookmarksCreateFolderModalMutation mutation.
await client.bookmarks.createFolder("Read Later");bookmarks.deleteFolder(folderId)
Delete a bookmark folder. Uses the GraphQL bookmarksFolderModalsDeleteMutation mutation.
await client.bookmarks.deleteFolder("1234567890");bookmarks.editFolder(folderId, name)
Rename a bookmark folder. Uses the GraphQL bookmarksFolderModalsEditMutation mutation.
await client.bookmarks.editFolder("1234567890", "New Folder Name");bookmarks.addToFolder(tweetId, folderId)
Add a bookmarked tweet to a specific folder. Uses the GraphQL bookmarksAddToFolderPutMutation mutation.
await client.bookmarks.addToFolder("9876543210", "1234567890");bookmarks.removeFromFolder(tweetId, folderId)
Remove a tweet from a bookmark folder. Uses the GraphQL bookmarksAddToFolderRemoveMutation mutation.
await client.bookmarks.removeFromFolder("9876543210", "1234567890");bookmarks.folderTimeline(folderId, opts?)
Get bookmarked tweets within a specific folder. Uses the GraphQL bookmarkCollectionQuery query.
| Option | Type | Description |
|---|---|---|
folderId | string | The bookmark folder ID |
opts.count | number | Number of results (default 20) |
opts.cursor | string | Pagination cursor |
opts.variables | object | Additional GraphQL variables |
const { tweets, nextCursor } =
await client.bookmarks.folderTimeline("1234567890");
// Paginate
const page2 = await client.bookmarks.folderTimeline("1234567890", {
count: 40,
cursor: nextCursor,
});Full example
// Bookmark a tweet
await client.bookmarks.create("1234567890");
// Create a folder and organize
await client.bookmarks.createFolder("Tech");
const { items: folders } = await client.bookmarks.folders();
const techFolderId = folders[0].id_str;
// Add the tweet to the folder
await client.bookmarks.addToFolder("1234567890", techFolderId);
// Browse folder contents
const { tweets } = await client.bookmarks.folderTimeline(techFolderId);
// Search bookmarks
const { tweets: results } = await client.bookmarks.search("machine learning");
// Clean up
await client.bookmarks.removeFromFolder("1234567890", techFolderId);
await client.bookmarks.remove("1234567890");
await client.bookmarks.deleteFolder(techFolderId);