{ "kind": "open-flow-workflow", "version": 1, "name": "Yesterday’s HubSpot Contacts to Mailchimp", "content": { "modelVersion": 14, "document": { "bindings": {}, "graph": { "nodes": { "n_cee1867d4281010d": { "name": "Daily at 07:00 UTC", "kind": "cron", "cronTimes": [ { "type": "cron", "expression": "0 7 * * *", "timezone": "UTC" } ] }, "n_47353d72861ea0b0": { "inputs": {}, "name": "Calculate yesterday in UTC", "kind": "task", "task": { "inputs": [], "outputs": [ { "jsonSchema": { "type": "array", "items": { "type": "object", "properties": {}, "additionalProperties": true, "description": "HubSpot CRM search filter group." }, "maxItems": 5, "description": "HubSpot filter groups used to narrow the search." }, "nullable": true, "handle": "filterGroups" } ], "name": "Calculate yesterday in UTC", "moduleId": "n_71ee43198c37766e", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_17daf7378db9b7a8": { "inputs": { "filterGroups": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_47353d72861ea0b0", "output": "filterGroups" } ] }, "sorts": { "kind": "value", "value": [ "-createdate" ] }, "properties": { "kind": "value", "value": [ "email", "firstname", "lastname" ] }, "limit": { "kind": "value", "value": 100 } }, "name": "Find yesterday’s contacts", "kind": "task", "task": { "inputs": [ { "description": "Full-text query applied to the HubSpot CRM search.", "jsonSchema": { "type": "string", "description": "Full-text query applied to the HubSpot CRM search." }, "nullable": true, "handle": "query", "value": null }, { "description": "HubSpot filter groups used to narrow the search.", "jsonSchema": { "type": "array", "items": { "type": "object", "properties": {}, "additionalProperties": true, "description": "HubSpot CRM search filter group." }, "maxItems": 5, "description": "HubSpot filter groups used to narrow the search." }, "nullable": true, "handle": "filterGroups", "value": null }, { "description": "HubSpot sort expressions.", "jsonSchema": { "type": "array", "items": { "type": "string", "minLength": 1, "description": "HubSpot sort expression." }, "description": "HubSpot sort expressions." }, "nullable": true, "handle": "sorts", "value": null }, { "description": "Property names to include in the returned record payload.", "jsonSchema": { "type": "array", "items": { "type": "string", "minLength": 1, "description": "HubSpot property name." }, "description": "Property names to include in the returned record payload." }, "nullable": true, "handle": "properties", "value": null }, { "description": "Property names to include with their value history.", "jsonSchema": { "type": "array", "items": { "type": "string", "minLength": 1, "description": "HubSpot property name." }, "description": "Property names to include with their value history." }, "nullable": true, "handle": "propertiesWithHistory", "value": null }, { "description": "Associated object types to include in the response.", "jsonSchema": { "type": "array", "items": { "type": "string", "minLength": 1, "description": "HubSpot associated object type." }, "description": "Associated object types to include in the response." }, "nullable": true, "handle": "associations", "value": null }, { "description": "Maximum number of records to return.", "jsonSchema": { "type": "integer", "minimum": 1, "maximum": 200, "description": "Maximum number of records to return." }, "nullable": true, "handle": "limit", "value": null }, { "description": "Paging cursor returned by a previous search request.", "jsonSchema": { "type": "string", "minLength": 1, "description": "Paging cursor returned by a previous search request." }, "nullable": true, "handle": "after", "value": null } ], "outputs": [ { "description": "Records returned by the search request.", "jsonSchema": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "string", "description": "HubSpot record identifier." }, "archived": { "type": "boolean", "description": "Whether the record is archived." }, "createdAt": { "type": "string", "description": "Timestamp when the record was created." }, "updatedAt": { "type": "string", "description": "Timestamp when the record was last updated." }, "properties": { "type": "object", "additionalProperties": { "description": "Property value." }, "description": "HubSpot properties keyed by property name." }, "propertiesWithHistory": { "type": "object", "additionalProperties": { "description": "Property history payload." }, "description": "HubSpot property histories keyed by property name." }, "associations": { "type": "object", "properties": {}, "additionalProperties": true, "description": "Associations returned by HubSpot when requested." } }, "additionalProperties": true, "description": "HubSpot CRM record returned by the MCP server." }, "description": "Records returned by the search request." }, "nullable": false, "handle": "results" }, { "description": "Paging information returned by HubSpot.", "jsonSchema": { "type": "object", "properties": { "nextAfter": { "type": "string", "description": "Cursor for the next search request when another page is available." } }, "additionalProperties": true, "description": "Paging information returned by HubSpot." }, "nullable": true, "handle": "paging" }, { "description": "Raw MCP response payload.", "jsonSchema": { "description": "Raw MCP response payload." }, "nullable": true, "handle": "raw" } ], "name": "Find yesterday’s contacts", "executor": { "kind": "connector", "action": "hubspot.search_contacts" } } }, "n_46200ca87c4991a1": { "inputs": { "results": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_17daf7378db9b7a8", "output": "results" } ] }, "previousState": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_46200ca87c4991a1", "output": "state" } ] }, "listId": { "kind": "value", "value": "YOUR_MAILCHIMP_AUDIENCE_ID" } }, "name": "Prepare the next contact", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "string", "description": "HubSpot record identifier." }, "archived": { "type": "boolean", "description": "Whether the record is archived." }, "createdAt": { "type": "string", "description": "Timestamp when the record was created." }, "updatedAt": { "type": "string", "description": "Timestamp when the record was last updated." }, "properties": { "type": "object", "additionalProperties": { "description": "Property value." }, "description": "HubSpot properties keyed by property name." }, "propertiesWithHistory": { "type": "object", "additionalProperties": { "description": "Property history payload." }, "description": "HubSpot property histories keyed by property name." }, "associations": { "type": "object", "properties": {}, "additionalProperties": true, "description": "Associations returned by HubSpot when requested." } }, "additionalProperties": true, "description": "HubSpot CRM record returned by the MCP server." }, "description": "Records returned by the search request." }, "nullable": false, "handle": "results" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": true, "handle": "previousState" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "listId" } ], "outputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "state" }, { "jsonSchema": { "type": "boolean" }, "nullable": false, "handle": "more" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "endpoint" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "count" } ], "name": "Prepare the next contact", "moduleId": "n_e3cc71fd054cffc7", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_3bbacd4b342c591c": { "inputs": {}, "name": "More contacts?", "kind": "condition", "matchMode": "first", "cases": [ { "output": "more", "groups": [ { "expressions": [ { "left": { "kind": "source", "source": { "kind": "node", "nodeId": "n_46200ca87c4991a1", "output": "more" } }, "operator": "isTrue" } ] } ] } ] }, "n_a018024e8cf3cffb": { "inputs": { "endpoint": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_46200ca87c4991a1", "output": "endpoint" } ] }, "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_46200ca87c4991a1", "output": "body" } ] } }, "name": "Add the subscriber", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "endpoint" }, { "jsonSchema": {}, "nullable": true, "handle": "body" } ], "outputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "type": "object", "additionalProperties": { "type": "string" } }, "nullable": false, "handle": "headers" }, { "jsonSchema": { "const": "base64" }, "nullable": true, "handle": "bodyEncoding" } ], "name": "Add the subscriber", "executor": { "providerId": "mailchimp", "method": "POST", "query": { "mode": "fields", "names": [] }, "headers": { "mode": "fields", "names": [] }, "bodyFormat": "json", "kind": "connector-proxy" } } }, "n_4b8af2d38f46d6e2": { "inputs": { "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_a018024e8cf3cffb", "output": "body" } ] }, "statusCode": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_a018024e8cf3cffb", "output": "statusCode" } ] }, "bodyEncoding": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_a018024e8cf3cffb", "output": "bodyEncoding" } ] } }, "name": "Check the member response", "kind": "task", "task": { "inputs": [ { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": { "const": "base64" }, "nullable": true, "handle": "bodyEncoding" } ], "outputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "member" } ], "name": "Check the member response", "moduleId": "n_d671842b1a2fa255", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_04ceb23a54eb6986": { "name": "Added subscriber count", "kind": "outputs", "outputDefs": [ { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "count" } ], "outputMappings": { "count": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_46200ca87c4991a1", "output": "count" } ] } } } }, "edges": [ { "source": "n_cee1867d4281010d", "target": "n_47353d72861ea0b0" }, { "source": "n_47353d72861ea0b0", "target": "n_17daf7378db9b7a8" }, { "source": "n_17daf7378db9b7a8", "target": "n_46200ca87c4991a1" }, { "source": "n_46200ca87c4991a1", "target": "n_3bbacd4b342c591c" }, { "source": "n_3bbacd4b342c591c", "target": "n_a018024e8cf3cffb", "sourceHandle": "more" }, { "source": "n_a018024e8cf3cffb", "target": "n_4b8af2d38f46d6e2" }, { "source": "n_4b8af2d38f46d6e2", "target": "n_46200ca87c4991a1" }, { "source": "n_3bbacd4b342c591c", "target": "n_04ceb23a54eb6986", "sourceHandle": "otherwise" } ] } }, "modules": { "n_71ee43198c37766e": { "name": "Calculate yesterday in UTC", "imports": [], "source": "export default function yesterdayWindow() {\n const now=new Date(),today=Date.UTC(now.getUTCFullYear(),now.getUTCMonth(),now.getUTCDate());\n return {filterGroups:[{filters:[{propertyName:'createdate',operator:'GTE',value:String(today-86400000)},{propertyName:'createdate',operator:'LT',value:String(today)}]}]};\n}\n" }, "n_e3cc71fd054cffc7": { "name": "Prepare the next contact", "imports": [], "source": "export default function nextContact({results,previousState,listId}) {\n if(typeof listId!=='string'||!listId.trim()||listId==='YOUR_MAILCHIMP_AUDIENCE_ID')throw new Error('Configure the Mailchimp audience ID');\n const index=previousState?.index??0;\n if(!Array.isArray(results)||results.length>100||!Number.isInteger(index)||index<0||index>results.length)throw new Error('Invalid HubSpot result state');\n if(index===0)for(const r of results){const p=r?.properties;if(typeof p?.email!=='string'||!p.email.trim()||typeof p.firstname!=='string'||typeof p.lastname!=='string')throw new Error('Each HubSpot contact needs email, first name and last name text');}\n if(index===results.length)return {state:{index},more:false,endpoint:'/unused',body:{},count:index};\n const p=results[index].properties;return {state:{index:index+1},more:true,endpoint:'/lists/'+encodeURIComponent(listId)+'/members',body:{email_address:p.email,status:'subscribed',merge_fields:{FNAME:p.firstname,LNAME:p.lastname}},count:index+1};\n}\n" }, "n_d671842b1a2fa255": { "name": "Check the member response", "imports": [], "source": "export default function memberResult({ body, statusCode, bodyEncoding }) {\n if (statusCode !== 200 || bodyEncoding) throw new Error('Mailchimp did not return a completed member result (HTTP ' + statusCode + ')');\n if (!body || typeof body !== 'object' || Array.isArray(body) || typeof body.id !== 'string' || !body.id || typeof body.email_address !== 'string' || typeof body.status !== 'string') throw new Error('Mailchimp returned an unexpected member response');\n return { member: body };\n}\n" } } }, "presentation": { "designer": { "version": 1, "flow": { "direction": "vertical" } } } }