Merge several attachments & download them in a single a base64 represented PDF file.

🚧

Be sure to use the attachment id, not the request id

NEW files response attribute

We recently added a new files property which allow you to loop though all attachments uploaded in the Penbox form without having to maintain an exhaustive mapping of all the data keys form by form.

The advantage of looping through files instead of the previous attachments property is that it's groupped by data key which allows you to download all files uploaded for one question in the Penbox form into a single merged PDF.

{
  "id": "string",
  "data": {
    "zip": "string"
  },
  "responses": [
    {
      "data": {
        "reference_number_of_the_registration_form": 727618514,
        "vehicle_registration_application": [
          {
            "id": "c9ddb864-dac6-4c4f-80fa-ff4d95b9b510",
            "name": "John Doe Vehicle registration 1.pdf",
            "original_name": "705c_XP7YGCES8RB462717_2024-07-31_0743 (2).pdf"
          },
          {
            "id": "34e97fb8-2b4b-49fe-ab94-1c3638e9020c",
            "name": "John Doe Vehicle registration 2.pdf",
            "original_name": "BB RN122277453.pdf"
          }
        ],
        "place_of_birth": "Brussels",
        "eid_card": [
          {
            "id": "errtN97fb8-2b4b-49fe-ab94-1c3638e9020c",
            "name": "John Doe EID card.pdf",
            "original_name": "my_eid_card.pdf"
          }
         ]
      },
      "attachments": [
          {
            "id": "c9ddb864-dac6-4c4f-80fa-ff4d95b9b510",
            "name": "705c_XP7YGCES8RB462717_2024-07-31_0743 (2).pdf",
            "original_name": "705c_XP7YGCES8RB462717_2024-07-31_0743 (2).pdf"
          },
          {
            "id": "errtN97fb8-2b4b-49fe-ab94-1c3638e9020c",
            "name": "John Doe EID card.pdf",
            "original_name": "my_eid_card.pdf"
          },
          {
            "id": "34e97fb8-2b4b-49fe-ab94-1c3638e9020c",
            "name": "BB RN122277453.pdf",
            "original_name": "BB RN122277453.pdf"
          }
      ],
      "files": {
        "vehicle_registration_application": [
          {
            "id": "c9ddb864-dac6-4c4f-80fa-ff4d95b9b510",
            "name": "John Doe Vehicle registration 1.pdf",
            "original_name": "705c_XP7YGCES8RB462717_2024-07-31_0743 (2).pdf"
          },
          {
            "id": "34e97fb8-2b4b-49fe-ab94-1c3638e9020c",
            "name": "John Doe Vehicle registration 2.pdf",
            "original_name": "BB RN122277453.pdf"
          }
         ],
         "eid_card": [
          {
            "id": "errtN97fb8-2b4b-49fe-ab94-1c3638e9020c",
            "name": "John Doe EID card.pdf",
            "original_name": "my_eid_card.pdf"
          }
        ]
      }
    }
  ]
}

Get the vehicle registration files in one merge PDF

GET https://connect.penbox.io/v1/attachments?ids=c9ddb864-dac6-4c4f-80fa-ff4d95b9b510&ids=34e97fb8-2b4b-49fe-ab94-1c3638e9020c

Javascript client example

// This code is almost the same as what is used today to download a normal streamed attachment.
const downloadMergedPDF = async (fileIds) => {
  const fileUrl = `https://connect.penbox.io/v1/attachments?ids=${fileIds.join('&ids=')}`;
  const writer = fs.createWriteStream();

  const response = await axios({
    url: fileUrl,
    method: 'GET',
    responseType: 'stream'
  });

  response.data.pipe(writer);

  return new Promise((resolve, reject) => {
    writer.on('finish', resolve);
    writer.on('error', reject);
  });
};

// This code downloads all attachments per file key
const downloadAllFiles = async () => {
  const fileIds = PenboxRequest.responses[0].files.map(file => file.id);
  try {
    await downloadMergedPDF(fileIds);
  } catch (error) {
    console.error(`Error downloading merged PDF: ${error.message}`);
  }
};

downloadAllFiles(files);
Language
Authorization
OAuth2
Click Try It! to start a request and see the response here!