This is a comprehensive guide of all methods available for the Twitter API v2 on twitter-api-v2
package.
Every presented method in this guide is attached to v2 client, that you can access through
client.v2
.If you don't find the endpoint you want, don't panic! It probably hasn't been implemented yet. You can make your request manually using generic requests handlers
.get
,.post
,.put
,.patch
and.delete
methods. See the HTTP wrappers documentation.
Argument note: Described arguments often refers to an interface name. Generally, argument type is a Partial<>
(all properties are optionals) of the given interface.
Return type note: All return types are wrapped inside Promise
s.
Twitter API v2 intensively uses
includes
to efficiently attach data to items (medias, polls, users, ...) fetched through the API. An includes helper is available here to help you browsing included metas in your response data.
For streaming API, see Streaming part.
- API v2
- Tweet timelines
- Tweets
- Create a tweet
- Reply to a tweet
- Post a thread of tweets
- Delete a tweet
- Get a Single tweet
- Lookup for tweets
- Get users that liked a specific tweet
- Like a tweet
- Unlike a tweet
- Get tweet counts for a search (recent tweet only)
- Get tweet counts for a search (full archive)
- Get users that retweeted a specific tweet
- Retweet a tweet
- Unretweet a tweet
- List quoted replies of a tweet
- Bookmarks
- Users
- Lists
- Spaces
- Direct messages (DMs)
- Batch compliance
Search tweets of the last 7 days with a text query. Get to know how paginators work here.
Method: .search()
Endpoint: tweets/search/recent
Right level: Read-only
Arguments:
query: string
options?: Tweetv2SearchParams
or
options?: Tweetv2SearchParams
Returns: TweetSearchRecentV2Paginator
Example
const jsTweets = await client.v2.search('JavaScript', { 'media.fields': 'url' });
// Consume every possible tweet of jsTweets (until rate limit is hit)
for await (const tweet of jsTweets) {
console.log(tweet);
}
Search tweets (from Twitter creation in 2006) with a text query. Get to know how paginators work here.
Method: .searchAll()
Endpoint: tweets/search/all
Right level: Read-only
Arguments:
query: string
options?: Tweetv2SearchParams
Returns: TweetSearchAllV2Paginator
Example
const jsTweets = await client.v2.searchAll('JavaScript', { 'media.fields': 'url' });
// Consume fetched tweet from first page of jsTweets
for (const tweet of jsTweets) {
console.log(tweet);
}
Get reverse chronological tweet timeline of logged user. Get to know how paginators work here.
Method: .homeTimeline()
Endpoint: users/:id/timelines/reverse_chronological
Right level: Read-only
Arguments:
options?: TweetV2HomeTimelineParams
Returns: TweetHomeTimelineV2Paginator
(containing TweetV2
entities)
Example
const homeTimeline = await client.v2.homeTimeline({ exclude: 'replies' });
Get tweets of user userId
.
Get to know how paginators work here.
Method: .userTimeline()
Endpoint: users/:id/tweets
Right level: Read-only
Arguments:
userId: string
options?: TweetV2UserTimelineParams
Returns: TweetUserTimelineV2Paginator
Example
const tweetsOfJack = await client.v2.userTimeline('12', { exclude: 'replies' });
Get mentions of user userId
.
Get to know how paginators work here.
Method: .userMentionTimeline()
Endpoint: users/:id/mentions
Right level: Read-only
Arguments:
userId: string
options?: TweetV2UserTimelineParams
Returns: TweetUserMentionTimelineV2Paginator
Example
const tweetsOfJack = await client.v2.userMentionTimeline('12', { end_time: '2020-01-01' });
Post a new tweet.
Method: .tweet()
Endpoint: tweets
Right level: Read-write
Arguments:
statusOrPayload: string | SendTweetV2Params
payload?: SendTweetV2Params
Returns: TweetV2PostTweetResult
Example
const { data: createdTweet } = await client.v2.tweet('twitter-api-v2 is awesome!', {
poll: { duration_minutes: 120, options: ['Absolutely', 'For sure!'] },
});
console.log('Tweet', createdTweet.id, ':', createdTweet.text);
Alias to a .tweet
with in_reply_to_tweet_id
already set.
Method: .reply()
Endpoint: tweets
Right level: Read-write
Arguments:
status: string
in_reply_to_status_id: string
payload?: SendTweetV2Params
Returns: TweetV2PostTweetResult
Example
await client.v2.reply(
'reply to previously created tweet.',
createdTweet.id,
);
Post multiple tweets at one time.
Method: .tweetThread()
Endpoint: tweets
Right level: Read-write
Arguments:
tweets: (SendTweetV2Params | string)[]
Returns: TweetV2PostTweetResult[]
: Created tweets results (in the right order), first sent first position
Example
// You can use media IDs generated by v1 API to send medias!
const mediaId = await client.v1.uploadMedia('./image.png');
await client.v2.tweetThread([
'Hello, lets talk about Twitter!',
{ text: 'Twitter is a fantastic social network. Look at this:', media: { media_ids: [mediaId] } },
'This thread is automatically made with twitter-api-v2 :D',
]);
Delete a tweet that belongs to you.
Method: .deleteTweet()
Endpoint: tweets/:id
Right level: Read-write
Arguments:
tweetId: string
Returns: TweetV2DeleteTweetResult
Example
await client.v2.deleteTweet('20');
Method: .singleTweet()
Endpoint: tweets/:id
Right level: Read-only
Arguments:
tweetId: string
options?: Tweetv2FieldsParams
Returns: TweetV2SingleResult
Example
const tweetOfId20 = await client.v2.singleTweet('20', {
expansions: [
'entities.mentions.username',
'in_reply_to_user_id',
],
});
Get multiple tweets by ID.
Method: .tweets()
Endpoint: tweets
Right level: Read-only
Arguments:
tweetIds: string | string[]
options?: Tweetv2FieldsParams
Returns: TweetV2LookupResult
Example
const tweets = await client.v2.tweets(['20', '141']);
Method: .tweetLikedBy()
Endpoint: tweets/:id/liking_users
Right level: Read-only
Arguments:
tweetId: string
options?: TweetRetweetedOrLikedByV2Params
Returns: TweetV2LikedByResult
or TweetLikingUsersV2Paginator
(if options.asPaginator
)
Example
const users = await client.v2.tweetLikedBy('20');
console.log(users.data[0].id);
const usersPaginated = await client.v2.tweetLikedBy('20', { asPaginator: true });
for await (const user of usersPaginated) {
console.log(user.id);
}
Like a single tweet.
Method: .like()
Endpoint: users/:loggedUserId/likes (POST)
Right level: Read-write
Arguments:
loggedUserId: string
: Logged user (you) IDtweetId: string
: Tweet to like
Returns: TweetV2LikeResult
Example
await client.v2.like('12', '20');
Remove a like of a single tweet.
Method: .unlike()
Endpoint: users/:loggedUserId/likes/:tweetId (DELETE)
Right level: Read-write
Arguments:
loggedUserId: string
: Logged user (you) IDtweetId: string
: Tweet to unlike
Returns: TweetV2LikeResult
Example
await client.v2.unlike('12', '20');
Method: .tweetCountRecent()
Endpoint: tweets/counts/recent
Right level: Read-only
Arguments:
query: string
options?: TweetV2CountParams
Returns: TweetV2CountResult
Example
const recentTweetsWithNode = await client.v2.tweetCountRecent('NodeJs');
console.log(recentTweetsWithNode.data[0].tweet_count);
Method: .tweetCountAll()
Endpoint: tweets/counts/all
Right level: Read-only
Arguments:
query: string
options?: TweetV2CountAllParams
Returns: TweetV2CountAllResult
Example
const allTweetsWithNode = await client.v2.tweetCountAll('NodeJs');
console.log(allTweetsWithNode.data[0].tweet_count);
Method: .tweetRetweetedBy()
Endpoint: tweets/:id/retweeted_by
Right level: Read-only
Arguments:
tweetId: string
options?: TweetRetweetedOrLikedByV2Params
Returns: TweetV2RetweetedByResult
or TweetRetweetersUsersV2Paginator
(if options.asPaginator
)
Example
const users = await client.v2.tweetRetweetedBy('20');
console.log(users.data[0].id);
const usersPaginated = await client.v2.tweetRetweetedBy('20', { asPaginator: true });
for await (const user of usersPaginated) {
console.log(user.id);
}
Retweet a single tweet.
Method: .retweet()
Endpoint: users/:loggedUserId/retweets (POST)
Right level: Read-write
Arguments:
loggedUserId: string
: Logged user (you) IDtweetId: string
: Tweet to retweet
Returns: TweetV2RetweetResult
Example
await client.v2.retweet('12', '20');
Remove a retweet of a single tweet.
Method: .unretweet()
Endpoint: users/:loggedUserId/retweets/:tweetId (DELETE)
Right level: Read-write
Arguments:
loggedUserId: string
: Logged user (you) IDtweetId: string
: Tweet to unretweet
Returns: TweetV2RetweetResult
Example
await client.v2.unretweet('12', '20');
List quoted replies of a tweets using a tweet paginator.
Method: .quotes()
Endpoint: tweets/:id/quote_tweets (GET)
Right level: Read-only
Arguments:
tweetId: string
: Tweet IDoptions: TweetV2PaginableTimelineParams
: Tweet meta options
Returns: QuotedTweetsTimelineV2Paginator
: A tweet paginator
Example
const quotes = await client.v2.quotes({ expansions: ['author_id'], 'user.fields': ['username', 'url'] })
for await (const quote of quotes) {
const quotedTweetAuthor = bookmarks.includes.author(quote)
if (quotedTweetAuthor) {
console.log('Quote answer tweet', quote.id, 'has been made by', quotedTweetAuthor.username)
}
}
Add tweet as bookmark.
Method: .bookmark()
Endpoint: users/:id/bookmarks (POST)
Right level: Read-write
Arguments:
tweetId: string
: Tweet to bookmark
Returns: TweetV2BookmarkResult
Example
await client.v2.bookmark('20')
Remove a bookmark by tweet ID.
Method: .deleteBookmark()
Endpoint: users/:id/bookmarks/:tweet_id (DELETE)
Right level: Read-write
Arguments:
tweetId: string
: Tweet to unbookmark
Returns: TweetV2BookmarkResult
Example
await client.v2.deleteBookmark('20')
List bookmarked tweets using a tweet paginator.
Method: .bookmarks()
Endpoint: users/:id/bookmarks (GET)
Right level: Read-only
Arguments:
options: TweetV2PaginableTimelineParams
: Tweet meta options
Returns: TweetBookmarksTimelineV2Paginator
: A tweet paginator
Example
const bookmarks = await client.v2.bookmarks({ expansions: ['referenced_tweets.id'] })
for await (const bookmark of bookmarks) {
const quotedTweet = bookmarks.includes.quote(bookmark)
if (quotedTweet) {
console.log('Bookmarked tweet', bookmark.id, 'is a quote of', quotedTweet.id)
}
}
Get the logged user.
Method: .me()
Endpoint: users/me
Right level: Read-only
Arguments:
options?: UsersV2Params
Returns: UserV2Result
Example
const meUser = await client.v2.me({ expansions: ['pinned_tweet_id'] });
Get a single user by ID.
Method: .user()
Endpoint: users/:id
Right level: Read-only
Arguments:
userId: string
options?: UsersV2Params
Returns: UserV2Result
Example
const jack = await client.v2.user('12', { 'tweet.fields': ['id', 'text'] });
Get a single user by username.
Method: .userByUsername()
Endpoint: users/by/username/:username
Right level: Read-only
Arguments:
username: string
options?: UsersV2Params
Returns: UserV2Result
Example
const jack = await client.v2.userByUsername('jack');
Get users using a bunch of IDs.
Method: .users()
Endpoint: users
Right level: Read-only
Arguments:
userIds: string | string[]
options?: UsersV2Params
Returns: UsersV2Result
Example
const users = await client.v2.users(['12', '180248', '193208']);
Get users using a bunch of usernames.
Method: .usersByUsernames()
Endpoint: users/by
Right level: Read-only
Arguments:
usernames: string | string[]
options?: UsersV2Params
Returns: UsersV2Result
Example
const users = await client.v2.usersByUsernames(['jack', 'plhery', 'alkihis']);
Return the last likes of a specific user. Get to know how paginators work here.
Method: .userLikedTweets()
Endpoint: users/:id/liked_tweets
Right level: Read-only
Arguments:
userId: string
options?: TweetV2PaginableListParams
Returns: TweetV2UserLikedTweetsPaginator
Example
const likedTweets = await client.v2.userLikedTweets('12');
console.log(likedTweets.tweets[0].id);
await likedTweets.fetchNext();
Get followers of a specific user ID.
Method: .followers()
Endpoint: users/:id/followers
Right level: Read-only
Arguments:
userId: string
options?: FollowersV2Params
Returns:
- If
asPaginator
is absent orfalse
inoptions
:UserV2TimelineResult
- If
asPaginator
istrue
inoptions
:UserFollowersV2Paginator
Example
const followersOfJack = await client.v2.followers('12');
const followersOfJackAsPaginator = await client.v2.followers('12', { asPaginator: true });
console.log(followersOfJackAsPaginator instanceof UserFollowersV2Paginator) // true
Get followings (people who follows) of a specific user ID.
Method: .following()
Endpoint: users/:id/following
Right level: Read-only
Arguments:
userId: string
options?: FollowersV2Params
Returns:
- If
asPaginator
is absent orfalse
inoptions
:UserV2TimelineResult
- If
asPaginator
istrue
inoptions
:UserFollowingV2Paginator
Example
const followingsOfJack = await client.v2.following('12');
const followingsOfJackAsPaginator = await client.v2.following('12', { asPaginator: true });
console.log(followingsOfJackAsPaginator instanceof UserFollowingV2Paginator) // true
Method: .follow()
Endpoint: users/:loggedUserId/following (POST)
Right level: Read-write
Arguments:
loggedUserId: string
: Logged user (you) IDuserId: string
: User to follow
Returns: UserV2FollowResult
Example
await client.v2.follow('12', '1903892');
Method: .unfollow()
Endpoint: users/:loggedUserId/following/:userId (DELETE)
Right level: Read-write
Arguments:
loggedUserId: string
: Logged user (you) IDuserId: string
: User to unfollow
Returns: UserV2UnfollowResult
Example
await client.v2.unfollow('12', '1903892');
Method: .block()
Endpoint: users/:loggedUserId/blocking (POST)
Right level: Read-write
Arguments:
loggedUserId: string
: Logged user (you) IDuserId: string
: User to block
Returns: UserV2BlockResult
Example
await client.v2.block('12', '1903892');
Method: .unblock()
Endpoint: users/:loggedUserId/blocking/:userId (DELETE)
Right level: Read-write
Arguments:
loggedUserId: string
: Logged user (you) IDuserId: string
: User to unblock
Returns: UserV2BlockResult
Example
await client.v2.unblock('12', '1903892');
Get users blocked by the authenticating user. Get to know how paginators work here.
Method: .userBlockingUsers()
Endpoint: users/:id/blocking
Right level: Read-only
Arguments:
loggedUserId: string
: Logged user (you) IDoptions?: UserV2TimelineParams
Returns: UserBlockingUsersV2Paginator
Example
const blockedPaginator = await client.v2.userBlockingUsers('14');
for await (const blockedUser of blockedPaginator) {
console.log(`You are blocking @${blockedUser.username}.`);
}
Method: .mute()
Endpoint: users/:loggedUserId/muting (POST)
Right level: Read-write
Arguments:
loggedUserId: string
: Logged user (you) IDuserId: string
: User to mute
Returns: UserV2MuteResult
Example
await client.v2.mute('12', '1903892');
Method: .unmute()
Endpoint: users/:loggedUserId/muting/:userId (DELETE)
Right level: Read-write
Arguments:
loggedUserId: string
: Logged user (you) IDuserId: string
: User to unmute
Returns: UserV2MuteResult
Example
await client.v2.unmute('12', '1903892');
Get users muted by authenticated user. Get to know how paginators work here.
Method: .userMutingUsers()
Endpoint: users/:id/muting
Right level: Read-only
Arguments:
loggedUserId: string
: Logged user (you) IDoptions?: UserV2TimelineParams
Returns: UserMutingUsersV2Paginator
Example
const mutedPaginator = await client.v2.userMutingUsers('14');
for await (const mutedUser of mutedPaginator) {
console.log(`You are muting @${mutedUser.username}.`);
}
Method: .list()
Endpoint: lists/:id
Right level: Read-only
Arguments:
id: string
options: GetListV2Params
Returns: ListGetV2Result
Example
const aList = await client.v2.list('102', { expansions: ['owner_id'] });
Method: .listsOwned()
Endpoint: users/:id/owned_lists
Right level: Read-only
Arguments:
userId: string
options: GetListTimelineV2Params
Returns: UserOwnedListsV2Paginator
(that contains ListV2
objects)
Example
// Get lists owned by me
const ownedLists = await client.v2.listsOwned((await client.v2.me()).data.id);
for await (const list of ownedLists) {
console.log(list.id);
}
Method: .listMemberships()
Endpoint: users/:id/list_memberships
Right level: Read-only
Arguments:
userId: string
options: GetListTimelineV2Params
Returns: UserListMembershipsV2Paginator
(that contains ListV2
objects)
Example
// Get lists owned by me inside
const listsWithMe = await client.v2.listMemberships((await client.v2.me()).data.id);
for await (const list of listsWithMe) {
console.log(list.id);
}
Method: .listFollowed()
Endpoint: users/:id/followed_lists
Right level: Read-only
Arguments:
userId: string
options: GetListTimelineV2Params
Returns: UserListFollowedV2Paginator
(that contains ListV2
objects)
Example
// Get lists that I follow
const followedLists = await client.v2.listFollowed((await client.v2.me()).data.id);
for await (const list of followedLists) {
console.log(list.id);
}
Method: .listTweets()
Endpoint: lists/:id/tweets
Right level: Read-only
Arguments:
listId: string
options: TweetV2PaginableListParams
Returns: TweetV2ListTweetsPaginator
(that contains TweetV2
objects)
Example
const tweets = await client.v2.listTweets('102', { 'media.fields': ['media_key'], expansions: ['attachments.media_keys'] });
for await (const tweet of tweets) {
console.log(tweet.id);
}
Method: .listMembers()
Endpoint: lists/:id/members
Right level: Read-only
Arguments:
listId: string
options: UserV2TimelineParams
Returns: UserListMembersV2Paginator
(that contains UserV2
objects)
Example
const membersOfList = await client.v2.listMembers('102');
for await (const user of membersOfList) {
console.log(user.id);
}
Method: .listFollowers()
Endpoint: lists/:id/followers
Right level: Read-only
Arguments:
listId: string
options: UserV2TimelineParams
Returns: UserListFollowersV2Paginator
(that contains UserV2
objects)
Example
const followersOfList = await client.v2.listFollowers('102');
for await (const user of followersOfList) {
console.log(user.id);
}
Method: .createList()
Endpoint: lists
Right level: Read-write
Arguments:
options: ListCreateV2Params
Returns: ListCreateV2Result
Example
const myNewList = await client.v2.createList({ name: 'cats', private: true });
Method: .updateList()
Endpoint: lists/:id
Right level: Read-write
Arguments:
listId: string
options: ListUpdateV2Params
Returns: ListUpdateV2Result
Example
const updatedList = await client.v2.updateList('128492', { private: true });
Method: .removeList()
Endpoint: lists/:id
Right level: Read-write
Arguments:
listId: string
Returns: ListDeleteV2Result
Example
await client.v2.removeList('128492');
Method: .addListMember()
Endpoint: lists/:id/members
Right level: Read-write
Arguments:
listId: string
userId: string
Returns: ListMemberV2Result
Example
await client.v2.addListMember('12', '128492');
Method: .removeListMember()
Endpoint: lists/:id/members/:user_id
Right level: Read-write
Arguments:
listId: string
userId: string
Returns: ListMemberV2Result
Example
await client.v2.removeListMember('128492', '12');
Method: .subscribeToList()
Endpoint: users/:id/followed_lists
Right level: Read-write
Arguments:
loggedUserId: string
listId: string
Returns: ListFollowV2Result
Example
await client.v2.subscribeToList('12', '128492');
Method: .unsubscribeOfList()
Endpoint: users/:id/followed_lists/:list_id
Right level: Read-write
Arguments:
loggedUserId: string
listId: string
Returns: ListFollowV2Result
Example
await client.v2.unsubscribeOfList('12', '128492');
Method: .pinList()
Endpoint: users/:id/pinned_lists
Right level: Read-write
Arguments:
loggedUserId: string
listId: string
Returns: ListPinV2Result
Example
await client.v2.pinList('12', '128492');
Method: .unpinList()
Endpoint: users/:id/pinned_lists/:list_id
Right level: Read-write
Arguments:
loggedUserId: string
listId: string
Returns: ListPinV2Result
Example
await client.v2.unpinList('12', '128492');
Get a single space by its ID.
Method: .space()
Endpoint: spaces/:id
Right level: Read-only
Arguments:
spaceId: string
options?: SpaceV2FieldsParams
Returns: SpaceV2SingleResult
Example
const { data: space } = await client.v2.space('space-id')
// space is a SpaceV2
console.log(space.state) // 'live'
Get spaces by its ID.
Method: .spaces()
Endpoint: spaces
Right level: Read-only
Arguments:
spaceIds: string | string[]
options?: SpaceV2FieldsParams
Returns: SpaceV2LookupResult
Example
const { data: spaces } = await client.v2.spaces('space-id,space-2-id')
console.log(spaces) // SpaceV2[]
Get spaces users who created them. (No pagination available)
Method: .spacesByCreators()
Endpoint: spaces/by/creator_ids
Right level: Read-only
Arguments:
creatorUserIds: string | string[]
options?: SpaceV2FieldsParams
Returns: SpaceV2LookupResult
Example
const { data: spaces } = await client.v2.spacesByCreators(['12', '1024'])
console.log(spaces) // SpaceV2[] - Spaces of users '12' and '1024'
Search spaces using a query (will be looked up in their title) and their state. (No pagination available)
Method: .searchSpaces()
Endpoint: spaces/search
Right level: Read-only
Arguments:
options: SpaceV2SearchParams
Returns: SpaceV2LookupResult
Example
const { data: spaces } = await client.v2.searchSpaces({ query: 'Node JS', state: 'live' })
console.log(spaces) // SpaceV2[] - Found live spaces talking about NodeJS!
Get buyers of your space by its ID.
Method: .spaceBuyers()
Endpoint: spaces/:id/buyers
Right level: Read-only
Arguments:
spaceId: string
options?: SpaceV2BuyersParams
Returns: SpaceV2BuyersResult
Example
const { data: users } = await client.v2.spaceBuyers('space-id')
// users is a UserV2[]
Get tweets of your space by its ID.
Method: .spaceTweets()
Endpoint: spaces/:id/tweets
Right level: Read-only
Arguments:
spaceId: string
options?: Tweetv2FieldsParams
Returns: TweetV2LookupResult
Example
const { data: tweets } = await client.v2.spaceTweets('space-id')
// tweets is a TweetV2[]
Returns a list of Direct Messages for the authenticated user, both sent and received.
Method: .listDmEvents()
Endpoint: dm_events
Right level: Read-only
Arguments:
options?: GetDMEventV2Params
Returns: FullDMTimelineV2Paginator
(containing DMEventV2
)
Example
const eventTimeline = await client.v2.listDmEvents()
console.log(eventTimeline.events)
Returns a list of Direct Messages (DM) events within a 1-1 conversation with the user specified.
Method: .listDmEventsWithParticipant()
Endpoint: dm_conversations/with/:participant_id/dm_events
Right level: Read-only
Arguments:
participantId: string
options?: GetDMEventV2Params
Returns: OneToOneDMTimelineV2Paginator
(containing DMEventV2
)
Example
const eventTimeline = await client.v2.listDmEventsWithParticipant('12')
console.log(eventTimeline.events)
Returns a list of Direct Messages (DM) events within a 1-1 conversation with the user specified.
Method: .listDmEventsOfConversation()
Endpoint: dm_conversations/:dm_conversation_id/dm_events
Right level: Read-only
Arguments:
dmConversationId: string
options?: GetDMEventV2Params
Returns: ConversationDMTimelineV2Paginator
(containing DMEventV2
)
Example
const eventTimeline = await client.v2.listDmEventsOfConversation('12')
console.log(eventTimeline.events)
Creates a new group conversation and adds a Direct Message to it on behalf of an authenticated user.
Method: .createDmConversation()
Endpoint: dm_conversations
Right level: Read-write
Arguments:
options: CreateDMConversationParams
Returns: PostDMInConversationResult
Example
const { dm_conversation_id, dm_event_id } = await client.v2.createDmConversation({
conversation_type: 'Group',
participant_ids: ['12', '24'],
message: {
text: 'Hello!',
attachments: [{ media_id: '123' }],
},
})
Creates a one-to-one Direct Message and adds it to the one-to-one conversation. If the conversation does not exists, it creates it.
Method: .sendDmToParticipant()
Endpoint: dm_conversations/with/:participant_id/messages
Right level: Read-write
Arguments:
participantId: string
options: PostDMInConversationParams
Returns: PostDMInConversationResult
Example
const { dm_conversation_id, dm_event_id } = await client.v2.sendDmToParticipant('12', {
text: 'Hello!',
attachments: [{ media_id: '123' }],
})
Creates a Direct Message on behalf of an authenticated user, and adds it to the specified conversation.
Method: .sendDmInConversation()
Endpoint: dm_conversations/:dm_conversation_id/messages
Right level: Read-write
Arguments:
conversationId: string
options: PostDMInConversationParams
Returns: PostDMInConversationResult
Example
const { dm_event_id } = await client.v2.sendDmInConversation('19732-4843', {
text: 'Hello!',
})
Get a already created compliance job.
Method: .complianceJob()
Endpoint: compliance/jobs/:id (GET)
Right level: Read-only
Arguments:
jobId: string
: Job ID
Returns: BatchComplianceV2Result
Example
const job = await client.v2.complianceJob('289859');
console.log(job.data.status); // 'in_progress'
Get a list of compliance jobs by type and status.
Method: .complianceJobs()
Endpoint: compliance/jobs (GET)
Right level: Read-only
Arguments:
options: BatchComplianceSearchV2Params
: Options
Returns: BatchComplianceListV2Result
Example
const jobs = await client.v2.complianceJobs({ type: 'tweets' });
console.log(jobs.data[0].status); // 'in_progress'
Create new compliance job given a user/tweet ID list.
Method: .sendComplianceJob()
Endpoint: compliance/jobs (POST)
Right level: Read-only
Arguments:
options: BatchComplianceV2Params
: Job options
Returns: BatchComplianceV2Result
Example
// Create the job
const createdJob = await client.v2.sendComplianceJob({
type: 'tweets',
ids: ['20', '1430917443426336770', '1430914940559372289', '1298636084130336773'],
});
// Await the job result
const jobResult = await client.v2.complianceJobResult(createdJob.data);
Await job resolution (can be very long), download the result and parse it.
Method: .complianceJobResult()
Right level: Read-only
Arguments:
job: BatchComplianceJobV2
: Job (extracted fromBatchComplianceV2Result
/BatchComplianceListV2Result
)
Returns: BatchComplianceV2JobResult
Example
// Create the job
const createdJob = await client.v2.sendComplianceJob({
type: 'tweets',
ids: ['20', '1430917443426336770', '1430914940559372289', '1298636084130336773'],
});
// Await the job result
const jobResult = await client.v2.complianceJobResult(createdJob.data);
for (const tweetCompliance of jobResult) {
// Job result is parsed into an array
console.log(`#${tweetCompliance.id}: action ${tweetCompliance.action} because ${tweetCompliance.reason}`);
}