export type GetApiApiV4SystemsSystemIdLiveDataArgs = {system_id: number, duration?: number | undefined}; export type GetApiApiV4SystemsSystemIdLiveDataOptions = {baseUrl?: string | undefined, fetch?: typeof fetch | undefined}; /** * Site Level Live Status * * GET /api/v4/systems/{system_id}/live_data */ export const getApiApiV4SystemsSystemIdLiveData = async (args: GetApiApiV4SystemsSystemIdLiveDataArgs, options?: GetApiApiV4SystemsSystemIdLiveDataOptions) => { const {baseUrl = "https://api-qa2.enphaseenergy.com", fetch: fetchFn = fetch} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "text/event-stream") if (args.duration != null) headers.set("duration", String(args.duration)) const url = `${baseUrl.replace(/\/+$/, '')}/api/v4/systems/${encodeURIComponent(String(args.system_id))}/live_data${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "GET", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.text() };