{
  "schema_version": "1.0.0",
  "id": "invoice-email-to-sheet",
  "title": "Extract invoice emails into a Google Sheet",
  "category": "invoices-docs",
  "difficulty": "beginner",
  "featured": true,
  "description": "Read each invoice email under a Gmail label, pull vendor, number, dates, and total, and log a clean row in Google Sheets.",
  "tags": [
    "invoices",
    "gmail",
    "google-sheets",
    "ai-extraction",
    "accounts-payable"
  ],
  "apps": [
    "Gmail",
    "AI by Zapier",
    "Code by Zapier",
    "Google Sheets",
    "Paths by Zapier",
    "Slack"
  ],
  "plan": {
    "minimum": "Professional",
    "reasons": [
      "multi-step Zap: 6 steps after the trigger",
      "Paths by Zapier",
      "AI by Zapier"
    ]
  },
  "tasks": {
    "typical": 4,
    "max": 5
  },
  "trigger": {
    "app": "Gmail",
    "event": "New Labeled Email",
    "kind": "polling",
    "title": "New email under the Invoices label",
    "why": "Fires for each email you (or a Gmail filter) put under the Invoices label. Labelling first keeps newsletters and receipts out of the payables sheet.",
    "config": {
      "Label": "Invoices"
    },
    "outputs": [
      "message_id",
      "thread_id",
      "from_email",
      "from_name",
      "to",
      "subject",
      "date",
      "body_plain",
      "snippet",
      "labels",
      "attachment_count",
      "attachment_names"
    ],
    "sample": "sample-trigger.json"
  },
  "steps": [
    {
      "key": "extract",
      "kind": "ai",
      "app": "AI by Zapier",
      "event": "Analyze and Return Data",
      "title": "Pull the invoice fields",
      "why": "Asks for the fields as named outputs. The prompt forbids guessing and asks whether the figures are actually in the email text, because Gmail gives Zapier the message body, not the text inside a PDF.",
      "fields": {
        "Model": "Default (fast)",
        "Instructions": "You read supplier invoices for an accounts-payable team. From the email below, return: vendor (the company that sent the invoice), invoice_number (exactly as printed), invoice_date and due_date (YYYY-MM-DD, empty if not stated), total_text (the grand total exactly as printed, with its currency symbol or code, for example \"$1,280.00\" or \"1.280,00 EUR\"), currency (ISO code if you can tell, otherwise empty), line_summary (one short line describing what was bought), and text_found (\"yes\" if the email text actually contains the invoice figures, \"no\" if the figures are only inside an attachment you cannot read). Never invent a number. If a value is not in the text, leave it empty.",
        "Input data": "From: {{trigger.from_name}} <{{trigger.from_email}}>\nSubject: {{trigger.subject}}\n\n{{trigger.body_plain}}",
        "Output fields": "vendor, invoice_number, invoice_date, due_date, total_text, currency, line_summary, text_found"
      },
      "outputs": [
        "vendor",
        "invoice_number",
        "invoice_date",
        "due_date",
        "total_text",
        "currency",
        "line_summary",
        "text_found"
      ]
    },
    {
      "key": "money",
      "kind": "code",
      "app": "Code by Zapier",
      "event": "Run JavaScript",
      "title": "Turn the printed total into cents",
      "why": "Parses US, European, and Swiss number formats into an exact amount in cents and flags anything ambiguous, such as \"1,280\" with no decimals.",
      "code": {
        "language": "javascript",
        "module": "parse-money",
        "file": "code/parse-money.js"
      },
      "input_data": {
        "amount_text": "{{extract.total_text}}",
        "currency_hint": "{{extract.currency}}"
      },
      "outputs": [
        "amount",
        "amount_fixed",
        "amount_cents",
        "currency",
        "format",
        "needs_review"
      ]
    },
    {
      "key": "log",
      "kind": "action",
      "app": "Google Sheets",
      "event": "Create Spreadsheet Row",
      "title": "Log the invoice row",
      "why": "Every invoice gets a row, including the ones that need a person, so nothing is silently dropped.",
      "fields": {
        "Drive": "My Google Drive",
        "Spreadsheet": "Payables",
        "Worksheet": "Invoices",
        "Columns": {
          "received_at": "{{trigger.date}}",
          "from_email": "{{trigger.from_email}}",
          "vendor": "{{extract.vendor}}",
          "invoice_number": "{{extract.invoice_number}}",
          "invoice_date": "{{extract.invoice_date}}",
          "due_date": "{{extract.due_date}}",
          "amount": "{{money.amount_fixed}}",
          "currency": "{{money.currency}}",
          "what": "{{extract.line_summary}}",
          "needs_review": "{{money.needs_review}}",
          "text_found": "{{extract.text_found}}",
          "gmail_link": "https://mail.google.com/mail/u/0/#all/{{trigger.message_id}}"
        }
      },
      "outputs": [
        "id",
        "row_number"
      ]
    },
    {
      "key": "route",
      "kind": "paths",
      "app": "Paths by Zapier",
      "event": "Split into paths",
      "title": "Clean row or needs a person",
      "why": "The row exists either way. The paths decide whether the email is filed as logged or flagged for a person to open the PDF.",
      "paths": [
        {
          "name": "Logged",
          "conditions": [
            [
              {
                "field": "{{money.needs_review}}",
                "operator": "(Boolean) Is false"
              },
              {
                "field": "{{extract.text_found}}",
                "operator": "(Text) Exactly matches",
                "value": "yes"
              }
            ]
          ],
          "usually": true,
          "steps": [
            {
              "key": "file",
              "kind": "action",
              "app": "Gmail",
              "event": "Add Label to Email",
              "title": "File the email as logged",
              "why": "Moves the email under Invoices/Logged so the Invoices label only holds work still to do.",
              "fields": {
                "Message": "{{trigger.message_id}}",
                "Labels": "Invoices/Logged"
              },
              "outputs": [
                "id"
              ]
            }
          ]
        },
        {
          "name": "Needs review",
          "conditions": [
            [
              {
                "field": "{{money.needs_review}}",
                "operator": "(Boolean) Is true"
              }
            ],
            [
              {
                "field": "{{extract.text_found}}",
                "operator": "(Text) Does not exactly match",
                "value": "yes"
              }
            ]
          ],
          "usually": false,
          "steps": [
            {
              "key": "ask",
              "kind": "action",
              "app": "Slack",
              "event": "Send Channel Message",
              "title": "Ask a person to check the row",
              "why": "Posts the row number and the reason so a person can open the PDF and fix the amount by hand.",
              "fields": {
                "Channel": "#accounts-payable",
                "Message Text": "Invoice from {{extract.vendor}} needs a look (row {{log.row_number}}). Amount read as \"{{extract.total_text}}\", format {{money.format}}, figures in email text: {{extract.text_found}}. Subject: {{trigger.subject}}",
                "Send as a bot?": "Yes",
                "Bot Name": "Zap alerts",
                "Include a link to this Zap?": "No"
              },
              "outputs": [
                "ts",
                "permalink"
              ]
            }
          ]
        }
      ]
    }
  ]
}
