### Install with npm Source: https://docs.x.com/xdks/typescript/install Install the XDK TypeScript SDK using npm. ```bash npm install @xdevplatform/xdk ``` -------------------------------- ### Install with pnpm Source: https://docs.x.com/xdks/typescript/install Install the XDK TypeScript SDK using pnpm. ```bash pnpm add @xdevplatform/xdk ``` -------------------------------- ### Install with yarn Source: https://docs.x.com/xdks/typescript/install Install the XDK TypeScript SDK using yarn. ```bash yarn add @xdevplatform/xdk ``` -------------------------------- ### Basic Pagination Setup (JavaScript) Source: https://docs.x.com/xdks/typescript/pagination Initialize a paginator using JavaScript. The async function should return data in a paginated format. ```javascript import { Client } from '@xdevplatform/xdk'; import { UserPaginator } from '@xdevplatform/xdk'; const client = new Client({ bearerToken: 'your-bearer-token' }); const followers = new UserPaginator(async (token) => { const res = await client.users.getFollowers('', { maxResults: 100, paginationToken: token, userFields: ['id','name','username'], }); return { data: res.data ?? [], meta: res.meta, includes: res.includes, errors: res.errors }; }); ``` -------------------------------- ### Quick Start with TypeScript XDK Source: https://docs.x.com/xdks/typescript/overview Demonstrates how to initialize the XDK client with a bearer token and fetch user information by username. Requires importing Client, ClientConfig, and Users from '@xdevplatform/xdk'. ```typescript import { Client, type ClientConfig, type Users } from '@xdevplatform/xdk'; const config: ClientConfig = { bearerToken: 'your-bearer-token' }; const client: Client = new Client(config); async function main(): Promise { const userResponse: Users.GetByUsernameResponse = await client.users.getByUsername('XDevelopers'); const username: string = userResponse.data?.username!; console.log(username); } main(); ``` -------------------------------- ### Quick Start with JavaScript XDK Source: https://docs.x.com/xdks/typescript/overview Shows how to use the XDK client in JavaScript to retrieve user data. Initializes the client with a bearer token and calls the getByUsername method. ```javascript import { Client } from '@xdevplatform/xdk'; const client = new Client({ bearerToken: 'your-bearer-token' }); const userResponse = await client.users.getByUsername('XDevelopers'); const username = userResponse.data.username; console.log(username); ``` -------------------------------- ### get Source: https://docs.x.com/xdks/typescript/reference/classes/WebhooksClient Retrieves webhook configurations. Can return raw API response or structured data. ```APIDOC ## get ### Description Get a list of webhook configs associated with a client app. ### Method (Not specified, likely GET) ### Endpoint (Not specified, but related to webhooks) ### Parameters #### Query Parameters - `options` (GetOptions & { requestOptions: { raw: true } }) - Required - Options for the request, including a flag to return the raw response. ### Response #### Success Response (200) - `Response` - The raw API response if `requestOptions.raw` is true. ``` ```APIDOC ## get ### Description Get a list of webhook configs associated with a client app. ### Method (Not specified, likely GET) ### Endpoint (Not specified, but related to webhooks) ### Parameters #### Query Parameters - `options?` (GetOptions) - Optional - Options for the request. ### Response #### Success Response (200) - `Get2WebhooksResponse` - An object containing the webhook configurations. ``` -------------------------------- ### Basic Pagination Setup (TypeScript) Source: https://docs.x.com/xdks/typescript/pagination Initialize a paginator by wrapping an async function that fetches paginated data. Ensure proper typing for the response data. ```typescript import { Client, UserPaginator, PaginatedResponse, Schemas } from '@xdevplatform/xdk'; const client: Client = new Client({ bearerToken: 'your-bearer-token' }); // Wrap any list endpoint with proper typing const followers: UserPaginator = new UserPaginator( async (token?: string): Promise> => { const res = await client.users.getFollowers('', { maxResults: 100, paginationToken: token, userFields: ['id','name','username'], }); return { data: res.data ?? [], meta: res.meta, includes: res.includes, errors: res.errors }; } ); ``` -------------------------------- ### get Source: https://docs.x.com/xdks/typescript/reference/classes/HttpClient Makes a GET request to the specified URL, optionally with custom headers. ```APIDOC ## get(url, headers?) ### Description Make a GET request. ### Parameters - **url** (string) - The URL to make the GET request to. - **headers?** (Record) - Optional. Custom headers to include in the request. ### Returns - `Promise`: A promise that resolves with the HTTP response. ### Defined in http-client.ts:141 ``` -------------------------------- ### OAuth 1.0a Authentication (JavaScript) Source: https://docs.x.com/xdks/typescript/authentication This JavaScript example demonstrates OAuth 1.0a authentication for legacy applications. Ensure all placeholder credentials are replaced with valid values. ```javascript import { Client, OAuth1 } from '@xdevplatform/xdk'; const oauth1 = new OAuth1({ apiKey: 'your-api-key', apiSecret: 'your-api-secret', accessToken: 'user-access-token', accessTokenSecret: 'user-access-token-secret' }); const client = new Client({ oauth1: oauth1 }); const response = await client.users.getMe(); const me = response.data; console.log(me); ``` -------------------------------- ### Get Bookmark Folders Source: https://docs.x.com/xdks/typescript/reference/modules/Users Retrieves the bookmark folders for the user. This endpoint returns a list of folders where bookmarks are organized. ```APIDOC ## GET /users/{id}/bookmark_folders ### Description Retrieves the bookmark folders for the user. ### Endpoint /users/{id}/bookmark_folders ### Response #### Success Response (200) - **data** (array) - A list of bookmark folders. #### Response Example ```json { "data": [ { "id": "folder_id_1", "name": "Folder 1" }, { "id": "folder_id_2", "name": "Folder 2" } ] } ``` ``` -------------------------------- ### getByKey Source: https://docs.x.com/xdks/typescript/reference/classes/MediaClient Get Media by media key. Retrieves details of a specific Media file by its media key. ```APIDOC ## getByKey(mediaKey, options) ### Description Get Media by media key. Retrieves details of a specific Media file by its media key. ### Parameters #### Path Parameters - **mediaKey** (string) - Required - A single Media Key. - **options** (GetByKeyOptions & { requestOptions: { raw: true } }) - Required - ### Returns - Promise - Promise resolving to the API response, or raw Response if requestOptions.raw is true ``` ```APIDOC ## getByKey(mediaKey, options?) ### Description Get Media by media key. Retrieves details of a specific Media file by its media key. ### Parameters #### Path Parameters - **mediaKey** (string) - Required - **options** (GetByKeyOptions) - Optional ### Returns - Promise ``` -------------------------------- ### next Source: https://docs.x.com/xdks/typescript/reference/classes/PostPaginator Creates a new paginator instance that starts from the next page, without affecting the current paginator's state. Returns a Promise that resolves to a new Paginator instance for the next page. ```APIDOC ## next ### Description Get next page as a new instance. This method creates a new paginator instance that starts from the next page, without affecting the current paginator's state. ### Method `next()` ### Returns `Promise>` - New paginator instance for the next page. ### Example ```typescript const followers = await client.users.getFollowers('783214'); await followers.fetchNext(); // Fetch first page if (!followers.done) { const nextPage = await followers.next(); // Get next page as new instance console.log(followers.items.length); // Still first page console.log(nextPage.items.length); // Second page } ``` ``` -------------------------------- ### getStreamLinks Source: https://docs.x.com/xdks/typescript/reference/classes/WebhooksClient Get stream links. Get a list of webhook links associated with a filtered stream ruleset. ```APIDOC ## getStreamLinks(options: Object): Promise ### Description Get stream links. Get a list of webhook links associated with a filtered stream ruleset. ### Parameters #### Path Parameters - **options** (Object) - Required - #### Returns Promise #### Defined in webhooks/client.ts:254 ``` -------------------------------- ### GetResponse Source: https://docs.x.com/xdks/typescript/reference/modules/Webhooks Response type for the get operation. ```APIDOC ## Type Alias: GetResponse Ƭ **GetResponse**: [`Get2WebhooksResponse`](/xdks/typescript/reference/interfaces/Schemas.Get2WebhooksResponse) Response for get. #### Defined in [webhooks/models.ts:60](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/webhooks/models.ts#L60) ``` -------------------------------- ### Initialize and Use X API Client Source: https://docs.x.com/xdks/typescript/reference/classes/Client Demonstrates initializing the Client with a bearer token and making calls to retrieve user information and followers. Includes pagination and iteration over results. ```typescript import { Client } from '@xdevplatform/xdk'; const client = new Client({ bearerToken: 'your-bearer-token' }); // Get user information const user = await client.users.getUser('783214'); // Get followers with pagination const followers = await client.users.getFollowers('783214', { maxResults: 10, userFields: ['id', 'name', 'username'] }); // Iterate through followers for await (const follower of followers) { console.log(follower.username); } ``` -------------------------------- ### Get Personalized Trends Source: https://docs.x.com/xdks/typescript/reference/modules/Trends Fetches personalized trends for the authenticated user. ```APIDOC ## Get Personalized Trends ### Description Fetches personalized trends for the authenticated user. ### Method GET ### Endpoint /2/users/personalized_trends ### Parameters #### Query Parameters None ### Response #### Success Response (200) - **GetPersonalizedResponse** (object) - The response object containing personalized trends data. ### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### Schemas.EntityIndicesInclusiveInclusive Source: https://docs.x.com/xdks/typescript/reference/modules Represents entity indices with inclusive start and inclusive end. ```APIDOC ## Schemas.EntityIndicesInclusiveInclusive ### Description Defines the structure for entity indices, specifying both an inclusive start and an inclusive end. ### Method Not Applicable (Schema Definition) ### Endpoint Not Applicable (Schema Definition) ### Parameters Not Applicable (Schema Definition) ### Request Example ```json { "example": "request body for EntityIndicesInclusiveInclusive" } ``` ### Response Not Applicable (Schema Definition) #### Response Example ```json { "example": "response body for EntityIndicesInclusiveInclusive" } ``` ``` -------------------------------- ### MediaClient constructor Source: https://docs.x.com/xdks/typescript/reference/classes/MediaClient Creates a new media client instance. ```APIDOC ## new MediaClient(client) ### Description Creates a new media client instance. ### Parameters #### Path Parameters - **client** (Client) - Required - The main X API client instance ### Returns - MediaClient - A new MediaClient instance. ``` -------------------------------- ### Schemas.EntityIndicesInclusiveExclusive Source: https://docs.x.com/xdks/typescript/reference/modules Represents entity indices with inclusive start and exclusive end. ```APIDOC ## Schemas.EntityIndicesInclusiveExclusive ### Description Defines the structure for entity indices, specifying an inclusive start and an exclusive end. ### Method Not Applicable (Schema Definition) ### Endpoint Not Applicable (Schema Definition) ### Parameters Not Applicable (Schema Definition) ### Request Example ```json { "example": "request body for EntityIndicesInclusiveExclusive" } ``` ### Response Not Applicable (Schema Definition) #### Response Example ```json { "example": "response body for EntityIndicesInclusiveExclusive" } ``` ``` -------------------------------- ### Get Trends by WOEID Source: https://docs.x.com/xdks/typescript/reference/modules/Trends Fetches trends for a specific location identified by its WOEID. ```APIDOC ## Get Trends by WOEID ### Description Fetches trends for a specific location identified by its WOEID. ### Method GET ### Endpoint /2/trends/by/woeid/:woeid ### Parameters #### Path Parameters - **woeid** (string) - Required - The Where On Earth ID (WOEID) of the location. ### Response #### Success Response (200) - **GetByWoeidResponse** (object) - The response object containing trends data. ### Response Example ```json { "example": "response body" } ``` ``` -------------------------------- ### Client Constructor Source: https://docs.x.com/xdks/typescript/reference/classes/Client Creates a new X API client instance. Supports Bearer token, OAuth2, and OAuth1 authentication. ```APIDOC ## new Client(config) ### Description Creates a new X API client instance. ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Constructor `new Client(config: any)` ### Parameters * **config** (any) - Required - Configuration options for the client ### Returns * **Client** - A new instance of the Client class. ### Request Example ```typescript // Bearer token authentication const client = new Client({ bearerToken: 'your-bearer-token' }); // OAuth2 authentication const client = new Client({ accessToken: 'your-access-token' }); // OAuth1 authentication const client = new Client({ oauth1: oauth1Instance }); ``` ``` -------------------------------- ### ActivityClient Constructor Source: https://docs.x.com/xdks/typescript/reference/classes/ActivityClient Creates a new activity client instance. Requires the main X API client instance. ```APIDOC ## constructor ### Description Creates a new activity client instance. ### Parameters #### Path Parameters - **client** (Client) - Required - The main X API client instance ### Returns - ActivityClient ### Defined in [activity/client.ts:118](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/activity/client.ts#L118) ``` -------------------------------- ### GetResponse Source: https://docs.x.com/xdks/typescript/reference/modules/News Type alias for the response of a get operation. It maps to the Get2NewsIdResponse interface. ```APIDOC ## Type Alias: GetResponse Ƭ **GetResponse**: [`Get2NewsIdResponse`](/xdks/typescript/reference/interfaces/Schemas.Get2NewsIdResponse) Response for get #### Defined in [news/models.ts:18](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/news/models.ts#L18) ``` -------------------------------- ### NewsClient constructor Source: https://docs.x.com/xdks/typescript/reference/classes/NewsClient Creates a new news client instance. Requires the main X API client instance. ```APIDOC ## constructor NewsClient ### Description Creates a new news client instance. ### Parameters #### Path Parameters - None #### Query Parameters - None #### Request Body - None ### Method constructor ### Endpoint N/A ### Request Example ```typescript const newsClient = new NewsClient(client); ``` ### Response #### Success Response - Returns a new instance of NewsClient. ### Response Example ```typescript // NewsClient instance ``` ``` -------------------------------- ### getByIds Source: https://docs.x.com/xdks/typescript/reference/classes/SpacesClient Get Spaces by IDs. Retrieves details of multiple Spaces by their IDs. ```APIDOC ## getByIds(ids: any[], options?: GetByIdsOptions) ### Description Get Spaces by IDs. Retrieves details of multiple Spaces by their IDs. ### Parameters #### Path Parameters - **ids** (any[]) - Required - The list of Space IDs to return. - **options** (GetByIdsOptions) - Optional #### Returns - Promise #### Defined in src/spaces/client.ts:374 ``` -------------------------------- ### initializeUpload Source: https://docs.x.com/xdks/typescript/reference/classes/MediaClient Initializes a media upload. ```APIDOC ## initializeUpload ### Description Initialize media upload. Initializes a media upload. ### Method POST (assumed based on operation) ### Endpoint /media/upload (assumed based on operation) ### Parameters #### Request Body - **options** (Object) - Required - ### Response #### Success Response (200) - **response** (Response) - API response or raw Response if requestOptions.raw is true ``` -------------------------------- ### getUploadStatus Source: https://docs.x.com/xdks/typescript/reference/classes/MediaClient Get Media upload status. Retrieves the status of a Media upload by its ID. ```APIDOC ## getUploadStatus(mediaId, options) ### Description Get Media upload status. Retrieves the status of a Media upload by its ID. ### Parameters #### Path Parameters - **mediaId** (string) - Required - Media id for the requested media upload status. - **options** (GetUploadStatusOptions & { requestOptions: { raw: true } }) - Required - ### Returns - Promise - Promise resolving to the API response, or raw Response if requestOptions.raw is true ``` ```APIDOC ## getUploadStatus(mediaId, options?) ### Description Get Media upload status. Retrieves the status of a Media upload by its ID. ### Parameters #### Path Parameters - **mediaId** (string) - Required - **options** (GetUploadStatusOptions) - Optional ### Returns - Promise ``` -------------------------------- ### SpacesClient Constructor Source: https://docs.x.com/xdks/typescript/reference/classes/SpacesClient Creates a new spaces client instance. Requires the main X API client instance. ```APIDOC ## new SpacesClient(client: Client) ### Description Creates a new spaces client instance. ### Parameters #### Path Parameters - **client** (Client) - Required - The main X API client instance #### Returns - SpacesClient #### Defined in src/spaces/client.ts:316 ``` -------------------------------- ### getPosts Source: https://docs.x.com/xdks/typescript/reference/classes/SpacesClient Get Space Posts. Retrieves a list of Posts shared in a specific Space by its ID. ```APIDOC ## getPosts(id: string, options?: GetPostsOptions) ### Description Get Space Posts. Retrieves a list of Posts shared in a specific Space by its ID. ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the Space to be retrieved. - **options** (GetPostsOptions) - Optional #### Returns - Promise #### Defined in src/spaces/client.ts:585 ``` -------------------------------- ### getMembers Source: https://docs.x.com/xdks/typescript/reference/classes/ListsClient Get List members. Retrieves a list of Users who are members of a specific List by its ID. ```APIDOC ## getMembers ### Description Get List members. Retrieves a list of Users who are members of a specific List by its ID. ### Method GET ### Endpoint /2/lists/:id/members ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the List. #### Query Parameters - **options** (GetMembersOptions) - Optional - Options for filtering and pagination. ### Returns Promise ### Defined in [lists/client.ts:445](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/lists/client.ts#L445) ``` -------------------------------- ### UsageClient Constructor Source: https://docs.x.com/xdks/typescript/reference/classes/UsageClient Creates a new instance of the UsageClient. It requires an authenticated Client instance to interact with the X API. ```APIDOC ## new UsageClient(client: Client) ### Description Creates a new usage client instance. ### Parameters #### Path Parameters - **client** (Client) - The main X API client instance. ### Returns UsageClient ``` -------------------------------- ### getFollowers Source: https://docs.x.com/xdks/typescript/reference/classes/ListsClient Get List followers. Retrieves a list of Users who follow a specific List by its ID. ```APIDOC ## getFollowers ### Description Get List followers. Retrieves a list of Users who follow a specific List by its ID. ### Method GET ### Endpoint /2/lists/:id/followers ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the List. #### Query Parameters - **options** (GetFollowersOptions) - Optional - Options for filtering and pagination. ### Returns Promise or Promise ### Defined in [lists/client.ts:339](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/lists/client.ts#L339) [lists/client.ts:352](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/lists/client.ts#L352) ``` -------------------------------- ### create Source: https://docs.x.com/xdks/typescript/reference/classes/ListsClient Create List. Creates a new List for the authenticated user. ```APIDOC ## create ### Description Create List. Creates a new List for the authenticated user. ### Method POST ### Endpoint /2/lists ### Parameters #### Request Body - **options** (CreateOptions) - Optional - Options for creating the list. ### Returns Promise or Promise ### Defined in [lists/client.ts:560](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/lists/client.ts#L560) [lists/client.ts:569](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/lists/client.ts#L569) ``` -------------------------------- ### Get Timeline Source: https://docs.x.com/xdks/typescript/reference/modules/Users Retrieves the timeline for a user in reverse chronological order. This endpoint provides a feed of posts. ```APIDOC ## GET /users/{id}/timelines/reverse_chronological ### Description Retrieves the timeline for a user in reverse chronological order. ### Endpoint /users/{id}/timelines/reverse_chronological ### Response #### Success Response (200) - **data** (array) - A list of posts in the user's timeline. #### Response Example ```json { "data": [ { "id": "post_id_1", "text": "This is a post." }, { "id": "post_id_2", "text": "Another post." } ] } ``` ``` -------------------------------- ### create Source: https://docs.x.com/xdks/typescript/reference/classes/WebhooksClient Creates a new webhook configuration. Can return raw API response or structured data. ```APIDOC ## create ### Description Creates a new webhook configuration. ### Method (Not specified, likely POST) ### Endpoint (Not specified, but related to webhooks) ### Parameters #### Query Parameters - `options` (CreateOptions & { requestOptions: { raw: true } }) - Required - Options for the creation, including a flag to return the raw response. ### Response #### Success Response (200) - `Response` - The raw API response if `requestOptions.raw` is true. ``` ```APIDOC ## create ### Description Creates a new webhook configuration. ### Method (Not specified, likely POST) ### Endpoint (Not specified, but related to webhooks) ### Parameters #### Query Parameters - `options?` (CreateOptions) - Optional - Options for the creation. ### Response #### Success Response (200) - `WebhookConfigCreateResponse` - An object representing the created webhook configuration. ``` -------------------------------- ### ListsClient constructor Source: https://docs.x.com/xdks/typescript/reference/classes/ListsClient Creates a new lists client instance. ```APIDOC ## constructor ### Description Creates a new lists client instance. ### Parameters #### Path Parameters - **client** (Client) - Required - The main X API client instance ### Returns ListsClient ### Defined in [lists/client.ts:294](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/lists/client.ts#L294) ``` -------------------------------- ### getEventsByConversationId Source: https://docs.x.com/xdks/typescript/reference/classes/DirectMessagesClient Get DM events for a DM conversation. Retrieves direct message events for a specific conversation. ```APIDOC ## getEventsByConversationId ### Description Get DM events for a DM conversation. Retrieves direct message events for a specific conversation. ### Method GET ### Endpoint /2/direct_messages/events ### Parameters #### Path Parameters - **id** (string) - Required - The DM conversation ID. #### Query Parameters - **options** (GetEventsByConversationIdOptions) - Optional - - **options.requestOptions.raw** (true) - Required - If set to true, the response will be the raw Response object. ### Response #### Success Response (200) - **Response** (Response) - Promise resolving to the API response, or raw Response if requestOptions.raw is true #### Success Response (200) - **Get2DmConversationsIdDmEventsResponse** (Get2DmConversationsIdDmEventsResponse) - ``` -------------------------------- ### HttpClient Constructor Source: https://docs.x.com/xdks/typescript/reference/classes/HttpClient Initializes a new instance of the HttpClient class. ```APIDOC ## new HttpClient() ### Description Creates a new instance of the HttpClient. ### Returns - `HttpClient`: An instance of the HttpClient. ### Defined in http-client.ts:43 ``` -------------------------------- ### ComplianceClient Constructor Source: https://docs.x.com/xdks/typescript/reference/classes/ComplianceClient Creates a new compliance client instance. Requires the main X API client instance. ```APIDOC ## new ComplianceClient(client: Client): ComplianceClient ### Description Creates a new compliance client instance. ### Parameters #### Path Parameters - **client** (Client) - Required - The main X API client instance. ### Returns ComplianceClient ### Defined in compliance/client.ts:93 ``` -------------------------------- ### Get List Memberships Source: https://docs.x.com/xdks/typescript/reference/modules/Users Retrieves the list memberships for a user. This endpoint returns information about the lists a user is a member of. ```APIDOC ## GET /users/{id}/list_memberships ### Description Retrieves the list memberships for a user. ### Endpoint /users/{id}/list_memberships ### Response #### Success Response (200) - **data** (array) - A list of list memberships. #### Response Example ```json { "data": [ { "id": "list_id_1", "name": "List Name 1" }, { "id": "list_id_2", "name": "List Name 2" } ] } ``` ``` -------------------------------- ### getAnalytics Source: https://docs.x.com/xdks/typescript/reference/classes/PostsClient Get Post analytics. Retrieves analytics data for specified Posts within a defined time range. ```APIDOC ## getAnalytics ### Description Get Post analytics. Retrieves analytics data for specified Posts within a defined time range. ### Parameters #### Path Parameters - **ids** (any[]) - Required - A comma separated list of Post IDs. Up to 100 are allowed in a single request. - **endTime** (string) - Required - YYYY-MM-DDTHH:mm:ssZ. The UTC timestamp representing the end of the time range. - **startTime** (string) - Required - YYYY-MM-DDTHH:mm:ssZ. The UTC timestamp representing the start of the time range. - **granularity** (string) - Required - The granularity for the search counts results. - **options** (GetAnalyticsOptions & { requestOptions: { raw: true } }) - Required - ### Returns `Promise` ``` -------------------------------- ### GeneralClient Constructor Source: https://docs.x.com/xdks/typescript/reference/classes/GeneralClient Creates a new instance of the GeneralClient. This client is used for interacting with the general endpoints of the X API. ```APIDOC ## new GeneralClient(client) ### Description Creates a new general client instance. ### Parameters #### Path Parameters - **client** (Client) - The main X API client instance ### Returns GeneralClient ### Defined in [general/client.ts:42](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/general/client.ts#L42) ``` -------------------------------- ### Connect to Sampled Posts Stream (JavaScript) Source: https://docs.x.com/xdks/typescript/streaming Connects to a sample of public posts using JavaScript and listens for data, errors, and stream closure. Requires client initialization and specifies tweet fields. ```javascript import { Client } from '@xdevplatform/xdk'; const client = new Client({ bearerToken: 'your-bearer-token' }); const stream = await client.stream.postsSample({ tweetFields: ['id','text'] }); stream.on('data', (event) => { console.log('New data:', event); }); stream.on('error', (e) => console.error('Stream error:', e)); stream.on('close', () => console.log('Stream closed')); ``` -------------------------------- ### getInsights28hr Source: https://docs.x.com/xdks/typescript/reference/classes/PostsClient Get 28-hour Post insights. Retrieves engagement metrics for specified Posts over the last 28 hours. ```APIDOC ## getInsights28hr ### Description Get 28-hour Post insights. Retrieves engagement metrics for specified Posts over the last 28 hours. ### Parameters #### Path Parameters - **tweetIds** (any[]) - Required - List of PostIds for 28hr metrics. - **granularity** (string) - Required - granularity of metrics response. - **requestedMetrics** (any[]) - Required - request metrics for historical request. - **options** (GetInsights28hrOptions & { requestOptions: { raw: true } }) - Required - ### Returns `Promise` Promise resolving to the API response, or raw Response if requestOptions.raw is true ``` ```APIDOC ## getInsights28hr ### Parameters #### Path Parameters - **tweetIds** (any[]) - Required - - **granularity** (string) - Required - - **requestedMetrics** (any[]) - Required - - **options?** (GetInsights28hrOptions) - Optional - ### Returns `Promise` ``` -------------------------------- ### Client Constructors for Authentication Source: https://docs.x.com/xdks/typescript/reference/classes/Client Shows different ways to authenticate the X API client using bearer tokens, OAuth2 access tokens, or OAuth1 instances. ```typescript // Bearer token authentication const client = new Client({ bearerToken: 'your-bearer-token' }); ``` ```typescript // OAuth2 authentication const client = new Client({ accessToken: 'your-access-token' }); ``` ```typescript // OAuth1 authentication const client = new Client({ oauth1: oauth1Instance }); ``` -------------------------------- ### getConnectionHistory Source: https://docs.x.com/xdks/typescript/reference/classes/ConnectionsClient Get Connection History. Returns active and historical streaming connections with disconnect reasons for the authenticated application. ```APIDOC ## getConnectionHistory ### Description Get Connection History. Returns active and historical streaming connections with disconnect reasons for the authenticated application. ### Parameters #### Query Parameters - **options** (GetConnectionHistoryOptions) - Required - Options for getting connection history. - **options.requestOptions.raw** (true) - Required - If true, returns the raw Response object. ### Returns - **Promise** - Promise resolving to the API response, or raw Response if requestOptions.raw is true ### Defined in connections/client.ts:129 ``` ```APIDOC ## getConnectionHistory ### Description Get Connection History. ### Parameters #### Query Parameters - **options?** (GetConnectionHistoryOptions) - Optional - Options for getting connection history. ### Returns - **Promise** - Promise resolving to the Get2ConnectionsResponse object. ### Defined in connections/client.ts:138 ``` -------------------------------- ### UsersClient Constructor Source: https://docs.x.com/xdks/typescript/reference/classes/UsersClient Creates a new UsersClient instance. This client is used to interact with the users endpoints of the X API. ```APIDOC ## new UsersClient(client) ### Description Creates a new users client instance. ### Parameters #### Path Parameters - **client** (Client) - Required - The main X API client instance. ### Returns - UsersClient ### Defined in src/users/client.ts:1234 ``` -------------------------------- ### Get Followed Lists Source: https://docs.x.com/xdks/typescript/reference/modules/Users Retrieves the lists that a user is following. This endpoint returns information about lists the user actively follows. ```APIDOC ## GET /users/{id}/followed_lists ### Description Retrieves the lists that a user is following. ### Endpoint /users/{id}/followed_lists ### Response #### Success Response (200) - **data** (array) - A list of followed lists. #### Response Example ```json { "data": [ { "id": "followed_list_id_x", "name": "Followed List X" }, { "id": "followed_list_id_y", "name": "Followed List Y" } ] } ``` ``` -------------------------------- ### WebhooksClient Constructor Source: https://docs.x.com/xdks/typescript/reference/classes/WebhooksClient Creates a new webhooks client instance. ```APIDOC ## new WebhooksClient(client: Client) ### Description Creates a new webhooks client instance. ### Parameters #### Path Parameters - **client** (Client) - Required - The main X API client instance #### Returns WebhooksClient #### Defined in webhooks/client.ts:162 ``` -------------------------------- ### Get Pinned Lists Source: https://docs.x.com/xdks/typescript/reference/modules/Users Retrieves the lists pinned by a user. This endpoint returns information about the lists that the user has chosen to pin. ```APIDOC ## GET /users/{id}/pinned_lists ### Description Retrieves the lists pinned by a user. ### Endpoint /users/{id}/pinned_lists ### Response #### Success Response (200) - **data** (array) - A list of pinned lists. #### Response Example ```json { "data": [ { "id": "list_id_a", "name": "Pinned List A" }, { "id": "list_id_b", "name": "Pinned List B" } ] } ``` ``` -------------------------------- ### Get Previous Page as New Paginator Instance Source: https://docs.x.com/xdks/typescript/reference/classes/Paginator Retrieves a new Paginator instance representing the previous page of results. ```typescript const previousPagePaginator = await paginator.previous(); ``` -------------------------------- ### X API SDK Modules Overview Source: https://docs.x.com/xdks/typescript/reference/modules This section provides an overview of the modules available in the X API SDK, categorized into Schemas and Classes. It lists the various client classes that can be used to interact with different aspects of the X API. ```APIDOC ## X API SDK v2.152 - v0.4.0 This document outlines the available modules and classes within the X API SDK. ### Schemas The following schemas are available for data structures: * Schemas.UsersFollowingCreateResponse * Schemas.UsersFollowingDeleteResponse * Schemas.UsersLikesCreateRequest * Schemas.UsersLikesCreateResponse * Schemas.UsersLikesDeleteResponse * Schemas.UsersRetweetsCreateRequest * Schemas.UsersRetweetsCreateResponse * Schemas.UsersRetweetsDeleteResponse * Schemas.Variant * Schemas.WebhookConfig * Schemas.WebhookConfigCreateRequest * Schemas.WebhookConfigCreateResponse * Schemas.WebhookConfigDeleteResponse * Schemas.WebhookConfigPutResponse * Schemas.WebhookLinksCreateResponse * Schemas.WebhookLinksDeleteResponse * Schemas.WebhookLinksGetResponse * Schemas.WebhookReplayCreateRequest ### Classes The following client classes are available for interacting with the X API: * **AccountActivityClient**: For managing account activity. * **ActivityClient**: For general activity operations. * **Client**: The main client for the X API. * **NewsClient**: For accessing news-related functionalities. * **CommunitiesClient**: For managing communities. * **CommunityNotesClient**: For interacting with community notes. * **ComplianceClient**: For compliance-related operations. * **ConnectionsClient**: For managing connections. * **ApiError**: Represents API errors. * **DirectMessagesClient**: For handling direct messages. * **GeneralClient**: For general API operations. * **HttpClient**: Handles HTTP requests. * **ListsClient**: For managing lists. * **MediaClient**: For media uploads and management. * **EventPaginator**: For paginating through events. * **PostPaginator**: For paginating through posts. * **UserPaginator**: For paginating through users. * **Paginator**: A generic paginator class. * **PostsClient**: For managing posts. * **SpacesClient**: For managing Spaces. * **StreamClient**: For real-time stream interactions. * **TrendsClient**: For accessing trending topics. * **UsageClient**: For tracking API usage. ``` -------------------------------- ### GetBuyersResponse Source: https://docs.x.com/xdks/typescript/reference/modules/Spaces Response for retrieving buyers of a Space. ```APIDOC ## Type Alias: GetBuyersResponse Ƭ **GetBuyersResponse**: [`Get2SpacesIdBuyersResponse`](/xdks/typescript/reference/interfaces/Schemas.Get2SpacesIdBuyersResponse) Response for getBuyers ``` -------------------------------- ### InitializeUploadResponse Source: https://docs.x.com/xdks/typescript/reference/modules/Media Represents the response structure for initiating a media upload. It is an alias for MediaUploadResponse. ```APIDOC ## InitializeUploadResponse ### Description Response for initializeUpload. This type is an alias for MediaUploadResponse. ### Type [`MediaUploadResponse`](/xdks/typescript/reference/interfaces/Schemas.MediaUploadResponse) ``` -------------------------------- ### Get User By Username Source: https://docs.x.com/xdks/typescript/reference/modules/Users Retrieves a user's profile information using their username. This is useful for fetching public user data. ```APIDOC ## GET /users/by/username/{username} ### Description Retrieves a user's profile information using their username. ### Endpoint /users/by/username/{username} ### Parameters #### Path Parameters - **username** (string) - Required - The username of the user to retrieve. ### Response #### Success Response (200) - **id** (string) - The user's unique identifier. - **username** (string) - The user's username. - **name** (string) - The user's display name. #### Response Example ```json { "id": "user_id_123", "username": "exampleuser", "name": "Example User" } ``` ``` -------------------------------- ### getSubscriptions Source: https://docs.x.com/xdks/typescript/reference/classes/ActivityClient Get a list of active subscriptions for XAA. Returns a Promise resolving to the API response, or a raw Response if requestOptions.raw is true. ```APIDOC ## getSubscriptions ### Description Get X activity subscriptions Get a list of active subscriptions for XAA ### Parameters #### Query Parameters - **options** (Object) - Required - **requestOptions** (Object) - **raw** (true) - Required ### Returns - Promise ### Defined in [activity/client.ts:159](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/activity/client.ts#L159) ``` ```APIDOC ## getSubscriptions ### Description Get X activity subscriptions Get a list of active subscriptions for XAA ### Returns - Promise ### Defined in [activity/client.ts:168](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/activity/client.ts#L168) ``` -------------------------------- ### CommunitiesClient Constructor Source: https://docs.x.com/xdks/typescript/reference/classes/CommunitiesClient Creates a new communities client instance. It requires the main X API client instance for authentication and request handling. ```APIDOC ## new CommunitiesClient(client) ### Description Creates a new communities client instance. ### Parameters #### Path Parameters - **client** (Client) - Required - The main X API client instance. ### Returns - **CommunitiesClient** - The newly created CommunitiesClient instance. ### Defined in communities/client.ts:102 ``` -------------------------------- ### get news story by ID Source: https://docs.x.com/xdks/typescript/reference/classes/NewsClient Retrieves news story by its ID. Overloaded method to either return a raw Response or a structured Get2NewsIdResponse. ```APIDOC ## get ### Description Get news stories by ID. Retrieves news story by its ID. ### Method GET ### Endpoint /2/news/{id} ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the news story. #### Query Parameters - **options** (GetOptions & { requestOptions: { raw: true } }) - Required - Options for the request, including raw response flag. #### Request Body - None ### Request Example ```typescript // Example for raw response const response = await newsClient.get(newsId, { requestOptions: { raw: true } }); // Example for structured response const newsItem = await newsClient.get(newsId); ``` ### Response #### Success Response (200) - **Response** (Response) - Raw API response if requestOptions.raw is true. - **Get2NewsIdResponse** (Get2NewsIdResponse) - Structured response object. #### Response Example ```json // Raw Response Example HTTP/1.1 200 OK Content-Type: application/json { ... } // Structured Response Example { "data": { ... }, "meta": { ... } } ``` ``` -------------------------------- ### initializeUpload Source: https://docs.x.com/xdks/typescript/reference/classes/MediaClient Initializes an upload for a media file. This method can return either a structured response or the raw API response based on the request options. ```APIDOC ## initializeUpload ### Description Initializes an upload for a media file. This method can return either a structured response or the raw API response based on the request options. ### Method POST (inferred) ### Endpoint /media/upload (inferred) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **options** (InitializeUploadOptions & { requestOptions: { raw: true } }) - Required - Options for initializing the upload, including raw response preference. ### Request Example ```json { "options": { "requestOptions": { "raw": true } } } ``` ### Response #### Success Response (200) - **Response** - The raw API response if `requestOptions.raw` is true. #### Response Example ```json { "example": "raw response data" } ``` ## initializeUpload ### Description Initializes an upload for a media file, returning a structured response. ### Method POST (inferred) ### Endpoint /media/upload (inferred) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **options** (InitializeUploadOptions) - Required - Options for initializing the upload. ### Request Example ```json { "options": {} } ``` ### Response #### Success Response (200) - **MediaUploadResponse** - The structured response for media upload initialization. #### Response Example ```json { "example": "MediaUploadResponse object" } ``` ``` -------------------------------- ### getById Source: https://docs.x.com/xdks/typescript/reference/classes/CommunitiesClient Get Community by ID. Retrieves details of a specific Community by its ID. Supports returning either a structured response or the raw API Response. ```APIDOC ## getById(id, options) ### Description Get Community by ID. Retrieves details of a specific Community by its ID. ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the Community. - **options** (GetByIdOptions & { requestOptions: { raw: true } }) - Required - Options for retrieving the community, including raw response flag. ### Returns - **Promise** - Promise resolving to the API response, or raw Response if requestOptions.raw is true ### Defined in communities/client.ts:352 ``` ```APIDOC ## getById(id, options?) ### Description Get Community by ID. Retrieves details of a specific Community by its ID. ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the Community. - **options?** (GetByIdOptions) - Optional - Options for retrieving the community. ### Returns - **Promise** - Promise resolving to the structured community details. ### Defined in communities/client.ts:365 ``` -------------------------------- ### createBookmark Source: https://docs.x.com/xdks/typescript/reference/classes/UsersClient Adds a post to the authenticated user’s bookmarks. It returns a Promise that resolves to the API response. ```APIDOC ## createBookmark ### Description Adds a post to the authenticated user’s bookmarks. It returns a Promise that resolves to the API response. ### Method POST ### Endpoint /2/users/:id/bookmarks ### Parameters #### Path Parameters - **id** (string) - Required - The ID of the authenticated source User for whom to add bookmarks. #### Request Body - **id** (string) - Required - The ID of the post to bookmark. ### Response #### Success Response (200) - **data** (object) - Information about the created bookmark. #### Response Example ```json { "data": { "id": "11223", "bookmarkId": "44556" } } ``` ``` -------------------------------- ### PostPaginator Constructor Source: https://docs.x.com/xdks/typescript/reference/classes/PostPaginator Creates a new PostPaginator instance. This constructor takes a function that fetches a page of data, given an optional pagination token. ```APIDOC ## new PostPaginator(fetchPage) ### Description Creates a new paginator instance. ### Parameters #### Path Parameters - **fetchPage** (function) - Required - Function that fetches a page of data given a pagination token. The function should accept an optional token string and return a Promise resolving to a PaginatedResponse object. ### Returns - [`PostPaginator`](/xdks/typescript/reference/classes/PostPaginator) ### Defined in paginator.ts:90 ``` -------------------------------- ### createSubscription Source: https://docs.x.com/xdks/typescript/reference/classes/ActivityClient Create X activity subscription. Creates a subscription for an X activity event. Returns a Promise resolving to the API response, or a raw Response if requestOptions.raw is true. ```APIDOC ## createSubscription ### Description Create X activity subscription Creates a subscription for an X activity event ### Parameters #### Query Parameters - **options** (CreateSubscriptionOptions & { requestOptions: { raw: true } }) - Required ### Returns - Promise ### Defined in [activity/client.ts:237](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/activity/client.ts#L237) ``` ```APIDOC ## createSubscription ### Description Create X activity subscription Creates a subscription for an X activity event ### Parameters #### Query Parameters - **options?** (CreateSubscriptionOptions) - Optional ### Returns - Promise ### Defined in [activity/client.ts:246](https://github.com/xdevplatform/xdk-typescript/blob/81aacb165e0802e188f608bdf462b60fc4e713a2/src/activity/client.ts#L246) ``` -------------------------------- ### StreamClient Constructor Source: https://docs.x.com/xdks/typescript/reference/classes/StreamClient Initializes a new instance of the StreamClient class. ```APIDOC ## new StreamClient(client: Client) ### Description Initializes a new instance of the StreamClient class. ### Parameters #### Path Parameters - **client** (Client) - Required - The client instance to use for the stream. ### Returns StreamClient - An instance of the StreamClient. ```