export type CreateApiDocumentsIdContentArgs = {id: string}; export type CreateApiDocumentsIdContentOptions = {baseUrl?: string | undefined, basicAuth?: {username: string, password: string} | undefined, fetch?: typeof fetch | undefined}; /** * Fetch document content * * POST /documents/{id}/content * * Also accepts auth: oauth2 */ export const createApiDocumentsIdContent = async (args: CreateApiDocumentsIdContentArgs, options?: CreateApiDocumentsIdContentOptions) => { const {baseUrl = "https://api.razorpay.com/v1", fetch: fetchFn = fetch, basicAuth} = options ?? {} const query = new URLSearchParams() const headers = new Headers() headers.set('accept', "application/octet-stream") if (basicAuth !== undefined) headers.set('authorization', `Basic ${btoa(`${basicAuth.username}:${basicAuth.password}`)}`) const url = `${baseUrl.replace(/\/+$/, '')}/documents/${encodeURIComponent(String(args.id))}/content${query.size > 0 ? `?${query}` : ''}` const res = await fetchFn(url, {method: "POST", headers}) if (!res.ok) throw new Error(`Request failed with status ${res.status}`, {cause: {status: res.status, body: await res.text()}}) return res.blob() };