export type GetApiV3GrantsGrantIdAttachmentsAttachmentIdDownloadArgs = {query_imap?: boolean | undefined}; export type GetApiV3GrantsGrantIdAttachmentsAttachmentIdDownloadOptions = {baseUrl?: string | undefined, NYLASAPIKEY?: string | undefined, fetch?: typeof fetch | undefined}; /** * Download an Attachment * * GET /v3/grants/{grant_id}/attachments/{attachment_id}/download * * Also accepts auth: ACCESS_TOKEN */ export const getApiV3GrantsGrantIdAttachmentsAttachmentIdDownload = async (args: GetApiV3GrantsGrantIdAttachmentsAttachmentIdDownloadArgs, options?: GetApiV3GrantsGrantIdAttachmentsAttachmentIdDownloadOptions) => { const {baseUrl = "https://api.us.nylas.com", fetch: fetchFn = fetch, NYLASAPIKEY} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/octet-stream") if (args.query_imap != null) query.append("query_imap", String(args.query_imap)) if (NYLASAPIKEY !== undefined) headers.set('authorization', `Bearer ${NYLASAPIKEY}`) const url = `${baseUrl.replace(/\/+$/, '')}/v3/grants/${encodeURIComponent(String(args.grant_id))}/attachments/${encodeURIComponent(String(args.attachment_id))}/download${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() };