export type ForecastDataIngestionTargetDataPayload = {rangeType: 'EXACT' | 'NOT_LESS_THAN' | 'NOT_MORE_THAN' | 'BETWEEN', value?: number | undefined, fromValue?: number | undefined, toValue?: number | undefined, date: string}; export type ForecastDataIngestionTargetDataInput = {externalId: string, externalUnitId: string, externalSectionId?: string | undefined, targetPayload?: Array | undefined}; export type ForecastDataIngestionTargetDataInputList = {requests: Array}; export type CreateApiV2ForecastsTargetDataArgs = {body: ForecastDataIngestionTargetDataInputList}; export type CreateApiV2ForecastsTargetDataOptions = {baseUrl?: string | undefined, OAuth2ClientCredentials?: string | undefined, fetch?: typeof fetch | undefined}; /** * Upload daily target data with maximum 366 rows * * POST /v2/forecasts/target-data * * Also accepts auth: OAuth2ClientCredentials */ export const createApiV2ForecastsTargetData = async (args: CreateApiV2ForecastsTargetDataArgs, options?: CreateApiV2ForecastsTargetDataOptions) => { const {baseUrl = "https://api.quinyx.com", fetch: fetchFn = fetch, OAuth2ClientCredentials} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/json") headers.set('accept', "*/*") if (OAuth2ClientCredentials !== undefined) headers.set('authorization', `Bearer ${OAuth2ClientCredentials}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/forecasts/target-data${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 res.blob() };