{
  "name": "FlowPantry - receipt-capture-expense-log",
  "flow": [
    {
      "id": 1,
      "module": "gateway:CustomWebHook",
      "version": 1,
      "parameters": {
        "hook": null,
        "maxResults": 1
      },
      "mapper": {},
      "metadata": {
        "designer": {
          "x": 0,
          "y": 0
        }
      }
    },
    {
      "id": 2,
      "module": "http:ActionSendData",
      "version": 3,
      "parameters": {},
      "mapper": {
        "url": "https://api.openai.com/v1/chat/completions",
        "method": "post",
        "headers": [
          {
            "name": "Authorization",
            "value": "Bearer YOUR_OPENAI_API_KEY"
          }
        ],
        "qs": [],
        "serializeUrl": false,
        "parseResponse": true,
        "shareCookies": false,
        "rejectUnauthorized": true,
        "followRedirect": true,
        "useQuerystring": false,
        "gzip": true,
        "useMtls": false,
        "timeout": "",
        "bodyType": "raw",
        "contentType": "application/json",
        "inputMethod": "jsonString",
        "data": "{\"model\": \"gpt-4o-mini\", \"temperature\": 0, \"response_format\": {\"type\": \"json_object\"}, \"messages\": [{\"role\": \"system\", \"content\": \"You read receipts for YOUR BUSINESS. Extract only what is printed; use null for anything missing or unreadable. Reply ONLY with JSON: {\\\"is_receipt\\\":true/false,\\\"vendor\\\":\\\"\\\",\\\"date\\\":\\\"YYYY-MM-DD\\\",\\\"description\\\":\\\"under 12 words\\\",\\\"subtotal\\\":n|null,\\\"tax\\\":n|null,\\\"tip\\\":n|null,\\\"total\\\":n|null,\\\"currency\\\":\\\"USD\\\",\\\"card_last4\\\":\\\"\\\",\\\"category\\\":\\\"one of the list or Uncategorized\\\",\\\"confidence\\\":0-1}. Categories: Advertising, Car and truck, Fuel, Meals, Travel, Supplies, Materials, Tools and equipment, Office expenses, Software and subscriptions, Repairs and maintenance, Rent or lease, Utilities, Phone and internet, Insurance, Contract labor, Legal and professional, Taxes and licenses, Bank and card fees, Other.\"}, {\"role\": \"user\", \"content\": [{\"type\": \"text\", \"text\": \"Email from: {{1.from}}\\nSubject: {{1.subject}}\\nFile: {{1.file_name}}\"}, {\"type\": \"image_url\", \"image_url\": {\"url\": \"{{1.file_url}}\"}}]}]}"
      },
      "metadata": {
        "designer": {
          "x": 300,
          "y": 0
        }
      }
    },
    {
      "id": 3,
      "module": "json:ParseJSON",
      "version": 1,
      "parameters": {
        "type": ""
      },
      "mapper": {
        "json": "{{2.data.choices[].message.content}}"
      },
      "metadata": {
        "designer": {
          "x": 600,
          "y": 0
        }
      }
    },
    {
      "id": 4,
      "module": "builtin:BasicRouter",
      "version": 1,
      "parameters": {},
      "metadata": {
        "designer": {
          "x": 900,
          "y": 0
        }
      },
      "routes": [
        {
          "flow": [
            {
              "id": 5,
              "module": "http:ActionSendData",
              "version": 3,
              "parameters": {},
              "mapper": {
                "url": "SHEET_WEBHOOK_URL",
                "method": "post",
                "headers": [],
                "qs": [],
                "serializeUrl": false,
                "parseResponse": true,
                "shareCookies": false,
                "rejectUnauthorized": true,
                "followRedirect": true,
                "useQuerystring": false,
                "gzip": true,
                "useMtls": false,
                "timeout": "",
                "bodyType": "raw",
                "contentType": "application/json",
                "inputMethod": "jsonString",
                "data": "{\"logged_at\": \"{{now}}\", \"receipt_date\": \"{{3.date}}\", \"vendor\": \"{{3.vendor}}\", \"description\": \"{{3.description}}\", \"category_ai\": \"{{3.category}}\", \"category_final\": \"{{3.category}}\", \"subtotal\": \"{{3.subtotal}}\", \"tax\": \"{{3.tax}}\", \"tip\": \"{{3.tip}}\", \"total\": \"{{3.total}}\", \"currency\": \"{{3.currency}}\", \"card_last4\": \"{{3.card_last4}}\", \"status\": \"auto\", \"review_notes\": \"\", \"receipt_link\": \"{{1.file_url}}\", \"email_from\": \"{{1.from}}\", \"email_subject\": \"{{1.subject}}\"}"
              },
              "metadata": {
                "designer": {
                  "x": 1200,
                  "y": 0
                }
              },
              "filter": {
                "name": "Looks right",
                "conditions": [
                  [
                    {
                      "a": "{{3.confidence}}",
                      "o": "number:greaterorequal",
                      "b": "0.8"
                    },
                    {
                      "a": "{{3.is_receipt}}",
                      "o": "boolean:true",
                      "b": ""
                    },
                    {
                      "a": "{{3.total}}",
                      "o": "exist",
                      "b": ""
                    },
                    {
                      "a": "{{3.vendor}}",
                      "o": "exist",
                      "b": ""
                    },
                    {
                      "a": "{{3.date}}",
                      "o": "exist",
                      "b": ""
                    },
                    {
                      "a": "{{3.category}}",
                      "o": "text:notequal",
                      "b": "Uncategorized"
                    },
                    {
                      "a": "{{3.total}}",
                      "o": "number:lessorequal",
                      "b": "500"
                    }
                  ]
                ]
              }
            }
          ]
        },
        {
          "flow": [
            {
              "id": 6,
              "module": "http:ActionSendData",
              "version": 3,
              "parameters": {},
              "mapper": {
                "url": "SHEET_WEBHOOK_URL",
                "method": "post",
                "headers": [],
                "qs": [],
                "serializeUrl": false,
                "parseResponse": true,
                "shareCookies": false,
                "rejectUnauthorized": true,
                "followRedirect": true,
                "useQuerystring": false,
                "gzip": true,
                "useMtls": false,
                "timeout": "",
                "bodyType": "raw",
                "contentType": "application/json",
                "inputMethod": "jsonString",
                "data": "{\"logged_at\": \"{{now}}\", \"receipt_date\": \"{{3.date}}\", \"vendor\": \"{{3.vendor}}\", \"description\": \"{{3.description}}\", \"category_ai\": \"{{3.category}}\", \"category_final\": \"\", \"subtotal\": \"{{3.subtotal}}\", \"tax\": \"{{3.tax}}\", \"tip\": \"{{3.tip}}\", \"total\": \"{{3.total}}\", \"currency\": \"{{3.currency}}\", \"card_last4\": \"{{3.card_last4}}\", \"status\": \"needs_review\", \"review_notes\": \"AI confidence {{3.confidence}}; check vendor, date, total and category\", \"receipt_link\": \"{{1.file_url}}\", \"email_from\": \"{{1.from}}\", \"email_subject\": \"{{1.subject}}\"}"
              },
              "metadata": {
                "designer": {
                  "x": 1200,
                  "y": 0
                }
              },
              "filter": {
                "name": "Needs a human",
                "conditions": [
                  [
                    {
                      "a": "{{3.confidence}}",
                      "o": "number:less",
                      "b": "0.8"
                    }
                  ],
                  [
                    {
                      "a": "{{3.is_receipt}}",
                      "o": "boolean:false",
                      "b": ""
                    }
                  ],
                  [
                    {
                      "a": "{{3.total}}",
                      "o": "notexist",
                      "b": ""
                    }
                  ],
                  [
                    {
                      "a": "{{3.vendor}}",
                      "o": "notexist",
                      "b": ""
                    }
                  ],
                  [
                    {
                      "a": "{{3.date}}",
                      "o": "notexist",
                      "b": ""
                    }
                  ],
                  [
                    {
                      "a": "{{3.category}}",
                      "o": "text:equal",
                      "b": "Uncategorized"
                    }
                  ],
                  [
                    {
                      "a": "{{3.total}}",
                      "o": "number:greater",
                      "b": "500"
                    }
                  ]
                ]
              }
            },
            {
              "id": 7,
              "module": "http:ActionSendData",
              "version": 3,
              "parameters": {},
              "mapper": {
                "url": "https://api.resend.com/emails",
                "method": "post",
                "headers": [
                  {
                    "name": "Authorization",
                    "value": "Bearer YOUR_RESEND_API_KEY"
                  }
                ],
                "qs": [],
                "serializeUrl": false,
                "parseResponse": true,
                "shareCookies": false,
                "rejectUnauthorized": true,
                "followRedirect": true,
                "useQuerystring": false,
                "gzip": true,
                "useMtls": false,
                "timeout": "",
                "bodyType": "raw",
                "contentType": "application/json",
                "inputMethod": "jsonString",
                "data": "{\"from\": \"Receipts bot <receipts@yourdomain.com>\", \"to\": \"OWNER_EMAIL\", \"subject\": \"Check receipt: {{3.vendor}} {{3.total}}\", \"text\": \"This receipt was logged as needs_review.\\n\\nVendor: {{3.vendor}}\\nDate: {{3.date}}\\nTotal: {{3.total}} {{3.currency}}\\nAI category: {{3.category}}\\nAI confidence: {{3.confidence}}\\n\\nReceipt: {{1.file_url}}\\n\\nFix the row in your expense sheet and set status to reviewed.\"}"
              },
              "metadata": {
                "designer": {
                  "x": 1500,
                  "y": 0
                }
              }
            }
          ]
        }
      ]
    }
  ],
  "metadata": {
    "instant": true,
    "version": 1,
    "scenario": {
      "roundtrips": 1,
      "maxErrors": 3,
      "autoCommit": true,
      "autoCommitTriggerLast": true,
      "sequential": false,
      "slots": null,
      "confidential": false,
      "dataloss": false,
      "dlq": false,
      "freshVariables": false
    },
    "designer": {
      "orphans": []
    },
    "zone": "us1.make.com"
  }
}