export type GetApiV2DatasetDatasetNameKeyArgs = {datasetName: string, key: string, page?: number | undefined, pageSize?: number | undefined}; export type GetApiV2DatasetDatasetNameKeyOptions = {baseUrl?: string | undefined, apikey?: string | undefined, fetch?: typeof fetch | undefined}; /** * Get a value of a given key for a dataset * * GET /v2/dataset/{datasetName}/{key} * * Also accepts auth: oauth2 */ export const getApiV2DatasetDatasetNameKey = async (args: GetApiV2DatasetDatasetNameKeyArgs, options?: GetApiV2DatasetDatasetNameKeyOptions) => { const {baseUrl = "https://api.domain.com.au", fetch: fetchFn = fetch, apikey} = options ?? {} const query = new URLSearchParams() const headers = new Headers() if (args.page != null) query.append("page", String(args.page)) if (args.pageSize != null) query.append("pageSize", String(args.pageSize)) if (apikey !== undefined) headers.set("x-api-key", apikey) const url = `${baseUrl.replace(/\/+$/, '')}/v2/dataset/${encodeURIComponent(String(args.datasetName))}/${encodeURIComponent(String(args.key))}${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 undefined };