{ "kind": "open-flow-workflow", "version": 1, "name": "List HubSpot Contacts with Pagination", "content": { "modelVersion": 14, "document": { "bindings": {}, "graph": { "nodes": { "n_ee026d58848ab0a0": { "name": "List contacts", "kind": "start", "inputDefs": [] }, "n_d2f35310a48887ea": { "inputs": { "previousState": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_d2f35310a48887ea", "output": "state" } ] }, "response": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_ad546831b10c7e3d", "output": "body" } ] }, "statusCode": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_ad546831b10c7e3d", "output": "statusCode" } ] } }, "name": "Collect contact pages", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": true, "handle": "previousState" }, { "jsonSchema": {}, "nullable": true, "handle": "response" }, { "jsonSchema": { "type": "integer" }, "nullable": true, "handle": "statusCode" } ], "outputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "state" }, { "jsonSchema": { "type": "boolean" }, "nullable": false, "handle": "more" }, { "jsonSchema": { "type": "object", "additionalProperties": { "anyOf": [ { "type": [ "string", "number", "boolean" ] }, { "type": "array", "items": { "type": [ "string", "number", "boolean" ] } } ] } }, "nullable": false, "handle": "params" }, { "jsonSchema": { "type": "array", "items": { "type": "object", "additionalProperties": true } }, "nullable": false, "handle": "contacts" } ], "name": "Collect contact pages", "moduleId": "n_9325c91195a10e34", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_7d077122049a5ba3": { "inputs": {}, "name": "Another page?", "kind": "condition", "matchMode": "first", "cases": [ { "output": "yes", "groups": [ { "expressions": [ { "left": { "kind": "source", "source": { "kind": "node", "nodeId": "n_d2f35310a48887ea", "output": "more" } }, "operator": "isTrue" } ] } ] } ] }, "n_ad546831b10c7e3d": { "inputs": { "url": { "kind": "value", "value": "https://api.hubapi.com/crm/v3/objects/contacts" }, "query": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_d2f35310a48887ea", "output": "params" } ] }, "auth.token": { "kind": "unset" } }, "name": "Read contacts", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "url" }, { "jsonSchema": { "type": "object", "additionalProperties": { "anyOf": [ { "type": [ "string", "number", "boolean" ] }, { "type": "array", "items": { "type": [ "string", "number", "boolean" ] } } ] } }, "nullable": true, "handle": "query" }, { "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 contacts", "executor": { "method": "GET", "query": { "mode": "object", "names": [] }, "headers": { "mode": "fields", "names": [] }, "bodyFormat": "none", "authentication": { "type": "bearer" }, "responseFormat": "json", "statusPolicy": "success", "kind": "http-request" } } }, "n_49289e9e3adb2976": { "inputs": {}, "name": "Wait five seconds", "kind": "wait", "inputDefinitions": [], "prompt": "Wait five seconds", "autoContinue": { "kind": "after", "durationMs": 5000 } }, "n_402d308dd11657be": { "name": "Collected contacts", "kind": "outputs", "outputDefs": [ { "jsonSchema": { "type": "array", "items": { "type": "object", "additionalProperties": true } }, "nullable": false, "handle": "contacts" } ], "outputMappings": { "contacts": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_d2f35310a48887ea", "output": "contacts" } ] } } } }, "edges": [ { "source": "n_ee026d58848ab0a0", "target": "n_d2f35310a48887ea" }, { "source": "n_d2f35310a48887ea", "target": "n_7d077122049a5ba3" }, { "source": "n_7d077122049a5ba3", "target": "n_ad546831b10c7e3d", "sourceHandle": "yes" }, { "source": "n_ad546831b10c7e3d", "target": "n_49289e9e3adb2976" }, { "source": "n_49289e9e3adb2976", "target": "n_d2f35310a48887ea", "sourceHandle": "continue" }, { "source": "n_7d077122049a5ba3", "target": "n_402d308dd11657be", "sourceHandle": "otherwise" } ] } }, "modules": { "n_9325c91195a10e34": { "name": "Collect contact pages", "imports": [], "source": "export default function pages({previousState,response,statusCode}){let state=previousState??{contacts:[],seen:[],cursor:null};if(!Array.isArray(state.contacts)||!Array.isArray(state.seen))throw Error('Invalid page state');if(response!=null){if(statusCode<200||statusCode>=300||!Array.isArray(response.results))throw Error('Invalid HubSpot page');const p=response.paging;if(p!=null&&(typeof p!=='object'||Array.isArray(p)))throw Error('Invalid paging');const next=p?.next;if(next!=null&&(typeof next!=='object'||typeof next.after!=='string'||!next.after||state.seen.includes(next.after)))throw Error('Invalid or repeated cursor');state={contacts:state.contacts.concat(response.results),seen:next?state.seen.concat(next.after):state.seen,cursor:next?.after??null}}return{state,more:response==null||state.cursor!=null,params:{limit:100,...(state.cursor?{after:state.cursor}:{})},contacts:state.contacts}}\n" } } }, "presentation": { "designer": { "version": 1, "flow": { "direction": "vertical" } } } }