{ "kind": "open-flow-workflow", "version": 1, "name": "Sync HubSpot Companies to Zendesk", "content": { "modelVersion": 14, "document": { "bindings": {}, "graph": { "nodes": { "n_5f4311b1287d50c7": { "name": "Every five minutes", "kind": "cron", "cronTimes": [ { "type": "cron", "expression": "*/5 * * * *", "timezone": "UTC" } ] }, "n_2152ebb8903c084e": { "inputs": {}, "name": "Read the last run time", "kind": "task", "task": { "inputs": [], "outputs": [ { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "since" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "until" } ], "name": "Read the last run time", "moduleId": "n_dba0f008601c4a26", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_9036c2a2278e3509": { "inputs": { "since": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_2152ebb8903c084e", "output": "since" } ] }, "until": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_2152ebb8903c084e", "output": "until" } ] }, "previousState": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_9036c2a2278e3509", "output": "state" } ] }, "response": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_ba660c28a1212866", "output": "body" } ] }, "statusCode": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_ba660c28a1212866", "output": "statusCode" } ] } }, "name": "Collect HubSpot companies", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "since" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "until" }, { "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": "companies" }, { "jsonSchema": { "type": "boolean" }, "nullable": false, "handle": "hasCompanies" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "count" } ], "name": "Collect HubSpot companies", "moduleId": "n_b720064ebcf76cc4", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_c77fe856e8beaf44": { "inputs": {}, "name": "Another company page", "kind": "condition", "matchMode": "first", "cases": [ { "output": "yes", "groups": [ { "expressions": [ { "left": { "kind": "source", "source": { "kind": "node", "nodeId": "n_9036c2a2278e3509", "output": "more" } }, "operator": "==", "right": { "kind": "value", "value": true } } ] } ] } ] }, "n_ba660c28a1212866": { "inputs": { "url": { "kind": "value", "value": "https://api.hubapi.com/crm/v3/objects/companies" }, "query": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_9036c2a2278e3509", "output": "params" } ] }, "auth.token": { "kind": "unset" } }, "name": "List HubSpot companies", "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": "List HubSpot companies", "executor": { "method": "GET", "query": { "mode": "object", "names": [] }, "headers": { "mode": "fields", "names": [] }, "bodyFormat": "none", "authentication": { "type": "bearer" }, "responseFormat": "json", "statusPolicy": "success", "kind": "http-request" } } }, "n_3537fccd0c21e11a": { "inputs": {}, "name": "Any changed companies", "kind": "condition", "matchMode": "first", "cases": [ { "output": "yes", "groups": [ { "expressions": [ { "left": { "kind": "source", "source": { "kind": "node", "nodeId": "n_9036c2a2278e3509", "output": "hasCompanies" } }, "operator": "==", "right": { "kind": "value", "value": true } } ] } ] } ] }, "n_fe46eade733a042f": { "inputs": { "previousState": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_fe46eade733a042f", "output": "state" } ] }, "organizations": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_ca285270943c13f6", "output": "organizations" } ] }, "pagination": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_ca285270943c13f6", "output": "pagination" } ] } }, "name": "Collect Zendesk organizations", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": true, "handle": "previousState" }, { "jsonSchema": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "integer", "exclusiveMinimum": 0, "description": "Zendesk organization identifier." }, "url": { "type": [ "string", "null" ], "description": "API URL of the organization, or null when Zendesk omits it." }, "name": { "type": [ "string", "null" ], "description": "Organization name, or null when Zendesk omits it." }, "externalId": { "type": [ "string", "null" ], "description": "External identifier, or null when Zendesk omits it." }, "details": { "type": [ "string", "null" ], "description": "Organization details, or null when Zendesk omits it." }, "notes": { "type": [ "string", "null" ], "description": "Organization notes, or null when Zendesk omits it." }, "createdAt": { "type": [ "string", "null" ], "description": "Organization creation timestamp, or null when Zendesk omits it." }, "updatedAt": { "type": [ "string", "null" ], "description": "Organization update timestamp, or null when Zendesk omits it." }, "groupId": { "type": [ "integer", "null" ], "description": "Default group identifier, or null when Zendesk omits it." }, "sharedTickets": { "type": [ "boolean", "null" ], "description": "Whether end users can view each other's tickets, or null when omitted." }, "sharedComments": { "type": [ "boolean", "null" ], "description": "Whether end users can comment on shared tickets, or null when omitted." }, "domainNames": { "type": "array", "items": { "type": "string", "description": "Organization domain name." }, "description": "Organization domain names." }, "tags": { "type": "array", "items": { "type": "string", "description": "Tag attached to the organization." }, "description": "Organization tags." }, "raw": { "type": "object", "additionalProperties": { "description": "A record value." }, "description": "Raw Zendesk organization payload." } }, "required": [ "id", "url", "name", "externalId", "details", "notes", "createdAt", "updatedAt", "groupId", "sharedTickets", "sharedComments", "domainNames", "tags", "raw" ], "additionalProperties": false, "description": "Zendesk organization in the current page." }, "description": "Organizations returned by Zendesk." }, "nullable": true, "handle": "organizations" }, { "jsonSchema": { "type": "object", "properties": { "count": { "type": [ "integer", "null" ], "description": "Total count reported by Zendesk, or null when the endpoint does not provide it." }, "hasMore": { "type": "boolean", "description": "Whether Zendesk indicates that more records are available." }, "nextPage": { "type": [ "string", "null" ], "description": "URL for the next Zendesk page, or null when there is no next page." }, "previousPage": { "type": [ "string", "null" ], "description": "URL for the previous Zendesk page, or null when there is no previous page." }, "afterCursor": { "type": [ "string", "null" ], "description": "Cursor for the next page, or null when cursor pagination is not in use." }, "beforeCursor": { "type": [ "string", "null" ], "description": "Cursor for the previous page, or null when cursor pagination is not in use." } }, "required": [ "count", "hasMore", "nextPage", "previousPage", "afterCursor", "beforeCursor" ], "additionalProperties": false, "description": "Pagination metadata for the organization list." }, "nullable": true, "handle": "pagination" } ], "outputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "state" }, { "jsonSchema": { "type": "boolean" }, "nullable": false, "handle": "more" }, { "jsonSchema": { "type": "integer", "minimum": 1 }, "nullable": false, "handle": "page" }, { "jsonSchema": { "type": "array", "items": { "type": "object", "additionalProperties": true } }, "nullable": false, "handle": "items" } ], "name": "Collect Zendesk organizations", "moduleId": "n_f19c9518993d0c1c", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_a9f13d7d27aa1f31": { "inputs": {}, "name": "Another organization page", "kind": "condition", "matchMode": "first", "cases": [ { "output": "yes", "groups": [ { "expressions": [ { "left": { "kind": "source", "source": { "kind": "node", "nodeId": "n_fe46eade733a042f", "output": "more" } }, "operator": "==", "right": { "kind": "value", "value": true } } ] } ] } ] }, "n_ca285270943c13f6": { "inputs": { "page": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_fe46eade733a042f", "output": "page" } ] }, "perPage": { "kind": "value", "value": 100 } }, "name": "List Zendesk organizations", "kind": "task", "task": { "inputs": [ { "description": "Offset pagination page number.", "jsonSchema": { "type": "integer", "minimum": 1, "description": "Offset pagination page number." }, "nullable": true, "handle": "page", "value": null }, { "description": "Maximum number of records to return for offset pagination.", "jsonSchema": { "type": "integer", "minimum": 1, "maximum": 100, "description": "Maximum number of records to return for offset pagination." }, "nullable": true, "handle": "perPage", "value": null } ], "outputs": [ { "description": "Organizations returned by Zendesk.", "jsonSchema": { "type": "array", "items": { "type": "object", "properties": { "id": { "type": "integer", "exclusiveMinimum": 0, "description": "Zendesk organization identifier." }, "url": { "type": [ "string", "null" ], "description": "API URL of the organization, or null when Zendesk omits it." }, "name": { "type": [ "string", "null" ], "description": "Organization name, or null when Zendesk omits it." }, "externalId": { "type": [ "string", "null" ], "description": "External identifier, or null when Zendesk omits it." }, "details": { "type": [ "string", "null" ], "description": "Organization details, or null when Zendesk omits it." }, "notes": { "type": [ "string", "null" ], "description": "Organization notes, or null when Zendesk omits it." }, "createdAt": { "type": [ "string", "null" ], "description": "Organization creation timestamp, or null when Zendesk omits it." }, "updatedAt": { "type": [ "string", "null" ], "description": "Organization update timestamp, or null when Zendesk omits it." }, "groupId": { "type": [ "integer", "null" ], "description": "Default group identifier, or null when Zendesk omits it." }, "sharedTickets": { "type": [ "boolean", "null" ], "description": "Whether end users can view each other's tickets, or null when omitted." }, "sharedComments": { "type": [ "boolean", "null" ], "description": "Whether end users can comment on shared tickets, or null when omitted." }, "domainNames": { "type": "array", "items": { "type": "string", "description": "Organization domain name." }, "description": "Organization domain names." }, "tags": { "type": "array", "items": { "type": "string", "description": "Tag attached to the organization." }, "description": "Organization tags." }, "raw": { "type": "object", "additionalProperties": { "description": "A record value." }, "description": "Raw Zendesk organization payload." } }, "required": [ "id", "url", "name", "externalId", "details", "notes", "createdAt", "updatedAt", "groupId", "sharedTickets", "sharedComments", "domainNames", "tags", "raw" ], "additionalProperties": false, "description": "Zendesk organization in the current page." }, "description": "Organizations returned by Zendesk." }, "nullable": false, "handle": "organizations" }, { "description": "Pagination metadata for the organization list.", "jsonSchema": { "type": "object", "properties": { "count": { "type": [ "integer", "null" ], "description": "Total count reported by Zendesk, or null when the endpoint does not provide it." }, "hasMore": { "type": "boolean", "description": "Whether Zendesk indicates that more records are available." }, "nextPage": { "type": [ "string", "null" ], "description": "URL for the next Zendesk page, or null when there is no next page." }, "previousPage": { "type": [ "string", "null" ], "description": "URL for the previous Zendesk page, or null when there is no previous page." }, "afterCursor": { "type": [ "string", "null" ], "description": "Cursor for the next page, or null when cursor pagination is not in use." }, "beforeCursor": { "type": [ "string", "null" ], "description": "Cursor for the previous page, or null when cursor pagination is not in use." } }, "required": [ "count", "hasMore", "nextPage", "previousPage", "afterCursor", "beforeCursor" ], "additionalProperties": false, "description": "Pagination metadata for the organization list." }, "nullable": false, "handle": "pagination" } ], "name": "List Zendesk organizations", "executor": { "kind": "connector", "action": "zendesk.list_organizations" } } }, "n_aa28ea3e9176079b": { "inputs": { "companies": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_9036c2a2278e3509", "output": "companies" } ] }, "organizations": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_fe46eade733a042f", "output": "items" } ] } }, "name": "Match organizations by name", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "array", "items": { "type": "object", "additionalProperties": true } }, "nullable": false, "handle": "companies" }, { "jsonSchema": { "type": "array", "items": { "type": "object", "additionalProperties": true } }, "nullable": false, "handle": "organizations" } ], "outputs": [ { "jsonSchema": { "type": "array", "items": { "type": "object", "additionalProperties": true } }, "nullable": false, "handle": "plans" } ], "name": "Match organizations by name", "moduleId": "n_0accd36a95dbf13e", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_cdf18403b49551d5": { "inputs": { "plans": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_aa28ea3e9176079b", "output": "plans" } ] }, "previousState": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_cdf18403b49551d5", "output": "state" } ] }, "confirmed": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_fa7992fcaf2dd6c3", "output": "confirmed" } ] } }, "name": "Prepare the next organization", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "array", "items": { "type": "object", "additionalProperties": true } }, "nullable": false, "handle": "plans" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": true, "handle": "previousState" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": true, "handle": "confirmed" } ], "outputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "state" }, { "jsonSchema": { "type": "boolean" }, "nullable": false, "handle": "more" }, { "jsonSchema": { "type": "boolean" }, "nullable": false, "handle": "isCreate" }, { "jsonSchema": { "type": "string" }, "nullable": false, "handle": "endpoint" }, { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": true, "handle": "expectedId" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "count" } ], "name": "Prepare the next organization", "moduleId": "n_d2e7a2c838497e70", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_225585832346a3d7": { "inputs": {}, "name": "Another company", "kind": "condition", "matchMode": "first", "cases": [ { "output": "yes", "groups": [ { "expressions": [ { "left": { "kind": "source", "source": { "kind": "node", "nodeId": "n_cdf18403b49551d5", "output": "more" } }, "operator": "==", "right": { "kind": "value", "value": true } } ] } ] } ] }, "n_732c74c8a6b73122": { "inputs": {}, "name": "Create or update", "kind": "condition", "matchMode": "first", "cases": [ { "output": "create", "groups": [ { "expressions": [ { "left": { "kind": "source", "source": { "kind": "node", "nodeId": "n_cdf18403b49551d5", "output": "isCreate" } }, "operator": "==", "right": { "kind": "value", "value": true } } ] } ] } ] }, "n_861f8de76ae7059f": { "inputs": { "endpoint": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_cdf18403b49551d5", "output": "endpoint" } ] }, "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_cdf18403b49551d5", "output": "body" } ] } }, "name": "Create the Zendesk organization", "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": "Create the Zendesk organization", "executor": { "providerId": "zendesk", "method": "POST", "query": { "mode": "fields", "names": [] }, "headers": { "mode": "fields", "names": [] }, "bodyFormat": "json", "kind": "connector-proxy" } } }, "n_2b2fc0e29b892ac7": { "inputs": { "endpoint": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_cdf18403b49551d5", "output": "endpoint" } ] }, "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_cdf18403b49551d5", "output": "body" } ] } }, "name": "Update the Zendesk organization", "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": "Update the Zendesk organization", "executor": { "providerId": "zendesk", "method": "PUT", "query": { "mode": "fields", "names": [] }, "headers": { "mode": "fields", "names": [] }, "bodyFormat": "json", "kind": "connector-proxy" } } }, "n_fa7992fcaf2dd6c3": { "inputs": { "expectedId": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_cdf18403b49551d5", "output": "expectedId" } ] }, "statusCode": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_861f8de76ae7059f", "output": "statusCode" }, { "kind": "node", "nodeId": "n_2b2fc0e29b892ac7", "output": "statusCode" } ] }, "body": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_861f8de76ae7059f", "output": "body" }, { "kind": "node", "nodeId": "n_2b2fc0e29b892ac7", "output": "body" } ] } }, "name": "Confirm the organization", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "statusCode" }, { "jsonSchema": {}, "nullable": true, "handle": "body" }, { "jsonSchema": { "type": "integer" }, "nullable": true, "handle": "expectedId" } ], "outputs": [ { "jsonSchema": { "type": "object", "additionalProperties": true }, "nullable": false, "handle": "confirmed" } ], "name": "Confirm the organization", "moduleId": "n_ff53d7d1e0f84015", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_69717032eb8bce5a": { "inputs": { "count": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_cdf18403b49551d5", "output": "count" } ] }, "until": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_2152ebb8903c084e", "output": "until" } ] } }, "name": "Save the completed run", "kind": "task", "task": { "inputs": [ { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "count" }, { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "until" } ], "outputs": [ { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "count" } ], "name": "Save the completed run", "moduleId": "n_b65c79158693fb7f", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_d5f6bd152429e13c": { "inputs": {}, "name": "No changed companies", "kind": "task", "task": { "inputs": [], "outputs": [ { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "count" } ], "name": "No changed companies", "moduleId": "n_7300c4c5edc856e5", "capabilities": [ { "kind": "connector", "mode": "independent", "actions": [] } ] } }, "n_35d9a610d5a7e1e6": { "name": "Number of organizations", "kind": "outputs", "outputDefs": [ { "jsonSchema": { "type": "integer" }, "nullable": false, "handle": "count" } ], "outputMappings": { "count": { "kind": "sources", "sources": [ { "kind": "node", "nodeId": "n_69717032eb8bce5a", "output": "count" }, { "kind": "node", "nodeId": "n_d5f6bd152429e13c", "output": "count" } ] } } } }, "edges": [ { "source": "n_5f4311b1287d50c7", "target": "n_2152ebb8903c084e" }, { "source": "n_2152ebb8903c084e", "target": "n_9036c2a2278e3509" }, { "source": "n_9036c2a2278e3509", "target": "n_c77fe856e8beaf44" }, { "source": "n_c77fe856e8beaf44", "target": "n_ba660c28a1212866", "sourceHandle": "yes" }, { "source": "n_ba660c28a1212866", "target": "n_9036c2a2278e3509" }, { "source": "n_c77fe856e8beaf44", "target": "n_3537fccd0c21e11a", "sourceHandle": "otherwise" }, { "source": "n_3537fccd0c21e11a", "target": "n_fe46eade733a042f", "sourceHandle": "yes" }, { "source": "n_3537fccd0c21e11a", "target": "n_d5f6bd152429e13c", "sourceHandle": "otherwise" }, { "source": "n_d5f6bd152429e13c", "target": "n_35d9a610d5a7e1e6" }, { "source": "n_fe46eade733a042f", "target": "n_a9f13d7d27aa1f31" }, { "source": "n_a9f13d7d27aa1f31", "target": "n_ca285270943c13f6", "sourceHandle": "yes" }, { "source": "n_ca285270943c13f6", "target": "n_fe46eade733a042f" }, { "source": "n_a9f13d7d27aa1f31", "target": "n_aa28ea3e9176079b", "sourceHandle": "otherwise" }, { "source": "n_aa28ea3e9176079b", "target": "n_cdf18403b49551d5" }, { "source": "n_cdf18403b49551d5", "target": "n_225585832346a3d7" }, { "source": "n_225585832346a3d7", "target": "n_732c74c8a6b73122", "sourceHandle": "yes" }, { "source": "n_732c74c8a6b73122", "target": "n_861f8de76ae7059f", "sourceHandle": "create" }, { "source": "n_732c74c8a6b73122", "target": "n_2b2fc0e29b892ac7", "sourceHandle": "otherwise" }, { "source": "n_861f8de76ae7059f", "target": "n_fa7992fcaf2dd6c3" }, { "source": "n_2b2fc0e29b892ac7", "target": "n_fa7992fcaf2dd6c3" }, { "source": "n_fa7992fcaf2dd6c3", "target": "n_cdf18403b49551d5" }, { "source": "n_225585832346a3d7", "target": "n_69717032eb8bce5a", "sourceHandle": "otherwise" }, { "source": "n_69717032eb8bce5a", "target": "n_35d9a610d5a7e1e6" } ] } }, "modules": { "n_dba0f008601c4a26": { "name": "Read the last run time", "imports": [], "source": "export default async function window(_input,context){const until=Date.now(),saved=await context.state.get('last-company-run');let since=saved;if(since==null){since=until;await context.state.set('last-company-run',since)}if(!Number.isSafeInteger(since)||since<0||since>until)throw Error('Invalid company watermark');return {since,until}}\n" }, "n_b720064ebcf76cc4": { "name": "Collect HubSpot companies", "imports": [], "source": "export default function pages({since,until,previousState,response,statusCode}){let state=previousState??{companies:[],seen:[],cursor:null};if(!Array.isArray(state.companies)||!Array.isArray(state.seen))throw Error('Invalid company progress');if(response!=null){if(statusCode<200||statusCode>=300||!response||!Array.isArray(response.results))throw Error('Invalid HubSpot list');let companies=state.companies;for(const c of response.results){if(!c||typeof c.id!=='string'||!c.properties||typeof c.updatedAt!=='string')throw Error('Invalid HubSpot company');const t=Date.parse(c.updatedAt);if(!Number.isFinite(t))throw Error('Invalid company timestamp');if(t>=since&&t0,count:0}}\n" }, "n_f19c9518993d0c1c": { "name": "Collect Zendesk organizations", "imports": [], "source": "export default function pages({previousState,organizations,pagination}){let s=previousState??{items:[],page:1};if(!Array.isArray(s.items)||!Number.isInteger(s.page)||s.page<1)throw Error('Invalid organization progress');if(organizations!=null){if(!Array.isArray(organizations)||!pagination||typeof pagination.hasMore!=='boolean')throw Error('Invalid Zendesk page');if(pagination.hasMore&&s.page>=100)throw Error('Zendesk offset pagination exceeds 100 pages');s={items:s.items.concat(organizations),page:pagination.hasMore?s.page+1:0}}return {state:s,more:organizations==null||s.page>0,page:s.page||1,items:s.items}}\n" }, "n_0accd36a95dbf13e": { "name": "Match organizations by name", "imports": [], "source": "export default function plan({companies,organizations}){if(!Array.isArray(companies)||!Array.isArray(organizations))throw Error('Invalid records');const names=new Map();for(const o of organizations){if(!o||!Number.isSafeInteger(o.id)||typeof o.name!=='string')throw Error('Invalid Zendesk organization');let k=o.name.toLowerCase();names.set(k,[...(names.get(k)||[]),o])}const seen=new Set(),plans=[];for(const c of companies){const name=c.properties?.name,domain=c.properties?.domain;if(typeof name!=='string'||!name.trim()||typeof domain!=='string'||!domain.trim())throw Error('Company name or domain missing');let k=name.toLowerCase();if(seen.has(k))throw Error('Duplicate HubSpot company names');seen.add(k);const matches=names.get(k)||[];if(matches.length>1)throw Error('Duplicate Zendesk organization names');plans.push({id:matches[0]?.id??null,name,domain})}return {plans}}\n" }, "n_d2e7a2c838497e70": { "name": "Prepare the next organization", "imports": [], "source": "export default function next({plans,previousState,confirmed}){if(!Array.isArray(plans))throw Error('Invalid company plans');let index=0;if(previousState!=null){if(!Number.isInteger(previousState.index)||!confirmed||confirmed.ok!==true)throw Error('Organization write not confirmed');index=previousState.index}if(index>=plans.length)return {state:{index},more:false,isCreate:true,endpoint:'/api/v2/organizations.json',body:{},expectedId:null,count:index};const p=plans[index];return {state:{index:index+1},more:true,isCreate:p.id===null,endpoint:p.id===null?'/api/v2/organizations.json':'/api/v2/organizations/'+p.id+'.json',body:{organization:{name:p.name,domain_names:[p.domain]}},expectedId:p.id,count:index}}\n" }, "n_ff53d7d1e0f84015": { "name": "Confirm the organization", "imports": [], "source": "export default function confirm({statusCode,body,expectedId}){if(statusCode<200||statusCode>=300||!body||!body.organization||!Number.isSafeInteger(body.organization.id))throw Error('Zendesk did not confirm organization');if(expectedId!==null&&body.organization.id!==expectedId)throw Error('Zendesk confirmed a different organization');return {confirmed:{ok:true}}}\n" }, "n_b65c79158693fb7f": { "name": "Save the completed run", "imports": [], "source": "export default async function finish({count,until},context){if(!Number.isSafeInteger(count)||!Number.isSafeInteger(until))throw Error('Invalid run completion');if(count>0)await context.state.set('last-company-run',until);return {count}}\n" }, "n_7300c4c5edc856e5": { "name": "No changed companies", "imports": [], "source": "export default function(){return {count:0}}" } } }, "presentation": { "designer": { "version": 1, "flow": { "direction": "vertical" } } } }