{
  "schema_version": "1.0.0",
  "id": "invoice-email-to-quickbooks-bill",
  "title": "Draft a QuickBooks bill from an invoice email",
  "category": "invoices-docs",
  "difficulty": "intermediate",
  "featured": true,
  "description": "Match the sender to a QuickBooks vendor and create the bill only when the vendor exists and the total parsed cleanly.",
  "tags": [
    "invoices",
    "quickbooks",
    "gmail",
    "accounts-payable",
    "ai-extraction"
  ],
  "apps": [
    "Gmail",
    "AI by Zapier",
    "Code by Zapier",
    "QuickBooks Online",
    "Filter by Zapier"
  ],
  "plan": {
    "minimum": "Professional",
    "reasons": [
      "multi-step Zap: 6 steps after the trigger",
      "Filter by Zapier",
      "AI by Zapier",
      "premium app: QuickBooks Online"
    ]
  },
  "tasks": {
    "typical": 5,
    "max": 5
  },
  "trigger": {
    "app": "Gmail",
    "event": "New Labeled Email",
    "kind": "polling",
    "title": "New email under Invoices/QuickBooks",
    "why": "Fires for each email under the Invoices/QuickBooks label.",
    "config": {
      "Label": "Invoices/QuickBooks"
    },
    "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": "Same extraction prompt as the other invoice templates.",
      "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": "Gives QuickBooks a plain decimal amount and flags anything ambiguous.",
      "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": "vendor",
      "kind": "search",
      "app": "QuickBooks Online",
      "event": "Find Vendor",
      "title": "Find the vendor in QuickBooks",
      "why": "Searches by display name. The Zap never creates vendors, so an unknown sender cannot add a near-duplicate vendor record.",
      "fields": {
        "Display Name": "{{extract.vendor}}",
        "Should this step be considered a \"success\" when nothing is found?": "Yes"
      },
      "outputs": [
        "id",
        "display_name",
        "_zap_search_was_found_status"
      ]
    },
    {
      "key": "safe",
      "kind": "filter",
      "app": "Filter by Zapier",
      "event": "Only continue if...",
      "title": "Only known vendors with a clean amount",
      "why": "Unknown vendors and ambiguous totals stop here and stay under the label for a person.",
      "conditions": [
        [
          {
            "field": "{{vendor._zap_search_was_found_status}}",
            "operator": "(Boolean) Is true"
          },
          {
            "field": "{{money.needs_review}}",
            "operator": "(Boolean) Is false"
          },
          {
            "field": "{{extract.text_found}}",
            "operator": "(Text) Exactly matches",
            "value": "yes"
          }
        ]
      ],
      "usually": true
    },
    {
      "key": "bill",
      "kind": "action",
      "app": "QuickBooks Online",
      "event": "Create Bill",
      "title": "Create the bill",
      "why": "Creates the bill against the vendor id found above, with one expense line for the total.",
      "fields": {
        "Vendor": "{{vendor.id}}",
        "Bill Date": "{{extract.invoice_date}}",
        "Due Date": "{{extract.due_date}}",
        "Ref Number": "{{extract.invoice_number}}",
        "Line Item: Account": "YOUR_EXPENSE_ACCOUNT",
        "Line Item: Amount": "{{money.amount_fixed}}",
        "Line Item: Description": "{{extract.line_summary}}",
        "Memo": "From email: {{trigger.subject}}"
      },
      "outputs": [
        "id",
        "doc_number"
      ]
    },
    {
      "key": "file",
      "kind": "action",
      "app": "Gmail",
      "event": "Add Label to Email",
      "title": "File the email as billed",
      "why": "Moves the email to Invoices/Billed so the working label only holds invoices still to handle.",
      "fields": {
        "Message": "{{trigger.message_id}}",
        "Labels": "Invoices/Billed"
      },
      "outputs": [
        "id"
      ]
    }
  ]
}
