export type CreateApiStatementInitiationArgs = {client_id: string, 'Content-Type': string, Timezone?: string | undefined, 'Attachment-Encoding'?: string | undefined, body: BodyInit}; export type CreateApiStatementInitiationOptions = {baseUrl?: string | undefined, clientCredentials?: string | undefined, fetch?: typeof fetch | undefined}; /** * Statement Initiation Request * * POST /statement/initiation */ export const createApiStatementInitiation = async (args: CreateApiStatementInitiationArgs, options?: CreateApiStatementInitiationOptions) => { const {baseUrl = "https://tts.apib2b.citi.com/citiconnect/prod/accountstatementservices/v1", fetch: fetchFn = fetch, clientCredentials} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('content-type', "application/xml") headers.set('accept', "application/xml") if (args.client_id != null) query.append("client_id", String(args.client_id)) if (args['Content-Type'] != null) headers.set("Content-Type", String(args['Content-Type'])) if (args.Timezone != null) headers.set("Timezone", String(args.Timezone)) if (args['Attachment-Encoding'] != null) headers.set("Attachment-Encoding", String(args['Attachment-Encoding'])) if (clientCredentials !== undefined) headers.set('authorization', `Bearer ${clientCredentials}`) const url = `${baseUrl.replace(/\/+$/, '')}/statement/initiation${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 res.blob() };