Nightly OneDrive receipts to Excel expense log with Outlook summary
Drop receipts and invoices in OneDrive and every weekday at 11pm this agent parses them, fills your Excel expense log, and emails you a summary.
Build an agent workflow that runs on a cron trigger every weekday at 11pm in my local time zone and turns the receipts and invoices I drop in OneDrive into a clean Excel expense log, with an Outlook email summary at the end.
Inputs the workflow should accept as configuration:
- inbox_folder_path: the OneDrive folder I use as my receipts inbox (default /Receipts).
- workbook_path: the OneDrive path to my Excel expense log (must be OneDrive for Business or SharePoint, since the Excel API does not support consumer OneDrive).
- worksheet_name and table_name: the named table inside that workbook the agent should append rows to. Assume the table already has columns Date, Vendor, Amount, Currency, Tax, Category, Description, and Source File (in that order).
- summary_recipient: the email address that gets the nightly Outlook summary (default: my own).
- categories: a list of expense categories the agent should classify each receipt into (default: Travel, Meals, Software, Office, Hardware, Marketing, Professional Services, Other).
- timezone: my local IANA time zone, used both for the cron schedule and for the 'last 24 hours' window.
On each run, the agent should:
1. Use Microsoft OneDrive to enumerate files added to inbox_folder_path in the last 24 hours. Prefer search_items scoped to that folder with a recency filter, and fall back to list_children and filtering by createdDateTime if search is unavailable. Skip anything that lives inside a year/month subfolder (those are already filed).
2. For each new file, download its content with Microsoft OneDrive's download_file_content. If the file is an Office document (.docx, .doc, .xls, .xlsx, .pptx), use download_converted_format with format=pdf so the agent can read the contents as a PDF. Image formats (JPG, PNG, HEIC) and PDFs go straight through.
3. Read the file and extract: transaction date (ISO yyyy-mm-dd), vendor name, total amount, currency code (default USD if not stated), tax amount if visible, the best matching category from the configured list, and a single short description (under 80 chars). If the receipt is unreadable or any required field is missing, do not invent values: add the file to an 'unparseable' list with a short reason.
4. For each successfully parsed receipt, append one row to the configured Excel table using Microsoft Excel's add_table_row. Match the values to the existing column order, and put the original OneDrive filename (and a web URL to the file if available) in the Source File column.
5. After the row is appended, move the original file in OneDrive into inbox_folder_path/{YYYY}/{MM}/ based on the parsed transaction date (creating the year and month subfolders if they do not exist) using Microsoft OneDrive's move_item. Leave unparseable files in the inbox so I can fix them tomorrow.
6. At the end of the run, send one Microsoft Outlook email via send_mail to summary_recipient. The email should include: number of receipts processed, total amount spent grouped by currency, a count of receipts by category, the top three highest individual expenses with vendor and amount, and a clearly labeled list of any unparseable files with the reason and a direct OneDrive link to each. Use a clean HTML body, not plain text. If there were zero new receipts and zero unparseable files, send a brief 'nothing to do tonight' email so I know the agent ran.
Operational details:
- Treat Microsoft OneDrive, Microsoft Excel, and Microsoft Outlook as separate connections, even though they share a Microsoft 365 sign-in.
- Honor Microsoft Graph throttling: on 429, wait the Retry-After value and retry with backoff.
- Be idempotent: never write the same receipt twice. Before adding a row, check that no existing row in the table has the same Source File filename.
- Cap each run at processing 100 receipts; if there are more, process the oldest 100 and mention the backlog in the email.
Additional information
What does this prompt do?
- Scans your OneDrive Receipts folder every weekday at 11pm for anything you dropped in over the last 24 hours.
- Reads each photo, PDF, or Word receipt and extracts vendor, date, amount, currency, tax, category, and a one-line description.
- Appends every parsed receipt as a new row in your existing Excel expense log so your bookkeeping stays current.
- Files the original into a tidy year and month subfolder in OneDrive so the inbox stays clean.
- Emails you an Outlook summary with total spend, a count by category, and a list of any files it could not read so you can fix them.
What do I need to use this?
- A Microsoft 365 account with OneDrive, Excel, and Outlook (work or school, since Excel for the web requires a business OneDrive).
- An existing Excel workbook with a named table for your expense log, with columns like Date, Vendor, Amount, Currency, Tax, Category, Description, and Source File.
- A OneDrive folder you treat as a receipts inbox (for example /Receipts) where you drop photos, PDFs, and invoices.
How can I customize it?
- Change when it runs. Move it earlier in the evening, or have it run daily instead of weekday only.
- Change the inbox folder, the workbook, or the table name to match your filing system.
- Add or rename categories (Travel, Meals, Software, Office, Client billable) and tell the agent how to map vendors to them.
- Send the nightly summary to your accountant or a shared mailbox instead of yourself, or skip the email on nights with no receipts.
Frequently asked questions
Will this work with photos of paper receipts?
What happens if a receipt is blurry or missing key fields?
Does it touch receipts I dropped in days ago?
Can I keep using my current expense spreadsheet?
Does it work with personal OneDrive accounts?
Stop typing receipts into a spreadsheet.
Connect OneDrive, Excel, and Outlook once, and Geni does your nightly bookkeeping for you.