export type CreateApiMonthlyZReferenceTaxYearMonthArgs = {zReference: string, taxYear: unknown, month: 'JAN' | 'FEB' | 'MAR' | 'APR' | 'MAY' | 'JUN' | 'JUL' | 'AUG' | 'SEP' | 'OCT' | 'NOV' | 'DEC', Accept: 'application/vnd.hmrc.1.0+json', Authorization: string, body: BodyInit}; export type CreateApiMonthlyZReferenceTaxYearMonthOptions = {baseUrl?: string | undefined, userRestricted?: string | undefined, fetch?: typeof fetch | undefined}; /** * Submit monthly report data * * POST /monthly/{zReference}/{taxYear}/{month} */ export const createApiMonthlyZReferenceTaxYearMonth = async (args: CreateApiMonthlyZReferenceTaxYearMonthArgs, options?: CreateApiMonthlyZReferenceTaxYearMonthOptions) => { const {baseUrl = "https://test-api.service.hmrc.gov.uk/obligations/declaration/isa/return", fetch: fetchFn = fetch, userRestricted} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/x-ndjson") if (args.Accept != null) headers.set("Accept", String(args.Accept)) if (args.Authorization != null) headers.set("Authorization", String(args.Authorization)) if (userRestricted !== undefined) headers.set('authorization', `Bearer ${userRestricted}`) const url = `${baseUrl.replace(/\/+$/, '')}/monthly/${encodeURIComponent(String(args.zReference))}/${encodeURIComponent(String(args.taxYear))}/${encodeURIComponent(String(args.month))}${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers, body: args.body}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return undefined };