{
 "id": "receipttosheet",
 "name": "AutomateRecipes \u2013 receipt-to-sheet",
 "nodes": [
  {
   "parameters": {},
   "name": "Manual Trigger",
   "type": "n8n-nodes-base.manualTrigger",
   "typeVersion": 1,
   "position": [
    0,
    0
   ],
   "id": "17e533e2-9133-4ed9-a87f-2e00ac073ad5"
  },
  {
   "parameters": {
    "jsCode": "return [{json:{messageId:'r1',attachment:'receipt.jpg'}}];"
   },
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "name": "S1",
   "position": [
    220,
    0
   ],
   "id": "904b6637-eb40-46de-b74b-9215ef005a2c"
  },
  {
   "parameters": {
    "jsCode": "return $input.all().map(i=>({json:{...i.json,service:'openai/v1/chat/completions',payload:{model:'gpt-4o-mini',messages:[{role:'user',content:'Extract receipt vendor, date, total as JSON from '+i.json.attachment}]}}}));"
   },
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "name": "AIPREP",
   "position": [
    440,
    0
   ],
   "id": "48ed4917-9f39-46c1-939e-b70eb00b5ff5"
  },
  {
   "parameters": {
    "method": "POST",
    "url": "=http://127.0.0.1:9000/{{ $json.service }}",
    "sendBody": true,
    "specifyBody": "json",
    "jsonBody": "={{ JSON.stringify($json.payload) }}",
    "options": {}
   },
   "type": "n8n-nodes-base.httpRequest",
   "typeVersion": 4.2,
   "name": "S3 POST mock (AI)",
   "position": [
    660,
    0
   ],
   "id": "783cc1a6-b510-44f0-928e-50d057f3f23f"
  },
  {
   "parameters": {
    "jsCode": "const src=$('AIPREP').all();return $input.all().map((r,i)=>({json:{...src[i].json,ai:r.json.choices[0].message.content}}));"
   },
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "name": "S4",
   "position": [
    880,
    0
   ],
   "id": "03e2f00e-c694-4ffe-9574-13b40f649ebd"
  },
  {
   "parameters": {
    "jsCode": "return $input.all().map(i=>{const d=JSON.parse(i.json.ai.replace('[mock AI] ',''));if(d.total!==149.5)throw new Error('bad total');return {json:{service:'sheets/append',payload:d}}});"
   },
   "type": "n8n-nodes-base.code",
   "typeVersion": 2,
   "name": "S5",
   "position": [
    1100,
    0
   ],
   "id": "25da4158-7899-4ed4-a539-f3015f973947"
  },
  {
   "parameters": {
    "method": "POST",
    "url": "=http://127.0.0.1:9000/{{ $json.service }}",
    "sendBody": true,
    "specifyBody": "json",
    "jsonBody": "={{ JSON.stringify($json.payload) }}",
    "options": {}
   },
   "type": "n8n-nodes-base.httpRequest",
   "typeVersion": 4.2,
   "name": "S6 POST mock (send)",
   "position": [
    1320,
    0
   ],
   "id": "74fdb80f-4de4-4478-bd04-e7c4862da522"
  }
 ],
 "connections": {
  "Manual Trigger": {
   "main": [
    [
     {
      "node": "S1",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "S1": {
   "main": [
    [
     {
      "node": "AIPREP",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "AIPREP": {
   "main": [
    [
     {
      "node": "S3 POST mock (AI)",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "S3 POST mock (AI)": {
   "main": [
    [
     {
      "node": "S4",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "S4": {
   "main": [
    [
     {
      "node": "S5",
      "type": "main",
      "index": 0
     }
    ]
   ]
  },
  "S5": {
   "main": [
    [
     {
      "node": "S6 POST mock (send)",
      "type": "main",
      "index": 0
     }
    ]
   ]
  }
 },
 "settings": {},
 "active": false,
 "pinData": {},
 "meta": {
  "note": "Tested on n8n 1.70.3 with local mocks for: Gmail attachment trigger, OpenAI vision (text prompt mocked), Google Sheets. Replace 'POST mock'/'GET mock' HTTP nodes with the real app nodes + credentials before production."
 }
}