{ "kind": "open-flow-workflow", "version": 1, "name": "Capture a PostHog Event from a Webhook", "content": { "modelVersion": 14, "document": { "bindings": {}, "graph": { "nodes": { "n_3c49a6bfcfdd8203": { "name": "Receive an event name", "kind": "webhook", "bodyFields": [], "method": "GET", "options": { "responseStatusCode": 200 } }, "n_09ec1dd774153fd6": { "inputs": { "query": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_3c49a6bfcfdd8203", "output": "query" } ] }, "token": { "kind": "unset" }, "url": { "kind": "value", "value": "https://us.i.posthog.com/i/v0/e/" } }, "name": "Capture the event", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "query" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "token" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" } ], "outputs": [ { "jsonSchema": { "type": "boolean" }, "nullable": false, "handle": "accepted" } ], "name": "Capture the event", "moduleId": "n_565e4ceab7367ba4", "capabilities": [ { "kind": "http", "hosts": [ "us.i.posthog.com" ] } ] } }, "n_ad6b340217d8a998": { "name": "Capture request", "kind": "outputs", "outputDefs": [ { "jsonSchema": { "type": "boolean" }, "nullable": false, "handle": "accepted" } ], "outputMappings": { "accepted": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_09ec1dd774153fd6", "output": "accepted" } ] } } } }, "edges": [ { "source": "n_3c49a6bfcfdd8203", "target": "n_09ec1dd774153fd6" }, { "source": "n_09ec1dd774153fd6", "target": "n_ad6b340217d8a998" } ] } }, "modules": { "n_565e4ceab7367ba4": { "name": "Capture the event", "imports": [], "source": "export default async function capture({query,token,url},context){if(typeof query.event!=='string'||!query.event)throw Error('Expected an event query parameter');const res=await context.fetch(url,{method:'POST',headers:{'Content-Type':'application/json'},body:JSON.stringify({api_key:token,event:query.event,distinct_id:'n8n'})});if(!res.ok)throw Error('PostHog capture failed or outcome is unknown');return{accepted:true}}\n" } } }, "presentation": { "designer": { "version": 1, "flow": { "direction": "vertical" } } } }