{ "kind": "open-flow-workflow", "version": 1, "name": "Create, Update, and Read a Firestore Document", "content": { "modelVersion": 14, "document": { "bindings": {}, "graph": { "nodes": { "n_abe6a0e5cac8de2d": { "name": "Enter Firestore location", "kind": "start", "inputDefs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "project" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "collection" } ] }, "n_b584ed462aec87c2": { "inputs": { "project": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_abe6a0e5cac8de2d", "output": "project" } ] }, "collection": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_abe6a0e5cac8de2d", "output": "collection" } ] } }, "name": "Prepare the document", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "project" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "collection" } ], "outputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "body" } ], "name": "Prepare the document", "moduleId": "n_e2a6e50ee52fdceb", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_d7891d5fc05984b8": { "inputs": { "url": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_b584ed462aec87c2", "output": "url" } ] }, "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_b584ed462aec87c2", "output": "body" } ] }, "auth.token": { "kind": "unset" } }, "name": "Create the document", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "auth.token" } ], "outputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" } ], "name": "Create the document", "executor": { "method": "POST", "query": { "mode": "fields", "names": [] }, "headers": { "mode": "fields", "names": [] }, "bodyFormat": "json", "authentication": { "type": "bearer" }, "responseFormat": "json", "statusPolicy": "success", "kind": "http-request" } } }, "n_e4e3583fa4309067": { "inputs": { "project": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_abe6a0e5cac8de2d", "output": "project" } ] }, "collection": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_abe6a0e5cac8de2d", "output": "collection" } ] }, "created": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_d7891d5fc05984b8", "output": "body" } ] } }, "name": "Prepare the update", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "project" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "collection" }, { "jsonSchema": {}, "nullable": true, "handle": "created" } ], "outputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "body" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "doc" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "id" } ], "name": "Prepare the update", "moduleId": "n_ce890186930c7000", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_0cf161819f02625d": { "inputs": { "url": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_e4e3583fa4309067", "output": "url" } ] }, "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_e4e3583fa4309067", "output": "body" } ] }, "auth.token": { "kind": "unset" } }, "name": "Update the document", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "auth.token" } ], "outputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" } ], "name": "Update the document", "executor": { "method": "POST", "query": { "mode": "fields", "names": [] }, "headers": { "mode": "fields", "names": [] }, "bodyFormat": "json", "authentication": { "type": "bearer" }, "responseFormat": "json", "statusPolicy": "success", "kind": "http-request" } } }, "n_b3f1eff85abae322": { "inputs": { "project": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_abe6a0e5cac8de2d", "output": "project" } ] }, "doc": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_e4e3583fa4309067", "output": "doc" } ] }, "result": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_0cf161819f02625d", "output": "body" } ] } }, "name": "Confirm and prepare read", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "project" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "doc" }, { "jsonSchema": {}, "nullable": true, "handle": "result" } ], "outputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "body" } ], "name": "Confirm and prepare read", "moduleId": "n_c78839fc0735130c", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_cc6759a9d0fbaaed": { "inputs": { "url": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_b3f1eff85abae322", "output": "url" } ] }, "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_b3f1eff85abae322", "output": "body" } ] }, "auth.token": { "kind": "unset" } }, "name": "Read the document", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "auth.token" } ], "outputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" } ], "name": "Read the document", "executor": { "method": "POST", "query": { "mode": "fields", "names": [] }, "headers": { "mode": "fields", "names": [] }, "bodyFormat": "json", "authentication": { "type": "bearer" }, "responseFormat": "json", "statusPolicy": "success", "kind": "http-request" } } }, "n_9343710d470b7bb5": { "inputs": { "response": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_cc6759a9d0fbaaed", "output": "body" } ] } }, "name": "Return the document", "kind": "task", "task": { "inputs": [ { "jsonSchema": {}, "nullable": true, "handle": "response" } ], "outputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "document" } ], "name": "Return the document", "moduleId": "n_cc20b876ba0cdfb4", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_e4a29107a49683e3": { "name": "Document", "kind": "outputs", "outputDefs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "document" } ], "outputMappings": { "document": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_9343710d470b7bb5", "output": "document" } ] } } } }, "edges": [ { "source": "n_abe6a0e5cac8de2d", "target": "n_b584ed462aec87c2" }, { "source": "n_b584ed462aec87c2", "target": "n_d7891d5fc05984b8" }, { "source": "n_d7891d5fc05984b8", "target": "n_e4e3583fa4309067" }, { "source": "n_e4e3583fa4309067", "target": "n_0cf161819f02625d" }, { "source": "n_0cf161819f02625d", "target": "n_b3f1eff85abae322" }, { "source": "n_b3f1eff85abae322", "target": "n_cc6759a9d0fbaaed" }, { "source": "n_cc6759a9d0fbaaed", "target": "n_9343710d470b7bb5" }, { "source": "n_9343710d470b7bb5", "target": "n_e4a29107a49683e3" } ] } }, "modules": { "n_e2a6e50ee52fdceb": { "name": "Prepare the document", "imports": [], "source": "export default function prepare({project,collection}){if(!/^[a-z][a-z0-9-]{4,28}[a-z0-9]$/.test(project)||!collection||collection.includes('/'))throw Error('Enter a valid project ID and a single collection ID');return{url:`https://firestore.googleapis.com/v1/projects/${encodeURIComponent(project)}/databases/(default)/documents/${encodeURIComponent(collection)}`,body:{fields:{id:{integerValue:1},name:{stringValue:'n8n'}}}}}\n" }, "n_ce890186930c7000": { "name": "Prepare the update", "imports": [], "source": "export default function prepare({project,collection,created}){const prefix=`projects/${project}/databases/(default)/documents/${collection}/`;if(typeof created.name!=='string'||!created.name.startsWith(prefix)||!created.name.slice(prefix.length)||created.name.slice(prefix.length).includes('/'))throw Error('Create response lacks a matching document name; inspect Firestore before retrying');return{doc:created.name,id:created.name.slice(prefix.length),url:`https://firestore.googleapis.com/v1/projects/${encodeURIComponent(project)}/databases/(default)/documents:batchWrite`,body:{writes:[{update:{name:created.name,fields:{name:{stringValue:'nodemation'}}},updateMask:{fieldPaths:['name']}}]}}}\n" }, "n_c78839fc0735130c": { "name": "Confirm and prepare read", "imports": [], "source": "export default function prepare({project,doc,result}){if(!Array.isArray(result.status)||result.status.length!==1||!result.status[0]||typeof result.status[0]!=='object'||(result.status[0].code??0)!==0||!Array.isArray(result.writeResults)||result.writeResults.length!==1)throw Error('Update did not return a confirmed successful write; inspect Firestore before retrying');return{url:`https://firestore.googleapis.com/v1/projects/${encodeURIComponent(project)}/databases/(default)/documents:batchGet`,body:{documents:[doc]}}}\n" }, "n_cc20b876ba0cdfb4": { "name": "Return the document", "imports": [], "source": "export default function result({response}){if(!Array.isArray(response)||response.length!==1||!response[0].found)throw Error('Created document was not returned');const d=response[0].found;return{document:{_name:d.name,_id:d.name.split('/').pop(),_createTime:d.createTime,_updateTime:d.updateTime,id:d.fields?.id?.integerValue,name:d.fields?.name?.stringValue}}}\n" } } }, "presentation": { "designer": { "version": 1, "flow": { "direction": "vertical" } } } }