Lists
Create, manage, and interact with Twitter lists.
Methods that read one list return a parsed list: { id, name, description, private, member_count, subscriber_count, following, banner, facepile, owner, ... }. Timelines of lists, like discover or listMemberships, put them in lists.
lists.create(name, opts?)
Create a new list. Uses the GraphQL ListCreate mutation.
| Option | Type | Description |
|---|---|---|
name | string | The list name |
opts.private | boolean | Make the list private (default false) |
opts.description | string | List description |
await client.lists.create("Tech News");
// Private list with description
await client.lists.create("My Favorites", {
private: true,
description: "People I follow closely",
});lists.remove(listId)
Delete a list you own. Uses the GraphQL listEditSlotDeleteMutation mutation.
await client.lists.remove("1234567890");lists.update(listId, opts?)
Update a list's name, description, or visibility. Uses the GraphQL listEditSlotUpdateMutation mutation.
| Option | Type | Description |
|---|---|---|
listId | string | The list ID |
opts.name | string | New name |
opts.description | string | New description |
opts.private | boolean | Change visibility |
await client.lists.update("1234567890", {
name: "Renamed List",
description: "Updated description",
private: false,
});lists.get(listId)
Get a list by its REST ID. Uses the GraphQL ListByIdQuery query.
const list = await client.lists.get("1234567890");lists.hoverCard(listId) returns the same shape from listHoverCardBodyQuery, and null instead of throwing.
lists.getBySlug(slug, opts?)
Get a list by its slug and owner screen name. Uses the GraphQL listSlugRedirectQuery query. The owner is required now.
| Option | Type | Description |
|---|---|---|
slug | string | The list slug |
opts.ownerScreenName | string | The list owner's username |
const list = await client.lists.getBySlug("tech-news", {
ownerScreenName: "elonmusk",
});lists.addMember(listId, userId)
Add a user to a list. Uses the GraphQL ListMemberAdd mutation. Throws with X's reason when the add is refused.
await client.lists.addMember("1234567890", "44196397");You can't add more than 150 users in 24 hours to a list, or else you'll hit an undocumented ratelimit.
lists.removeMember(listId, userId)
Remove a user from a list. Uses the GraphQL setListMembershipRemoveMutation mutation.
await client.lists.removeMember("1234567890", "44196397");lists.isMember(listId, userIds)
Check whether up to 5 users are members of a list. Uses the GraphQL listMembersSuggestedSlotSearchMembershipQuery query.
await client.lists.isMember("1234567890", ["44196397", "12"]);
// { "44196397": true, "12": false }lists.members(listId, opts?)
Get the members of a list. Uses the GraphQL listMembersQuery query.
| Option | Type | Description |
|---|---|---|
opts.count | number | Number of results (default 20) |
opts.cursor | string | Pagination cursor |
opts.variables | object | Additional GraphQL variables |
const members = await client.lists.members("1234567890", { count: 50 });lists.subscribers(listId, opts?)
Get users who have subscribed to a list. Uses the GraphQL listSubscribersQuery query.
| Option | Type | Description |
|---|---|---|
opts.count | number | Number of results (default 20) |
opts.cursor | string | Pagination cursor |
opts.variables | object | Additional GraphQL variables |
const subs = await client.lists.subscribers("1234567890");lists.subscribe(listId)
Subscribe to a list. Uses the GraphQL followListButtonSubscribeMutation mutation.
await client.lists.subscribe("1234567890");lists.unsubscribe(listId)
Unsubscribe from a list. Uses the GraphQL followListButtonUnsubscribeMutation mutation.
await client.lists.unsubscribe("1234567890");lists.mute(listId)
Mute a list (hide its tweets from your timeline). Uses the legacy GraphQL MuteList mutation, which the web client no longer calls.
await client.lists.mute("1234567890");lists.unmute(listId)
Unmute a list. Uses the legacy GraphQL UnmuteList mutation, which the web client no longer calls.
await client.lists.unmute("1234567890");lists.timeline(listId, opts?)
Get the latest tweets from a list. Uses the GraphQL ListTimeline 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 } = await client.lists.timeline("1234567890");
// Paginate
const next = await client.lists.timeline("1234567890", { cursor: "DAABCgAB..." });lists.ranked(listId, opts?)
Get ranked (algorithmic) tweets from a list. Uses the legacy GraphQL ListRankedTweetsTimeline query, which the web client no longer calls.
| Option | Type | Description |
|---|---|---|
opts.count | number | Number of results (default 20) |
opts.cursor | string | Pagination cursor |
opts.variables | object | Additional GraphQL variables |
const ranked = await client.lists.ranked("1234567890");lists.search(listId, query, opts?)
Search tweets within a list. Uses the legacy GraphQL ListSearchTimeline query, which the web client no longer calls.
| Option | Type | Description |
|---|---|---|
listId | string | The list ID |
query | string | Search query |
opts.count | number | Number of results (default 20) |
opts.cursor | string | Pagination cursor |
opts.variables | object | Additional GraphQL variables |
const results = await client.lists.search("1234567890", "breaking news");lists.ownerships(userId?, opts?)
Get the lists you own, one slice at a time. Uses the GraphQL listAddMemberSlotQuery query, which only answers for your own account. Returns { lists, cursor, raw }.
| Option | Type | Description |
|---|---|---|
userId | string | Your REST ID (defaults to you) |
opts.memberOf | string | A user ID, to mark whether they're in each list |
opts.cursor | string | Pagination cursor |
const { lists } = await client.lists.ownerships();lists.listMemberships(userId, opts?)
Get lists a user is a member of. Uses the GraphQL listsMembershipsQuery query.
| Option | Type | Description |
|---|---|---|
userId | string | The user's REST ID or screen name |
opts.count | number | Number of results (default 20) |
opts.cursor | string | Pagination cursor |
opts.variables | object | Additional GraphQL variables |
const { lists } = await client.lists.listMemberships("44196397");lists.discover(opts?)
Discover suggested lists. Uses the GraphQL ListsDiscovery query.
| Option | Type | Description |
|---|---|---|
opts.count | number | Number of results (default 20) |
opts.cursor | string | Pagination cursor |
opts.variables | object | Additional GraphQL variables |
const suggestions = await client.lists.discover();lists.combined(opts?)
Get the lists a user owns and follows. Uses the GraphQL userListsQuery query. Defaults to you; pass opts.screenName or opts.userId for someone else.
| Option | Type | Description |
|---|---|---|
opts.count | number | Number of results (default 20) |
opts.cursor | string | Pagination cursor |
opts.variables | object | Additional GraphQL variables |
const all = await client.lists.combined();lists.manage(opts?)
Get the list management page timeline. Uses the GraphQL listsManagementQuery query.
| Option | Type | Description |
|---|---|---|
opts.count | number | Number of results (default 20) |
opts.cursor | string | Pagination cursor |
opts.variables | object | Additional GraphQL variables |
const managed = await client.lists.manage();lists.editBanner(listId, mediaId)
Update a list's banner image. Uses the GraphQL listBannerFieldPutMutation mutation.
await client.lists.editBanner("1234567890", "9876543210");lists.deleteBanner(listId)
Remove a list's banner image. Uses the GraphQL listEditSlotDeleteBannerMutation mutation.
await client.lists.deleteBanner("1234567890");lists.pinTimeline(listId)
Pin a list to your home tabs. Uses the GraphQL pinListButtonPinMutation mutation.
await client.lists.pinTimeline("1234567890");lists.unpinTimeline(listId)
Unpin a list from your home tabs. Uses the GraphQL pinListButtonUnpinMutation mutation.
await client.lists.unpinTimeline("1234567890");lists.pinned()
Get your pinned list timelines. Uses the GraphQL pinnedTimelinesQuery query.
const pinned = await client.lists.pinned();lists.recommendedUsers(listId, opts?)
Get suggested accounts to add to a list you own. Uses the GraphQL listEditRecommendedUsersQuery query, or listCreationRecommendedUsersQuery with opts.creation, which is the screen x.com shows right after you create a list. Twitter returns an empty timeline for lists you don't own.
| Param | Type | Description |
|---|---|---|
listId | string | List ID |
opts.creation | boolean | Use the creation suggestions |
opts.count | number | Number of results (default 20) |
opts.cursor | string | Pagination cursor |
opts.variables | object | Additional GraphQL variables |
const { users } = await client.lists.recommendedUsers("1234567890");Full example
// Create a list
await client.lists.create("JavaScript Devs", {
description: "Great JS developers to follow",
private: false,
});
// Add members
await client.lists.addMember(listId, "44196397");
await client.lists.addMember(listId, "12");
// Browse the list timeline
const tweets = await client.lists.timeline(listId, { count: 30 });
// Search within the list
const results = await client.lists.search(listId, "React");
// Pin it to home
await client.lists.pinTimeline(`list-${listId}`);
// Check who's subscribed
const subs = await client.lists.subscribers(listId);
// See all your lists
const myLists = await client.lists.ownerships(client.user.id);
// Discover new lists
const suggestions = await client.lists.discover();
// Clean up
await client.lists.removeMember(listId, "12");
await client.lists.remove(listId);