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

Function resolveUsernameId

apps/sim/connectors/x/x.ts:181–198  ·  view source on GitHub ↗

* Resolves a public username to its numeric user ID via * GET /2/users/by/username/:username.

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

Source from the content-addressed store, hash-verified

179 * GET /2/users/by/username/:username.
180 */
181async function resolveUsernameId(
182 accessToken: string,
183 username: string,
184 retryOptions?: Parameters<typeof fetchWithRetry>[2]
185): Promise<string> {
186 const handle = username.trim().replace(/^@/, '')
187 const data = (await xApiGet(
188 `/users/by/username/${encodeURIComponent(handle)}`,
189 accessToken,
190 undefined,
191 retryOptions
192 )) as { data?: { id?: string }; errors?: Array<{ detail?: string }> }
193 const id = data.data?.id
194 if (!id) {
195 throw new Error(data.errors?.[0]?.detail || `User @${handle} not found`)
196 }
197 return id
198}
199
200/**
201 * Builds a deterministic, metadata-based content hash for a tweet.

Callers 1

x.tsFile · 0.85

Calls 2

xApiGetFunction · 0.85
replaceMethod · 0.65

Tested by

no test coverage detected