export type GetApiV2DownloadsDirSubdirFilenameArgs = {download?: string | undefined, rotation?: number | undefined}; export type GetApiV2DownloadsDirSubdirFilenameOptions = {baseUrl?: string | undefined, apiKeys?: string | undefined, fetch?: typeof fetch | undefined}; /** * Download file * * GET /v2/downloads/{dir}/{subdir}/{filename} */ export const getApiV2DownloadsDirSubdirFilename = async (args: GetApiV2DownloadsDirSubdirFilenameArgs, options?: GetApiV2DownloadsDirSubdirFilenameOptions) => { const {baseUrl = "https://api.shipstation.com", fetch: fetchFn = fetch, apiKeys} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/pdf") if (args.download != null) query.append("download", String(args.download)) if (args.rotation != null) query.append("rotation", String(args.rotation)) if (apiKeys !== undefined) headers.set("api-key", apiKeys) const url = `${baseUrl.replace(/\/+$/, '')}/v2/downloads/${encodeURIComponent(String(args.dir))}/${encodeURIComponent(String(args.subdir))}/${encodeURIComponent(String(args.filename))}${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() };