fix(export): use direct content endpoint for PDF statement downloads
This commit is contained in:
@@ -111,25 +111,15 @@ export class BunqExport {
|
||||
throw new Error('Export ID not set');
|
||||
}
|
||||
|
||||
// First get the export details to find the attachment
|
||||
const exportDetails = await this.get();
|
||||
|
||||
if (!exportDetails.attachment || exportDetails.attachment.length === 0) {
|
||||
throw new Error('Export has no attachment');
|
||||
}
|
||||
// For PDF statements, use the /content endpoint directly
|
||||
const downloadUrl = `${this.bunqAccount.apiContext.getBaseUrl()}/v1/user/${this.bunqAccount.userId}/monetary-account/${this.monetaryAccount.id}/customer-statement/${this.id}/content`;
|
||||
|
||||
const attachmentUuid = exportDetails.attachment[0].attachment_public_uuid;
|
||||
|
||||
// Download the attachment content
|
||||
const response = await plugins.smartrequest.request(
|
||||
`${this.bunqAccount.apiContext.getBaseUrl()}/v1/attachment-public/${attachmentUuid}/content`,
|
||||
{
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'X-Bunq-Client-Authentication': this.bunqAccount.apiContext.getSession().getContext().sessionToken
|
||||
}
|
||||
const response = await plugins.smartrequest.request(downloadUrl, {
|
||||
method: 'GET',
|
||||
headers: {
|
||||
'X-Bunq-Client-Authentication': this.bunqAccount.apiContext.getSession().getContext().sessionToken
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
return Buffer.from(response.body);
|
||||
}
|
||||
|
Reference in New Issue
Block a user