export type GetApiV2OrdersOrderIdDocumentsArgs = {order_id: string, types?: (Array<'RETURN_LABEL' | 'CUSTOMER_INVOICE' | 'DELIVERY_SLIP' | 'SHIPMENT_DELIVERY_SLIP' | 'CHANNEL_SPECIFIC'>) | undefined, document_ids?: Array | undefined}; export type GetApiV2OrdersOrderIdDocumentsOptions = {baseUrl?: string | undefined, Bearer?: string | undefined, fetch?: typeof fetch | undefined}; /** * v2-downloadOrderDocuments - Download documents from an order * * GET /v2/orders/{order_id}/documents */ export const getApiV2OrdersOrderIdDocuments = async (args: GetApiV2OrdersOrderIdDocumentsArgs, options?: GetApiV2OrdersOrderIdDocumentsOptions) => { const {baseUrl = "https://miraklconnect.com/api", fetch: fetchFn = fetch, Bearer} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/zip") for (const item of args.types ?? []) query.append("types", String(item)) for (const item of args.document_ids ?? []) query.append("document_ids", String(item)) if (Bearer !== undefined) headers.set('authorization', `Bearer ${Bearer}`) const url = `${baseUrl.replace(/\/+$/, '')}/v2/orders/${encodeURIComponent(String(args.order_id))}/documents${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.blob() };