expense.attachment.updated event fires each time a document is added or removed, with a key you can download right away.
Before you start
- Set up a webhook endpoint subscribed to
expense.attachment.updated. - Create an API key, as described in the quickstart. Your handler uses it to download files.
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:RECEIPTuses/download/expenseSUPPORTING_DOCUMENTuses/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
documentKeystops resolving, with a404, once the document is removed or replaced. - Expect replacements. An expense has one receipt. Replacing it sends
ATTACHMENT_DELETEDfor the old file, thenATTACHMENT_ADDEDfor 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
idanddocumentKey, so a duplicate delivery doesn’t create a second copy.