From fb30c6f4e3938b8d3f65cfddfb6b5526a652c81a Mon Sep 17 00:00:00 2001 From: Juergen Kunz Date: Sat, 26 Jul 2025 20:54:39 +0000 Subject: [PATCH] fix(export): use direct content endpoint for PDF statement downloads --- changelog.md | 7 +++++++ package.json | 2 +- ts/bunq.classes.export.ts | 24 +++++++----------------- 3 files changed, 15 insertions(+), 18 deletions(-) diff --git a/changelog.md b/changelog.md index 295ba3a..7a40778 100644 --- a/changelog.md +++ b/changelog.md @@ -1,5 +1,12 @@ # Changelog +## 2025-07-26 - 4.1.3 - fix(export) +Fix PDF statement download to use direct content endpoint + +- Changed `downloadContent()` method to use the `/content` endpoint directly for PDF statements +- Removed unnecessary attachment lookup step that was causing issues +- Simplified the download process for customer statement exports + ## 2025-07-25 - 4.1.1 - fix(httpclient) Fix query parameter handling for smartrequest compatibility diff --git a/package.json b/package.json index ea0e6f0..ec722af 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@apiclient.xyz/bunq", - "version": "4.1.2", + "version": "4.1.3", "private": false, "description": "A full-featured TypeScript/JavaScript client for the bunq API", "type": "module", diff --git a/ts/bunq.classes.export.ts b/ts/bunq.classes.export.ts index bfb4934..2d08621 100644 --- a/ts/bunq.classes.export.ts +++ b/ts/bunq.classes.export.ts @@ -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); }