Skip to main content
Receipts for card and UPI expenses are usually uploaded after the payment. By then the transaction event has already been sent, so waiting for it won’t get you the receipt. The expense.attachment.updated event fires each time a document is added or removed, with a key you can download right away.

Before you start

Walkthrough

1

Receive the event

An employee uploads a receipt. Pazy sends expense.attachment.updated with action: "ATTACHMENT_ADDED" and attachmentType: "RECEIPT".
2

Choose the download endpoint

Use attachmentType to pick the path:
  • RECEIPT uses /download/expense
  • SUPPORTING_DOCUMENT uses /download/expense-attachment
3

Download the file

Call the File Download API with fileKey set to data.documentKey.
4

Store it against the expense

Save the file with the expense id from the event. Use name and mimeType from the event for the file name and type.

Example handler

Things to get right

  • Download straight away. A documentKey stops resolving, with a 404, once the document is removed or replaced.
  • Expect replacements. An expense has one receipt. Replacing it sends ATTACHMENT_DELETED for the old file, then ATTACHMENT_ADDED for the new one. Process both, and keep the latest.
  • Handle deletes. If you mirror files, delete your copy on ATTACHMENT_DELETED.
  • Do the download in a background job. Acknowledge the webhook first, as in Delivery and retries, so a slow download doesn’t cause a timeout and a retry.
  • Links raise no event. Link-type attachments have no file, so you won’t be notified about them.
  • Dedupe. Key your storage on the expense id and documentKey, so a duplicate delivery doesn’t create a second copy.