MCPcopy Index your code
hub / github.com/simstudioai/sim / xApiGet

Function xApiGet

apps/sim/connectors/x/x.ts:133–160  ·  view source on GitHub ↗

* Performs an authenticated GET against the X API v2 and returns the parsed JSON.

(
  path: string,
  accessToken: string,
  params?: Record<string, string>,
  retryOptions?: Parameters<typeof fetchWithRetry>[2]
)

Source from the content-addressed store, hash-verified

131 * Performs an authenticated GET against the X API v2 and returns the parsed JSON.
132 */
133async function xApiGet(
134 path: string,
135 accessToken: string,
136 params?: Record<string, string>,
137 retryOptions?: Parameters<typeof fetchWithRetry>[2]
138): Promise<unknown> {
139 const queryParams = params ? `?${new URLSearchParams(params).toString()}` : ''
140 const url = `${X_API_BASE}${path}${queryParams}`
141
142 const response = await fetchWithRetry(
143 url,
144 {
145 method: 'GET',
146 headers: {
147 Authorization: `Bearer ${accessToken}`,
148 'Content-Type': 'application/json',
149 },
150 },
151 retryOptions
152 )
153
154 if (!response.ok) {
155 const body = await response.text().catch(() => '')
156 throw new Error(`X API HTTP error: ${response.status} ${response.statusText} ${body}`.trim())
157 }
158
159 return response.json()
160}
161
162/**
163 * Resolves the authenticated user's numeric ID via GET /2/users/me.

Callers 3

resolveMyUserIdFunction · 0.85
resolveUsernameIdFunction · 0.85
x.tsFile · 0.85

Calls 3

fetchWithRetryFunction · 0.90
textMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected