You read each month's invoice emails and retype the vendor and amount into a sheet. This article is for people in accounting. It explains how to have AI read emails whose body contains the invoice details, and have a person review them before they go into Google Sheets.
Summary
Build a Samurai App workflow from these 4 connected steps.
- Start when Gmail receives a message
- Use "Generate with AI" to extract the vendor, amount, and so on from the body
- Use "Wait for approval or input" so a person checks the values
- Use "Run external service" to append one row to the sheet
- What it can do: read emails whose body contains the invoice details, and append them after review
- What it can't do: read PDF attachments with these steps. What arrives at the trigger is the list of attachments, not the file contents
- What it can't do: guarantee the extraction is correct. Because it handles amounts, we recommend you keep the review step
What it can and can't do
Extraction makes mistakes. In emails where similar numbers sit side by side, such as amounts with and without tax, or the invoice amount and the balance carried over from last month, it can mix them up. That's why a review step by a person comes before the append.
Instructions in an email can't make it act on its own. "Generate with AI" is a step with no tools that answers once. Even if the body contains something that reads like an instruction, it can't operate on email or sheets.
Invoices that arrive as PDFs are outside the scope of these steps. We haven't run them end to end with a real account, so they aren't in the steps. For Excel or CSV attachments, there is a separate path: "Ledger (add rows)" under "File processing".
Use RAW. There are two options for valueInputOption when appending to a sheet. RAW keeps the value exactly as entered, while USER_ENTERED interprets it as if typed on screen, so text can turn into numbers or dates.
There is no feature for recognizing the same email. Appending just adds to the end. If the same invoice is sent again, two rows go in, so make sure you can check by the invoice number column.
What you need
- A Gmail account and a Google Sheets sheet with headers in row 1
- Gmail and Google Sheets connected under "Connectors" in Samurai App
- Permission to add service integrations to a workflow (Manager or higher)
Steps
1. Prepare the sheet and connections
Create the headers Vendor Invoice number Invoice date Due date Total amount in the spreadsheet. The part of the URL between /d/ and /edit is the spreadsheetId.
On the "Connectors" screen, "Add" Gmail and Google Sheets and connect them with your own account. Adding connectors is done by admins and managers.
2. Extract values from the body
Create a workflow with "New", and add a field named event of the type "Group of fields" under "Workflow inputs".
Add "Generate with AI" from "Think", and write the following in "Instructions".
The following email is an invoice notice. Extract only the values written in the body.
Leave any field not in the body as an empty string, and do not fill it in by guessing.
{{input.event.message_text}}
Under "Output fields", add vendor (vendor), invoice_no (invoice number), invoice_date (invoice date), due_date (payment due date), and total (total amount), all of type text and marked "Required".
3. Add a step for a person to review
Add "Wait for approval or input" from "Stop and wait". In "Message", lay out the values from step 2 using "/" or "Variables", and include the subject too so the reviewer can compare against the email.
This step arrives as a pending approval in the "Inbox" of the person who started the run. For a run started by a trigger, that's the person who created the trigger. To assign someone else, pick up to 5 people under "Approvers", and they get the request by email.
- If the values are correct, press "Approve". The run moves on to the next step
- If they're wrong, press "Reject". The run stops there and nothing goes into the sheet. Enter the correct values in the sheet by hand
By default it waits up to 7 days, and the run fails after that.
4. Add a step that appends to the sheet
Add "Run external service" from "Connect" and choose GOOGLESHEETS_SPREADSHEETS_VALUES_APPEND.
| Name | Value |
|---|---|
spreadsheetId |
The ID from step 1 |
range |
The sheet name and column range, like Sheet1!A:E |
valueInputOption |
RAW |
values |
The 5 values from step 2 |
values is a two-dimensional array: the outer level is rows and the inner level is columns. Create one row and pick the values with "/" in the order of the headers.
This step is a write that runs in an unattended run. By default it runs without showing an approval card and is recorded in the approval log. If an admin has set this operation to "Confirm every time" or "Forbid", it is refused.
5. Publish and add the trigger
"Save", then press "Publish version N" on the "Versions" tab. On the "Triggers" tab, use "Add service integration" to choose the Gmail connection, and under "When to run" choose "New Gmail Message Received Trigger". In the query under "Filter", enter a condition that matches only invoice emails.
from:billing@example.com subject:invoice
Without a filter, an AI extraction and a review request happen for every email you receive, and each one costs about ¥0.5. Gmail triggers can be delayed by up to 15 minutes.
When it doesn't work
- All values arrive empty: The invoice details are in a PDF, not in the body. In this case, "Reject" and enter them by hand. If this keeps happening with the same sender, this path isn't a good fit
- It fails saying
message_textis missing: The email arrived without the body field. All fields that arrive are treated as optional, so check the input in "Recent runs" - The append step fails: Check the sheet name in
rangeand thespreadsheetId, fix them, and publish again. Enter the failed ones in the sheet by hand. If it was a temporary failure rather than a configuration mistake, "Retry from the failed step" on the run screen continues without repeating the extraction and review - It fails because nobody noticed the review request: Runs that exceed 7 days fail. Decide who is responsible and set them under "Approvers"
FAQ
Can I remove the review step and make it fully automatic?
It will run if you remove the step, but misreads go straight into the sheet. For sheets that handle amounts, we recommend keeping it.
Can it go as far as journal entries or registering in accounting software?
What this article covers stops at appending to the sheet.
What if different kinds of emails are mixed in?
Put "Classify into categories" from "Flow" before "Generate with AI" to split invoices from everything else. If you connect nothing to "Other", those emails don't go into the sheet.
Related guides
- Have AI draft replies to inquiry emails
- Send new Gmail messages to Slack
- Post Gmail notifications to Chatwork