export type CreateApiV2PlayerStatsArgs = {body: {xuids: Array, groups?: Array<{name: string, titleId: string}> | undefined, stats?: Array<{name: string, titleId: string}> | undefined}}; export type CreateApiV2PlayerStatsOptions = {baseUrl?: string | undefined, apiKey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get player statistics * * POST /v2/player/stats */ export const createApiV2PlayerStats = async (args: CreateApiV2PlayerStatsArgs, options?: CreateApiV2PlayerStatsOptions) => { const {baseUrl = "https://api.xbl.io", fetch: fetchFn = fetch, apiKey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") if (apiKey !== undefined) headers.set("X-Authorization", apiKey) const url = `${baseUrl.replace(/\/+$/, '')}/v2/player/stats${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: JSON.stringify(args.body)}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };