{
  "apiVersion": 63,
  "status": "Active",
  "label": "HubSpot Workflow Action CampaignMember Upsert",
  "description": "Receives a HubSpot workflow action payload and creates or updates one NexusCRM CampaignMember. Merge aliases canonicalize first and finalized durable remote identity is authoritative. A durable miss attempts explicit authored-evidence recovery and re-resolves before materialized HubSpot id compatibility lookup. A new Lead is created, mapped, and assigned durable authorship in one atomic child Flow before outbound sync can observe it. Deleted, suspended, or unresolved recovered owners fail closed; Email never adopts remote identity.",
  "runAtomically": true,
  "start": {
    "locationX": 40,
    "locationY": 0,
    "connector": {
      "targetReference": "InitCounters"
    }
  },
  "variables": [
    {
      "name": "payload",
      "dataType": "Any",
      "isInput": true
    },
    {
      "name": "record",
      "dataType": "Any",
      "isInput": true
    },
    {
      "name": "mappingSourceRecord",
      "dataType": "Any"
    },
    {
      "name": "sourceID",
      "dataType": "String",
      "isInput": true
    },
    {
      "name": "resolvedHubSpotId",
      "dataType": "String"
    },
    {
      "name": "durableAuthorityState",
      "dataType": "String"
    },
    {
      "name": "durableSourceObject",
      "dataType": "String"
    },
    {
      "name": "durableSourceRecordId",
      "dataType": "String"
    },
    {
      "name": "durableOwnerLifecycle",
      "dataType": "String"
    },
    {
      "name": "durableMirrorStatus",
      "dataType": "String"
    },
    {
      "name": "durableOwnerRecoveryDeferred",
      "dataType": "Boolean",
      "isOutput": true
    },
    {
      "name": "durableRecoveryState",
      "dataType": "String"
    },
    {
      "name": "mergeAliasApplied",
      "dataType": "Boolean"
    },
    {
      "name": "campaignMemberId",
      "dataType": "String",
      "isOutput": true
    },
    {
      "name": "leadMatchCount",
      "dataType": "Number"
    },
    {
      "name": "contactMatchCount",
      "dataType": "Number"
    },
    {
      "name": "totalMatchCount",
      "dataType": "Number"
    },
    {
      "name": "matchedLeadId",
      "dataType": "String"
    },
    {
      "name": "matchedContactId",
      "dataType": "String"
    }
  ],
  "recordLookups": [
    {
      "name": "FindCampaign",
      "label": "Find NexusCRM Campaign selected by adapter",
      "locationX": 40,
      "locationY": 240,
      "object": "Campaign",
      "filterLogic": "and",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "payload.campaign_id"
          }
        }
      ],
      "outputReference": "$campaign",
      "getFirstRecordOnly": true,
      "connector": {
        "targetReference": "CheckCampaignFound"
      }
    },
    {
      "name": "FindCampaignMemberStatus",
      "label": "Validate CampaignMember status for Campaign",
      "locationX": 40,
      "locationY": 480,
      "object": "CampaignMemberStatus",
      "filterLogic": "and",
      "filters": [
        {
          "field": "CampaignId",
          "operator": "EqualTo",
          "value": {
            "elementReference": "payload.campaign_id"
          }
        },
        {
          "field": "Label",
          "operator": "EqualTo",
          "value": {
            "elementReference": "payload.status"
          }
        }
      ],
      "outputReference": "$campaignMemberStatus",
      "getFirstRecordOnly": true,
      "connector": {
        "targetReference": "CheckStatusFound"
      }
    },
    {
      "name": "FindLeadsByRemoteId",
      "label": "Find Leads by HubSpot remote id",
      "locationX": 40,
      "locationY": 720,
      "object": "Lead",
      "filterLogic": "and",
      "filters": [
        {
          "field": "HubSpot_Id__c",
          "operator": "EqualTo",
          "value": {
            "elementReference": "resolvedHubSpotId"
          }
        },
        {
          "field": "IsConverted",
          "operator": "NotEqualTo",
          "value": true
        }
      ],
      "outputReference": "$remoteLeads",
      "getFirstRecordOnly": false,
      "connector": {
        "targetReference": "LoopRemoteLeads"
      }
    },
    {
      "name": "FindContactsByRemoteId",
      "label": "Find Contacts by HubSpot remote id",
      "locationX": 400,
      "locationY": 720,
      "object": "Contact",
      "filterLogic": "and",
      "filters": [
        {
          "field": "HubSpot_Id__c",
          "operator": "EqualTo",
          "value": {
            "elementReference": "resolvedHubSpotId"
          }
        }
      ],
      "outputReference": "$remoteContacts",
      "getFirstRecordOnly": false,
      "connector": {
        "targetReference": "LoopRemoteContacts"
      }
    },
    {
      "name": "FindHubSpotContactMergeAlias",
      "label": "Find canonical HubSpot id for a merged-away workflow-action contact id",
      "locationX": 760,
      "locationY": 960,
      "object": "HubSpotContactMergeAlias__c",
      "filterLogic": "and",
      "filters": [
        {
          "field": "LegacyHubSpotId__c",
          "operator": "EqualTo",
          "value": {
            "elementReference": "sourceID"
          }
        }
      ],
      "outputReference": "$hubSpotContactMergeAlias",
      "getFirstRecordOnly": true,
      "assignNullValuesIfNoRecordsFound": true,
      "connector": {
        "targetReference": "ApplyHubSpotMergeAliasOrResolveDurableIdentity"
      }
    },
    {
      "name": "FindLeadsByEmail",
      "label": "Fallback find Leads by email",
      "locationX": 40,
      "locationY": 1200,
      "object": "Lead",
      "filterLogic": "and",
      "filters": [
        {
          "field": "Email",
          "operator": "EqualTo",
          "value": {
            "elementReference": "workflowActionLeadEmail"
          }
        },
        {
          "field": "IsConverted",
          "operator": "NotEqualTo",
          "value": true
        }
      ],
      "outputReference": "$emailLeads",
      "getFirstRecordOnly": false,
      "connector": {
        "targetReference": "LoopEmailLeads"
      }
    },
    {
      "name": "FindContactsByEmail",
      "label": "Fallback find Contacts by email",
      "locationX": 400,
      "locationY": 1200,
      "object": "Contact",
      "filterLogic": "and",
      "filters": [
        {
          "field": "Email",
          "operator": "EqualTo",
          "value": {
            "elementReference": "workflowActionLeadEmail"
          }
        }
      ],
      "outputReference": "$emailContacts",
      "getFirstRecordOnly": false,
      "connector": {
        "targetReference": "LoopEmailContacts"
      }
    },
    {
      "name": "FindExistingLeadCampaignMember",
      "label": "Find existing CampaignMember for Lead",
      "locationX": 40,
      "locationY": 1680,
      "object": "CampaignMember",
      "filterLogic": "and",
      "filters": [
        {
          "field": "CampaignId",
          "operator": "EqualTo",
          "value": {
            "elementReference": "payload.campaign_id"
          }
        },
        {
          "field": "LeadId",
          "operator": "EqualTo",
          "value": {
            "elementReference": "matchedLeadId"
          }
        }
      ],
      "outputReference": "$campaignMember",
      "getFirstRecordOnly": true,
      "connector": {
        "targetReference": "ChooseLeadCreateOrUpdate"
      }
    },
    {
      "name": "FindExistingContactCampaignMember",
      "label": "Find existing CampaignMember for Contact",
      "locationX": 400,
      "locationY": 1680,
      "object": "CampaignMember",
      "filterLogic": "and",
      "filters": [
        {
          "field": "CampaignId",
          "operator": "EqualTo",
          "value": {
            "elementReference": "payload.campaign_id"
          }
        },
        {
          "field": "ContactId",
          "operator": "EqualTo",
          "value": {
            "elementReference": "matchedContactId"
          }
        }
      ],
      "outputReference": "$campaignMember",
      "getFirstRecordOnly": true,
      "connector": {
        "targetReference": "ChooseContactCreateOrUpdate"
      }
    },
    {
      "name": "FindDefaultOwnerBinding",
      "label": "Find default owner User (hardcoded fallback owner)",
      "locationX": 240,
      "locationY": 1080,
      "object": "User",
      "filterLogic": "and",
      "filters": [
        {
          "field": "Email",
          "operator": "EqualTo",
          "value": {
            "stringValue": "admin@example.invalid"
          }
        },
        {
          "field": "IsActive",
          "operator": "EqualTo",
          "value": true
        }
      ],
      "outputReference": "$defaultOwnerUser",
      "getFirstRecordOnly": true,
      "connector": {
        "targetReference": "CheckDefaultOwnerForShell"
      }
    },
    {
      "name": "FindLeadOwnerBinding",
      "label": "Find workflow-action Lead owner binding",
      "locationX": 580,
      "locationY": 1560,
      "object": "HubSpotOwnerBinding__c",
      "filterLogic": "and",
      "filters": [
        {
          "field": "HubSpotOwnerId__c",
          "operator": "EqualTo",
          "value": {
            "elementReference": "workflowActionHubSpotOwnerId"
          }
        },
        {
          "field": "BindingStatus__c",
          "operator": "EqualTo",
          "value": {
            "stringValue": "bound"
          }
        },
        {
          "field": "CRMPrincipalType__c",
          "operator": "EqualTo",
          "value": {
            "stringValue": "User"
          }
        }
      ],
      "outputReference": "$leadOwnerBinding",
      "getFirstRecordOnly": true,
      "connector": {
        "targetReference": "CheckLeadOwnerBinding"
      }
    },
    {
      "name": "FindLeadOwnerBindingDup",
      "label": "Find duplicate workflow-action Lead owner binding",
      "locationX": 580,
      "locationY": 1800,
      "object": "HubSpotOwnerBinding__c",
      "filterLogic": "and",
      "filters": [
        {
          "field": "HubSpotOwnerId__c",
          "operator": "EqualTo",
          "value": {
            "elementReference": "workflowActionHubSpotOwnerId"
          }
        },
        {
          "field": "BindingStatus__c",
          "operator": "EqualTo",
          "value": {
            "stringValue": "bound"
          }
        },
        {
          "field": "CRMPrincipalType__c",
          "operator": "EqualTo",
          "value": {
            "stringValue": "User"
          }
        },
        {
          "field": "Id",
          "operator": "NotEqualTo",
          "value": {
            "elementReference": "$leadOwnerBinding.Id"
          }
        }
      ],
      "outputReference": "$leadOwnerBindingDup",
      "getFirstRecordOnly": true,
      "connector": {
        "targetReference": "CheckLeadOwnerAmbiguous"
      }
    },
    {
      "name": "FindMatchedLeadForSafeRehydrate",
      "label": "Reload matched Lead before safe workflow-action rehydrate",
      "locationX": 40,
      "locationY": 1620,
      "object": "Lead",
      "filterLogic": "and",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "matchedLeadId"
          }
        }
      ],
      "outputReference": "matchedWorkflowActionLead",
      "getFirstRecordOnly": true,
      "connector": {
        "targetReference": "SafeLeadRehydrateNeeded"
      }
    },
    {
      "name": "FindMatchedContactForSafeRehydrate",
      "label": "Reload matched Contact before safe workflow-action rehydrate",
      "locationX": 400,
      "locationY": 1620,
      "object": "Contact",
      "filterLogic": "and",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "matchedContactId"
          }
        }
      ],
      "outputReference": "matchedWorkflowActionContact",
      "getFirstRecordOnly": true,
      "connector": {
        "targetReference": "SafeContactRehydrateNeeded"
      }
    }
  ],
  "decisions": [
    {
      "name": "ChooseLeadCampaignAttributionAfterCreate",
      "label": "Preserve existing Lead first campaign after create",
      "locationX": 40,
      "locationY": 1980,
      "rules": [
        {
          "name": "LeadFirstCampaignMissing",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "matchedWorkflowActionLead.First_Campaign__c",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "PatchLeadCampaignAttributionAfterCreate"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "PatchLeadLastCampaignAfterCreate"
      }
    },
    {
      "name": "ChooseContactCampaignAttributionAfterCreate",
      "label": "Preserve existing Contact first campaign after create",
      "locationX": 400,
      "locationY": 1980,
      "rules": [
        {
          "name": "ContactFirstCampaignMissing",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "matchedWorkflowActionContact.First_Campaign__c",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "PatchContactCampaignAttributionAfterCreate"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "PatchContactLastCampaignAfterCreate"
      }
    },
    {
      "name": "CheckDefaultOwnerForShell",
      "label": "Own the new Lead shell with the Integration User when configured?",
      "locationX": 40,
      "locationY": 1120,
      "rules": [
        {
          "name": "DefaultOwnerConfigured",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$defaultOwnerUser.Id",
              "operator": "IsNotBlank"
            }
          ],
          "connector": {
            "targetReference": "CreateLeadShellWithIntegrationOwner"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "CreateLeadShellForWorkflowAction"
      }
    },
    {
      "name": "ChooseMappingSourceRecord",
      "label": "Choose workflow-action mapping source",
      "locationX": 40,
      "locationY": 90,
      "rules": [
        {
          "name": "FullContactRecordAvailable",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "record.id",
              "operator": "IsNotBlank"
            }
          ],
          "connector": {
            "targetReference": "UseFullContactRecordForMappings"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "UseWorkflowActionPayloadForMappings"
      }
    },
    {
      "name": "CheckRequiredInputs",
      "label": "Required action inputs present?",
      "locationX": 40,
      "locationY": 120,
      "rules": [
        {
          "name": "MissingHydratedContact",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "payload.email",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "FailMissingHydratedContact"
          }
        },
        {
          "name": "MissingCampaign",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "payload.campaign_id",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "FailInvalidCampaign"
          }
        },
        {
          "name": "MissingStatus",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "payload.status",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "FailInvalidStatus"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "FindCampaign"
      }
    },
    {
      "name": "CheckCampaignFound",
      "label": "Campaign exists?",
      "locationX": 220,
      "locationY": 360,
      "rules": [
        {
          "name": "CampaignMissing",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$campaign.Id",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "FailInvalidCampaign"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "FindCampaignMemberStatus"
      }
    },
    {
      "name": "CheckStatusFound",
      "label": "CampaignMemberStatus exists?",
      "locationX": 220,
      "locationY": 600,
      "rules": [
        {
          "name": "StatusMissing",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$campaignMemberStatus.Id",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "FailInvalidStatus"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "ChooseRemoteOrEmailLookup"
      }
    },
    {
      "name": "ChooseRemoteOrEmailLookup",
      "label": "Use remote id before email fallback",
      "locationX": 40,
      "locationY": 660,
      "rules": [
        {
          "name": "RemoteIdMissing",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "sourceID",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "CheckEmailAvailable"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "FindHubSpotContactMergeAlias"
      }
    },
    {
      "name": "RouteDurableRemoteIdentity",
      "label": "Route authoritative remote identity before compatibility lookup",
      "locationX": 220,
      "locationY": 720,
      "rules": [
        {
          "name": "DurableAuthoritySuspended",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "durableAuthorityState",
              "operator": "EqualTo",
              "rightValue": "suspended_drift"
            }
          ],
          "connector": {
            "targetReference": "FailDurableAuthorityUnavailable"
          }
        },
        {
          "name": "DurableOwnerDeletedPendingRecovery",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "durableAuthorityState",
              "operator": "EqualTo",
              "rightValue": "owner_deleted_pending_recovery"
            }
          ],
          "connector": {
            "targetReference": "CompleteDeferredDurableOwnerRecovery"
          }
        },
        {
          "name": "DurableOwnerDeleted",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "durableAuthorityState",
              "operator": "EqualTo",
              "rightValue": "finalized"
            },
            {
              "leftValueReference": "durableOwnerLifecycle",
              "operator": "EqualTo",
              "rightValue": "deleted"
            }
          ],
          "connector": {
            "targetReference": "CompleteDeferredDurableOwnerRecovery"
          }
        },
        {
          "name": "DurableActiveLead",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "durableAuthorityState",
              "operator": "EqualTo",
              "rightValue": "finalized"
            },
            {
              "leftValueReference": "durableOwnerLifecycle",
              "operator": "EqualTo",
              "rightValue": "active"
            },
            {
              "leftValueReference": "durableSourceObject",
              "operator": "EqualTo",
              "rightValue": "Lead"
            }
          ],
          "connector": {
            "targetReference": "UseDurableLeadOwner"
          }
        },
        {
          "name": "DurableActiveContact",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "durableAuthorityState",
              "operator": "EqualTo",
              "rightValue": "finalized"
            },
            {
              "leftValueReference": "durableOwnerLifecycle",
              "operator": "EqualTo",
              "rightValue": "active"
            },
            {
              "leftValueReference": "durableSourceObject",
              "operator": "EqualTo",
              "rightValue": "Contact"
            }
          ],
          "connector": {
            "targetReference": "UseDurableContactOwner"
          }
        },
        {
          "name": "DurableRecoveryReadbackMissing",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "durableAuthorityState",
              "operator": "EqualTo",
              "rightValue": "missing"
            },
            {
              "leftValueReference": "durableRecoveryState",
              "operator": "EqualTo",
              "rightValue": "recovered"
            }
          ],
          "connector": {
            "targetReference": "FailDurableAuthorityUnavailable"
          }
        },
        {
          "name": "DurableAuthorityUnexpected",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "durableAuthorityState",
              "operator": "NotEqualTo",
              "rightValue": "missing"
            }
          ],
          "connector": {
            "targetReference": "FailDurableAuthorityUnavailable"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "RecoverDurableRemoteIdentity"
      }
    },
    {
      "name": "RouteDurableRecovery",
      "label": "Route missing durable identity recovery result",
      "locationX": 580,
      "locationY": 720,
      "rules": [
        {
          "name": "DurableIdentityNotFound",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "durableRecoveryState",
              "operator": "EqualTo",
              "rightValue": "not_found"
            }
          ],
          "connector": {
            "targetReference": "FindLeadsByRemoteId"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "FailDurableAuthorityUnavailable"
      }
    },
    {
      "name": "DecideRemoteMatches",
      "label": "Remote id resolved exactly one person?",
      "locationX": 220,
      "locationY": 960,
      "rules": [
        {
          "name": "RemoteAmbiguous",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "totalMatchCount",
              "operator": "GreaterThan",
              "rightValue": 1
            }
          ],
          "connector": {
            "targetReference": "FailAmbiguousPerson"
          }
        },
        {
          "name": "RemoteLeadMatched",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "leadMatchCount",
              "operator": "EqualTo",
              "rightValue": 1
            }
          ],
          "connector": {
            "targetReference": "FindMatchedLeadForSafeRehydrate"
          }
        },
        {
          "name": "RemoteContactMatched",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "contactMatchCount",
              "operator": "EqualTo",
              "rightValue": 1
            }
          ],
          "connector": {
            "targetReference": "FindMatchedContactForSafeRehydrate"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "ResolveMergeAliasAfterRemoteMiss"
      }
    },
    {
      "name": "ResolveMergeAliasAfterRemoteMiss",
      "label": "Resolve a merged-away HubSpot id before email fallback",
      "locationX": 580,
      "locationY": 960,
      "rules": [
        {
          "name": "MergeAliasAlreadyApplied",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "mergeAliasApplied",
              "operator": "EqualTo",
              "rightValue": true
            }
          ],
          "connector": {
            "targetReference": "FailStaleMergeAlias"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "CheckEmailAvailable"
      }
    },
    {
      "name": "ApplyHubSpotMergeAliasOrResolveDurableIdentity",
      "label": "Canonicalize a workflow-action merge loser before durable identity resolution",
      "locationX": 760,
      "locationY": 960,
      "rules": [
        {
          "name": "MergeAliasFound",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$hubSpotContactMergeAlias.CanonicalHubSpotId__c",
              "operator": "IsNotBlank"
            }
          ],
          "connector": {
            "targetReference": "ApplyHubSpotMergeAlias"
          }
        },
        {
          "name": "RemoteIdHasNoMergeAlias",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "sourceID",
              "operator": "IsNotBlank"
            }
          ],
          "connector": {
            "targetReference": "ResolveDurableRemoteIdentity"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "ResolveDurableRemoteIdentity"
      }
    },
    {
      "name": "CheckEmailAvailable",
      "label": "Email fallback available?",
      "locationX": 40,
      "locationY": 1080,
      "rules": [
        {
          "name": "EmailMissing",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "workflowActionLeadEmail",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "FailMissingPerson"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "ResetEmailCounters"
      }
    },
    {
      "name": "DecideEmailMatches",
      "label": "Email fallback resolved exactly one person?",
      "locationX": 220,
      "locationY": 1440,
      "rules": [
        {
          "name": "RemoteIdentityCollision",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "sourceID",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "totalMatchCount",
              "operator": "GreaterThan",
              "rightValue": 0
            }
          ],
          "connector": {
            "targetReference": "FailRemoteIdentityCollision"
          }
        },
        {
          "name": "EmailAmbiguous",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "totalMatchCount",
              "operator": "GreaterThan",
              "rightValue": 1
            }
          ],
          "connector": {
            "targetReference": "FailAmbiguousPerson"
          }
        },
        {
          "name": "EmailLeadMatched",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "leadMatchCount",
              "operator": "EqualTo",
              "rightValue": 1
            }
          ],
          "connector": {
            "targetReference": "FindMatchedLeadForSafeRehydrate"
          }
        },
        {
          "name": "EmailContactMatched",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "contactMatchCount",
              "operator": "EqualTo",
              "rightValue": 1
            }
          ],
          "connector": {
            "targetReference": "FindMatchedContactForSafeRehydrate"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "ChooseLeadShellOrFail"
      }
    },
    {
      "name": "ChooseLeadShellOrFail",
      "label": "Create Lead shell when remote id is present?",
      "locationX": 400,
      "locationY": 1560,
      "rules": [
        {
          "name": "RemoteIdAvailable",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "sourceID",
              "operator": "IsNotBlank"
            }
          ],
          "connector": {
            "targetReference": "FindDefaultOwnerBinding"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "FailMissingPerson"
      }
    },
    {
      "name": "SafeLeadRehydrateNeeded",
      "label": "Safely rehydrate matched Lead from workflow action?",
      "locationX": 40,
      "locationY": 1680,
      "rules": [
        {
          "name": "MatchedLeadNeedsSafeRehydrate",
          "conditionLogic": "(1 AND 2) OR (3 AND (4 OR 5 OR 6)) OR (7 AND (8 OR 9 OR 10)) OR (11 AND (12 OR 13 OR 14))",
          "conditions": [
            {
              "leftValueReference": "sourceID",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "matchedWorkflowActionLead.HubSpot_Id__c",
              "operator": "IsBlank"
            },
            {
              "leftValueReference": "payload.firstname",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "matchedWorkflowActionLead.FirstName",
              "operator": "IsBlank"
            },
            {
              "leftValueReference": "matchedWorkflowActionLead.FirstName",
              "operator": "EqualTo",
              "rightValue": "HubSpot Lead"
            },
            {
              "leftValueReference": "matchedWorkflowActionLead.FirstName",
              "operator": "EqualTo",
              "rightValue": "[not provided]"
            },
            {
              "leftValueReference": "payload.lastname",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "matchedWorkflowActionLead.LastName",
              "operator": "IsBlank"
            },
            {
              "leftValueReference": "matchedWorkflowActionLead.LastName",
              "operator": "EqualTo",
              "rightValue": "HubSpot Lead"
            },
            {
              "leftValueReference": "matchedWorkflowActionLead.LastName",
              "operator": "EqualTo",
              "rightValue": "[not provided]"
            },
            {
              "leftValueReference": "payload.company",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "matchedWorkflowActionLead.Company",
              "operator": "IsBlank"
            },
            {
              "leftValueReference": "matchedWorkflowActionLead.Company",
              "operator": "EqualTo",
              "rightValue": "HubSpot Lead"
            },
            {
              "leftValueReference": "matchedWorkflowActionLead.Company",
              "operator": "EqualTo",
              "rightValue": "[not provided]"
            }
          ],
          "connector": {
            "targetReference": "SafeRehydrateMatchedLead"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "FindExistingLeadCampaignMember"
      }
    },
    {
      "name": "SafeContactRehydrateNeeded",
      "label": "Safely rehydrate matched Contact from workflow action?",
      "locationX": 400,
      "locationY": 1680,
      "rules": [
        {
          "name": "MatchedContactNeedsSafeRehydrate",
          "conditionLogic": "(1 AND 2) OR (3 AND (4 OR 5 OR 6)) OR (7 AND (8 OR 9 OR 10))",
          "conditions": [
            {
              "leftValueReference": "sourceID",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "matchedWorkflowActionContact.HubSpot_Id__c",
              "operator": "IsBlank"
            },
            {
              "leftValueReference": "payload.firstname",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "matchedWorkflowActionContact.FirstName",
              "operator": "IsBlank"
            },
            {
              "leftValueReference": "matchedWorkflowActionContact.FirstName",
              "operator": "EqualTo",
              "rightValue": "HubSpot Lead"
            },
            {
              "leftValueReference": "matchedWorkflowActionContact.FirstName",
              "operator": "EqualTo",
              "rightValue": "[not provided]"
            },
            {
              "leftValueReference": "payload.lastname",
              "operator": "IsNotBlank"
            },
            {
              "leftValueReference": "matchedWorkflowActionContact.LastName",
              "operator": "IsBlank"
            },
            {
              "leftValueReference": "matchedWorkflowActionContact.LastName",
              "operator": "EqualTo",
              "rightValue": "HubSpot Lead"
            },
            {
              "leftValueReference": "matchedWorkflowActionContact.LastName",
              "operator": "EqualTo",
              "rightValue": "[not provided]"
            }
          ],
          "connector": {
            "targetReference": "SafeRehydrateMatchedContact"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "FindExistingContactCampaignMember"
      }
    },
    {
      "name": "ChooseLeadCreateOrUpdate",
      "label": "Create or update Lead CampaignMember",
      "locationX": 40,
      "locationY": 1800,
      "rules": [
        {
          "name": "LeadCampaignMemberMissing",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$campaignMember.Id",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "CreateLeadCampaignMember"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "UpdateLeadCampaignMember"
      }
    },
    {
      "name": "ChooseContactCreateOrUpdate",
      "label": "Create or update Contact CampaignMember",
      "locationX": 400,
      "locationY": 1800,
      "rules": [
        {
          "name": "ContactCampaignMemberMissing",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$campaignMember.Id",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "CreateContactCampaignMember"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "UpdateContactCampaignMember"
      }
    },
    {
      "name": "CheckLeadOwnerBinding",
      "label": "Apply bound owner to workflow-action Lead shell?",
      "locationX": 580,
      "locationY": 1680,
      "rules": [
        {
          "name": "BoundLeadOwnerFound",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$leadOwnerBinding.Id",
              "operator": "IsNotBlank"
            }
          ],
          "connector": {
            "targetReference": "FindLeadOwnerBindingDup"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "FindExistingLeadCampaignMember"
      }
    },
    {
      "name": "CheckLeadOwnerAmbiguous",
      "label": "Duplicate workflow-action Lead owner binding found?",
      "locationX": 580,
      "locationY": 1920,
      "rules": [
        {
          "name": "LeadOwnerDupFound",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$leadOwnerBindingDup.Id",
              "operator": "IsNotBlank"
            }
          ],
          "connector": {
            "targetReference": "FailAmbiguousLeadOwner"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "ApplyBoundOwnerToWorkflowActionLead"
      }
    }
  ],
  "formulas": [
    {
      "name": "workflowActionLeadEmail",
      "dataType": "String",
      "expression": "payload.email"
    },
    {
      "name": "workflowActionHubSpotOwnerId",
      "dataType": "String",
      "expression": "payload.hubspot_owner_id"
    },
    {
      "name": "workflowActionLeadFirstName",
      "dataType": "String",
      "expression": "IF(ISBLANK(payload.lastname), \"\", payload.firstname)"
    },
    {
      "name": "workflowActionLeadLastName",
      "dataType": "String",
      "expression": "BLANKVALUE(payload.lastname, BLANKVALUE(payload.firstname, BLANKVALUE(payload.company, \"HubSpot Lead\")))"
    },
    {
      "name": "workflowActionLeadCompany",
      "dataType": "String",
      "expression": "BLANKVALUE(payload.company, \"HubSpot Lead\")"
    },
    {
      "name": "safeWorkflowActionLeadFirstName",
      "dataType": "String",
      "expression": "IF(AND(NOT(ISBLANK(payload.firstname)), OR(ISBLANK(matchedWorkflowActionLead.FirstName), matchedWorkflowActionLead.FirstName = \"HubSpot Lead\", matchedWorkflowActionLead.FirstName = \"[not provided]\")), payload.firstname, matchedWorkflowActionLead.FirstName)"
    },
    {
      "name": "safeWorkflowActionLeadLastName",
      "dataType": "String",
      "expression": "IF(AND(NOT(ISBLANK(payload.lastname)), OR(ISBLANK(matchedWorkflowActionLead.LastName), matchedWorkflowActionLead.LastName = \"HubSpot Lead\", matchedWorkflowActionLead.LastName = \"[not provided]\")), payload.lastname, matchedWorkflowActionLead.LastName)"
    },
    {
      "name": "safeWorkflowActionLeadCompany",
      "dataType": "String",
      "expression": "IF(AND(NOT(ISBLANK(payload.company)), OR(ISBLANK(matchedWorkflowActionLead.Company), matchedWorkflowActionLead.Company = \"HubSpot Lead\", matchedWorkflowActionLead.Company = \"[not provided]\")), payload.company, matchedWorkflowActionLead.Company)"
    },
    {
      "name": "safeWorkflowActionContactFirstName",
      "dataType": "String",
      "expression": "IF(AND(NOT(ISBLANK(payload.firstname)), OR(ISBLANK(matchedWorkflowActionContact.FirstName), matchedWorkflowActionContact.FirstName = \"HubSpot Lead\", matchedWorkflowActionContact.FirstName = \"[not provided]\")), payload.firstname, matchedWorkflowActionContact.FirstName)"
    },
    {
      "name": "safeWorkflowActionContactLastName",
      "dataType": "String",
      "expression": "IF(AND(NOT(ISBLANK(payload.lastname)), OR(ISBLANK(matchedWorkflowActionContact.LastName), matchedWorkflowActionContact.LastName = \"HubSpot Lead\", matchedWorkflowActionContact.LastName = \"[not provided]\")), payload.lastname, matchedWorkflowActionContact.LastName)"
    }
  ],
  "assignments": [
    {
      "name": "CompleteDeferredDurableOwnerRecovery",
      "label": "Complete deferred deleted-owner recovery without a business write",
      "locationX": 400,
      "locationY": 720,
      "assignmentItems": [
        {
          "assignToReference": "durableOwnerRecoveryDeferred",
          "operator": "Assign",
          "value": {
            "booleanValue": true
          }
        }
      ]
    },
    {
      "name": "UseDurableLeadOwner",
      "label": "Use authoritative durable Lead owner",
      "locationX": 400,
      "locationY": 780,
      "assignmentItems": [
        {
          "assignToReference": "matchedLeadId",
          "operator": "Assign",
          "value": {
            "elementReference": "durableSourceRecordId"
          }
        }
      ],
      "connector": {
        "targetReference": "FindMatchedLeadForSafeRehydrate"
      }
    },
    {
      "name": "UseDurableContactOwner",
      "label": "Use authoritative durable Contact owner",
      "locationX": 580,
      "locationY": 780,
      "assignmentItems": [
        {
          "assignToReference": "matchedContactId",
          "operator": "Assign",
          "value": {
            "elementReference": "durableSourceRecordId"
          }
        }
      ],
      "connector": {
        "targetReference": "FindMatchedContactForSafeRehydrate"
      }
    },
    {
      "name": "InitCounters",
      "label": "Initialize person match counters",
      "locationX": 40,
      "locationY": 60,
      "assignmentItems": [
        {
          "assignToReference": "leadMatchCount",
          "operator": "Assign",
          "value": 0
        },
        {
          "assignToReference": "contactMatchCount",
          "operator": "Assign",
          "value": 0
        },
        {
          "assignToReference": "totalMatchCount",
          "operator": "Assign",
          "value": 0
        },
        {
          "assignToReference": "resolvedHubSpotId",
          "operator": "Assign",
          "value": {
            "elementReference": "sourceID"
          }
        },
        {
          "assignToReference": "mergeAliasApplied",
          "operator": "Assign",
          "value": false
        }
      ],
      "connector": {
        "targetReference": "ChooseMappingSourceRecord"
      }
    },
    {
      "name": "ApplyHubSpotMergeAlias",
      "label": "Resolve the merged-away HubSpot id to its canonical id",
      "locationX": 760,
      "locationY": 1020,
      "assignmentItems": [
        {
          "assignToReference": "resolvedHubSpotId",
          "operator": "Assign",
          "value": {
            "elementReference": "$hubSpotContactMergeAlias.CanonicalHubSpotId__c"
          }
        },
        {
          "assignToReference": "mergeAliasApplied",
          "operator": "Assign",
          "value": true
        },
        {
          "assignToReference": "leadMatchCount",
          "operator": "Assign",
          "value": 0
        },
        {
          "assignToReference": "contactMatchCount",
          "operator": "Assign",
          "value": 0
        },
        {
          "assignToReference": "totalMatchCount",
          "operator": "Assign",
          "value": 0
        },
        {
          "assignToReference": "matchedLeadId",
          "operator": "Assign",
          "value": null
        },
        {
          "assignToReference": "matchedContactId",
          "operator": "Assign",
          "value": null
        }
      ],
      "connector": {
        "targetReference": "ResolveDurableRemoteIdentity"
      }
    },
    {
      "name": "UseWorkflowActionPayloadForMappings",
      "label": "Use workflow-action payload for mappings",
      "locationX": 40,
      "locationY": 90,
      "assignmentItems": [
        {
          "assignToReference": "mappingSourceRecord.id",
          "operator": "Assign",
          "value": {
            "elementReference": "sourceID"
          }
        },
        {
          "assignToReference": "mappingSourceRecord.email",
          "operator": "Assign",
          "value": {
            "elementReference": "payload.email"
          }
        },
        {
          "assignToReference": "mappingSourceRecord.firstname",
          "operator": "Assign",
          "value": {
            "elementReference": "payload.firstname"
          }
        },
        {
          "assignToReference": "mappingSourceRecord.lastname",
          "operator": "Assign",
          "value": {
            "elementReference": "payload.lastname"
          }
        },
        {
          "assignToReference": "mappingSourceRecord.company",
          "operator": "Assign",
          "value": {
            "elementReference": "payload.company"
          }
        },
        {
          "assignToReference": "mappingSourceRecord.country_picklist__sfdc_",
          "operator": "Assign",
          "value": {
            "elementReference": "payload.country_picklist__sfdc_"
          }
        },
        {
          "assignToReference": "mappingSourceRecord.hubspot_owner_id",
          "operator": "Assign",
          "value": {
            "elementReference": "payload.hubspot_owner_id"
          }
        },
        {
          "assignToReference": "mappingSourceRecord.jobtitle",
          "operator": "Assign",
          "value": {
            "elementReference": "payload.jobtitle"
          }
        },
        {
          "assignToReference": "mappingSourceRecord.leadsource",
          "operator": "Assign",
          "value": {
            "elementReference": "payload.leadsource"
          }
        },
        {
          "assignToReference": "mappingSourceRecord.lifecyclestage",
          "operator": "Assign",
          "value": {
            "elementReference": "payload.lifecyclestage"
          }
        },
        {
          "assignToReference": "mappingSourceRecord.no__of_times_mql",
          "operator": "Assign",
          "value": {
            "elementReference": "payload.no__of_times_mql"
          }
        },
        {
          "assignToReference": "mappingSourceRecord.hs_lead_status",
          "operator": "Assign",
          "value": {
            "elementReference": "payload.hs_lead_status"
          }
        },
        {
          "assignToReference": "mappingSourceRecord.salesforce_industry",
          "operator": "Assign",
          "value": {
            "elementReference": "payload.salesforce_industry"
          }
        },
        {
          "assignToReference": "mappingSourceRecord.recent_source",
          "operator": "Assign",
          "value": {
            "elementReference": "payload.recent_source"
          }
        },
        {
          "assignToReference": "mappingSourceRecord.recent_source_details",
          "operator": "Assign",
          "value": {
            "elementReference": "payload.recent_source_details"
          }
        },
        {
          "assignToReference": "mappingSourceRecord.lead_source_details",
          "operator": "Assign",
          "value": {
            "elementReference": "payload.lead_source_details"
          }
        }
      ],
      "connector": {
        "targetReference": "CheckRequiredInputs"
      }
    },
    {
      "name": "UseFullContactRecordForMappings",
      "label": "Use auto-fetched HubSpot contact for mappings",
      "locationX": 400,
      "locationY": 90,
      "assignmentItems": [
        {
          "assignToReference": "mappingSourceRecord",
          "operator": "Assign",
          "value": {
            "elementReference": "record"
          }
        }
      ],
      "connector": {
        "targetReference": "CheckRequiredInputs"
      }
    },
    {
      "name": "CountRemoteLead",
      "label": "Count remote-id Lead match",
      "locationX": 40,
      "locationY": 840,
      "assignmentItems": [
        {
          "assignToReference": "leadMatchCount",
          "operator": "Add",
          "value": 1
        },
        {
          "assignToReference": "totalMatchCount",
          "operator": "Add",
          "value": 1
        },
        {
          "assignToReference": "matchedLeadId",
          "operator": "Assign",
          "value": {
            "elementReference": "$candidateLead.Id"
          }
        }
      ],
      "connector": {
        "targetReference": "LoopRemoteLeads"
      }
    },
    {
      "name": "CountRemoteContact",
      "label": "Count remote-id Contact match",
      "locationX": 400,
      "locationY": 840,
      "assignmentItems": [
        {
          "assignToReference": "contactMatchCount",
          "operator": "Add",
          "value": 1
        },
        {
          "assignToReference": "totalMatchCount",
          "operator": "Add",
          "value": 1
        },
        {
          "assignToReference": "matchedContactId",
          "operator": "Assign",
          "value": {
            "elementReference": "$candidateContact.Id"
          }
        }
      ],
      "connector": {
        "targetReference": "LoopRemoteContacts"
      }
    },
    {
      "name": "ResetEmailCounters",
      "label": "Reset counters for email fallback",
      "locationX": 40,
      "locationY": 1140,
      "assignmentItems": [
        {
          "assignToReference": "leadMatchCount",
          "operator": "Assign",
          "value": 0
        },
        {
          "assignToReference": "contactMatchCount",
          "operator": "Assign",
          "value": 0
        },
        {
          "assignToReference": "totalMatchCount",
          "operator": "Assign",
          "value": 0
        },
        {
          "assignToReference": "matchedLeadId",
          "operator": "Assign",
          "value": null
        },
        {
          "assignToReference": "matchedContactId",
          "operator": "Assign",
          "value": null
        }
      ],
      "connector": {
        "targetReference": "FindLeadsByEmail"
      }
    },
    {
      "name": "CountEmailLead",
      "label": "Count email Lead match",
      "locationX": 40,
      "locationY": 1320,
      "assignmentItems": [
        {
          "assignToReference": "leadMatchCount",
          "operator": "Add",
          "value": 1
        },
        {
          "assignToReference": "totalMatchCount",
          "operator": "Add",
          "value": 1
        },
        {
          "assignToReference": "matchedLeadId",
          "operator": "Assign",
          "value": {
            "elementReference": "$candidateLead.Id"
          }
        }
      ],
      "connector": {
        "targetReference": "LoopEmailLeads"
      }
    },
    {
      "name": "CountEmailContact",
      "label": "Count email Contact match",
      "locationX": 400,
      "locationY": 1320,
      "assignmentItems": [
        {
          "assignToReference": "contactMatchCount",
          "operator": "Add",
          "value": 1
        },
        {
          "assignToReference": "totalMatchCount",
          "operator": "Add",
          "value": 1
        },
        {
          "assignToReference": "matchedContactId",
          "operator": "Assign",
          "value": {
            "elementReference": "$candidateContact.Id"
          }
        }
      ],
      "connector": {
        "targetReference": "LoopEmailContacts"
      }
    },
    {
      "name": "SetUpdatedCampaignMemberId",
      "label": "Expose updated CampaignMember Id",
      "locationX": 220,
      "locationY": 2040,
      "assignmentItems": [
        {
          "assignToReference": "campaignMemberId",
          "operator": "Assign",
          "value": {
            "elementReference": "$campaignMember.Id"
          }
        }
      ]
    }
  ],
  "loops": [
    {
      "name": "LoopRemoteLeads",
      "label": "Loop remote-id Lead matches",
      "locationX": 40,
      "locationY": 780,
      "collectionReference": "$remoteLeads",
      "assignNextValueToReference": "$candidateLead",
      "nextValueConnector": {
        "targetReference": "CountRemoteLead"
      },
      "noMoreValuesConnector": {
        "targetReference": "FindContactsByRemoteId"
      }
    },
    {
      "name": "LoopRemoteContacts",
      "label": "Loop remote-id Contact matches",
      "locationX": 400,
      "locationY": 780,
      "collectionReference": "$remoteContacts",
      "assignNextValueToReference": "$candidateContact",
      "nextValueConnector": {
        "targetReference": "CountRemoteContact"
      },
      "noMoreValuesConnector": {
        "targetReference": "DecideRemoteMatches"
      }
    },
    {
      "name": "LoopEmailLeads",
      "label": "Loop email Lead matches",
      "locationX": 40,
      "locationY": 1260,
      "collectionReference": "$emailLeads",
      "assignNextValueToReference": "$candidateLead",
      "nextValueConnector": {
        "targetReference": "CountEmailLead"
      },
      "noMoreValuesConnector": {
        "targetReference": "FindContactsByEmail"
      }
    },
    {
      "name": "LoopEmailContacts",
      "label": "Loop email Contact matches",
      "locationX": 400,
      "locationY": 1260,
      "collectionReference": "$emailContacts",
      "assignNextValueToReference": "$candidateContact",
      "nextValueConnector": {
        "targetReference": "CountEmailContact"
      },
      "noMoreValuesConnector": {
        "targetReference": "DecideEmailMatches"
      }
    }
  ],
  "recordCreates": [
    {
      "name": "CreateLeadShellForWorkflowAction",
      "label": "Create Lead shell when workflow action beats contact webhook",
      "locationX": 40,
      "locationY": 1200,
      "object": "Lead",
      "upsertByExternalIdField": "HubSpot_Id__c",
      "inputAssignments": [
        {
          "field": "FirstName",
          "value": {
            "elementReference": "workflowActionLeadFirstName"
          }
        },
        {
          "field": "LastName",
          "value": {
            "elementReference": "workflowActionLeadLastName"
          }
        },
        {
          "field": "Email",
          "value": {
            "elementReference": "workflowActionLeadEmail"
          }
        },
        {
          "field": "Company",
          "value": {
            "elementReference": "workflowActionLeadCompany"
          }
        },
        {
          "field": "HubSpot_Id__c",
          "value": {
            "elementReference": "resolvedHubSpotId"
          }
        },
        {
          "field": "HubSpot_Sync_Enabled__c",
          "value": true
        },
        {
          "field": "IsConverted",
          "value": false
        }
      ],
      "assignRecordIdToReference": "matchedLeadId",
      "connector": {
        "targetReference": "ApplyMappingsToWorkflowActionLead"
      }
    },
    {
      "name": "CreateLeadShellWithIntegrationOwner",
      "label": "Create Lead shell owned by the Integration User",
      "locationX": 400,
      "locationY": 1200,
      "object": "Lead",
      "upsertByExternalIdField": "HubSpot_Id__c",
      "inputAssignments": [
        {
          "field": "FirstName",
          "value": {
            "elementReference": "workflowActionLeadFirstName"
          }
        },
        {
          "field": "LastName",
          "value": {
            "elementReference": "workflowActionLeadLastName"
          }
        },
        {
          "field": "Email",
          "value": {
            "elementReference": "workflowActionLeadEmail"
          }
        },
        {
          "field": "Company",
          "value": {
            "elementReference": "workflowActionLeadCompany"
          }
        },
        {
          "field": "HubSpot_Id__c",
          "value": {
            "elementReference": "resolvedHubSpotId"
          }
        },
        {
          "field": "HubSpot_Sync_Enabled__c",
          "value": true
        },
        {
          "field": "IsConverted",
          "value": false
        },
        {
          "field": "OwnerId",
          "value": {
            "elementReference": "$defaultOwnerUser.Id"
          }
        }
      ],
      "assignRecordIdToReference": "matchedLeadId",
      "connector": {
        "targetReference": "ApplyMappingsToWorkflowActionLead"
      }
    },
    {
      "name": "CreateLeadCampaignMember",
      "label": "Create CampaignMember for Lead",
      "locationX": 40,
      "locationY": 1920,
      "object": "CampaignMember",
      "inputAssignments": [
        {
          "field": "CampaignId",
          "value": {
            "elementReference": "payload.campaign_id"
          }
        },
        {
          "field": "LeadId",
          "value": {
            "elementReference": "matchedLeadId"
          }
        },
        {
          "field": "Status",
          "value": {
            "elementReference": "payload.status"
          }
        }
      ],
      "assignRecordIdToReference": "campaignMemberId",
      "connector": {
        "targetReference": "ChooseLeadCampaignAttributionAfterCreate"
      }
    },
    {
      "name": "CreateContactCampaignMember",
      "label": "Create CampaignMember for Contact",
      "locationX": 400,
      "locationY": 1920,
      "object": "CampaignMember",
      "inputAssignments": [
        {
          "field": "CampaignId",
          "value": {
            "elementReference": "payload.campaign_id"
          }
        },
        {
          "field": "ContactId",
          "value": {
            "elementReference": "matchedContactId"
          }
        },
        {
          "field": "Status",
          "value": {
            "elementReference": "payload.status"
          }
        }
      ],
      "assignRecordIdToReference": "campaignMemberId",
      "connector": {
        "targetReference": "ChooseContactCampaignAttributionAfterCreate"
      }
    }
  ],
  "recordUpdates": [
    {
      "name": "PatchLeadCampaignAttributionAfterCreate",
      "label": "Patch Lead first and last campaign after create",
      "locationX": 40,
      "locationY": 2040,
      "object": "Lead",
      "filterLogic": "and",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "matchedLeadId"
          }
        },
        {
          "field": "First_Campaign__c",
          "operator": "IsBlank"
        }
      ],
      "recheckFiltersAtWrite": true,
      "inputAssignments": [
        {
          "field": "First_Campaign__c",
          "value": {
            "elementReference": "payload.campaign_id"
          }
        },
        {
          "field": "Last_Campaign__c",
          "value": {
            "elementReference": "payload.campaign_id"
          }
        }
      ],
      "connector": {
        "targetReference": "EnsureLeadLastCampaignAfterCreate"
      }
    },
    {
      "name": "PatchContactCampaignAttributionAfterCreate",
      "label": "Patch Contact first and last campaign after create",
      "locationX": 400,
      "locationY": 2040,
      "object": "Contact",
      "filterLogic": "and",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "matchedContactId"
          }
        },
        {
          "field": "First_Campaign__c",
          "operator": "IsBlank"
        }
      ],
      "recheckFiltersAtWrite": true,
      "inputAssignments": [
        {
          "field": "First_Campaign__c",
          "value": {
            "elementReference": "payload.campaign_id"
          }
        },
        {
          "field": "Last_Campaign__c",
          "value": {
            "elementReference": "payload.campaign_id"
          }
        }
      ],
      "connector": {
        "targetReference": "EnsureContactLastCampaignAfterCreate"
      }
    },
    {
      "name": "EnsureLeadLastCampaignAfterCreate",
      "label": "Ensure Lead last campaign after guarded first attribution",
      "locationX": 40,
      "locationY": 2100,
      "object": "Lead",
      "filterLogic": "1 AND (2 OR 3)",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "matchedLeadId"
          }
        },
        {
          "field": "Last_Campaign__c",
          "operator": "IsBlank"
        },
        {
          "field": "Last_Campaign__c",
          "operator": "NotEqualTo",
          "value": {
            "elementReference": "payload.campaign_id"
          }
        }
      ],
      "recheckFiltersAtWrite": true,
      "inputAssignments": [
        {
          "field": "Last_Campaign__c",
          "value": {
            "elementReference": "payload.campaign_id"
          }
        }
      ]
    },
    {
      "name": "EnsureContactLastCampaignAfterCreate",
      "label": "Ensure Contact last campaign after guarded first attribution",
      "locationX": 400,
      "locationY": 2100,
      "object": "Contact",
      "filterLogic": "1 AND (2 OR 3)",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "matchedContactId"
          }
        },
        {
          "field": "Last_Campaign__c",
          "operator": "IsBlank"
        },
        {
          "field": "Last_Campaign__c",
          "operator": "NotEqualTo",
          "value": {
            "elementReference": "payload.campaign_id"
          }
        }
      ],
      "recheckFiltersAtWrite": true,
      "inputAssignments": [
        {
          "field": "Last_Campaign__c",
          "value": {
            "elementReference": "payload.campaign_id"
          }
        }
      ]
    },
    {
      "name": "PatchLeadLastCampaignAfterCreate",
      "label": "Patch Lead last campaign after create",
      "locationX": 220,
      "locationY": 2040,
      "object": "Lead",
      "filterLogic": "and",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "matchedLeadId"
          }
        }
      ],
      "inputAssignments": [
        {
          "field": "Last_Campaign__c",
          "value": {
            "elementReference": "payload.campaign_id"
          }
        }
      ]
    },
    {
      "name": "PatchContactLastCampaignAfterCreate",
      "label": "Patch Contact last campaign after create",
      "locationX": 580,
      "locationY": 2040,
      "object": "Contact",
      "filterLogic": "and",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "matchedContactId"
          }
        }
      ],
      "inputAssignments": [
        {
          "field": "Last_Campaign__c",
          "value": {
            "elementReference": "payload.campaign_id"
          }
        }
      ]
    },
    {
      "name": "SafeRehydrateMatchedLead",
      "label": "Safely rehydrate matched Lead from workflow action",
      "locationX": 40,
      "locationY": 1800,
      "object": "Lead",
      "filterLogic": "and",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "matchedLeadId"
          }
        }
      ],
      "inputAssignments": [
        {
          "field": "FirstName",
          "value": {
            "elementReference": "safeWorkflowActionLeadFirstName"
          }
        },
        {
          "field": "LastName",
          "value": {
            "elementReference": "safeWorkflowActionLeadLastName"
          }
        },
        {
          "field": "Company",
          "value": {
            "elementReference": "safeWorkflowActionLeadCompany"
          }
        }
      ],
      "connector": {
        "targetReference": "FindExistingLeadCampaignMember"
      }
    },
    {
      "name": "SafeRehydrateMatchedContact",
      "label": "Safely rehydrate matched Contact from workflow action",
      "locationX": 400,
      "locationY": 1800,
      "object": "Contact",
      "filterLogic": "and",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "matchedContactId"
          }
        }
      ],
      "inputAssignments": [
        {
          "field": "FirstName",
          "value": {
            "elementReference": "safeWorkflowActionContactFirstName"
          }
        },
        {
          "field": "LastName",
          "value": {
            "elementReference": "safeWorkflowActionContactLastName"
          }
        }
      ],
      "connector": {
        "targetReference": "FindExistingContactCampaignMember"
      }
    },
    {
      "name": "ApplyBoundOwnerToWorkflowActionLead",
      "label": "Apply bound owner to workflow-action Lead",
      "locationX": 580,
      "locationY": 2040,
      "object": "Lead",
      "filterLogic": "and",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "matchedLeadId"
          }
        }
      ],
      "inputAssignments": [
        {
          "field": "OwnerId",
          "value": {
            "elementReference": "$leadOwnerBinding.CRMPrincipalId__c"
          }
        }
      ],
      "connector": {
        "targetReference": "FindExistingLeadCampaignMember"
      }
    },
    {
      "name": "UpdateLeadCampaignMember",
      "label": "Update existing Lead CampaignMember",
      "locationX": 220,
      "locationY": 1920,
      "object": "CampaignMember",
      "filterLogic": "and",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "$campaignMember.Id"
          }
        }
      ],
      "inputAssignments": [
        {
          "field": "Status",
          "value": {
            "elementReference": "payload.status"
          }
        }
      ],
      "connector": {
        "targetReference": "SetUpdatedCampaignMemberId"
      }
    },
    {
      "name": "UpdateContactCampaignMember",
      "label": "Update existing Contact CampaignMember",
      "locationX": 580,
      "locationY": 1920,
      "object": "CampaignMember",
      "filterLogic": "and",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "$campaignMember.Id"
          }
        }
      ],
      "inputAssignments": [
        {
          "field": "Status",
          "value": {
            "elementReference": "payload.status"
          }
        }
      ],
      "connector": {
        "targetReference": "SetUpdatedCampaignMemberId"
      }
    }
  ],
  "actionCalls": [
    {
      "name": "ApplyMappingsToWorkflowActionLead",
      "label": "Apply HubSpot mappings to workflow-action Lead",
      "locationX": 220,
      "locationY": 1320,
      "actionName": "applyConnectorFieldMappings",
      "actionType": "applyConnectorFieldMappings",
      "inputParameters": [
        {
          "name": "source",
          "value": {
            "stringValue": "pingcap-hubspot-companion"
          }
        },
        {
          "name": "sourceObject",
          "value": {
            "stringValue": "contacts"
          }
        },
        {
          "name": "targetObject",
          "value": {
            "stringValue": "Lead"
          }
        },
        {
          "name": "actionType",
          "value": {
            "stringValue": "hubspotContactLeadInbound"
          }
        },
        {
          "name": "direction",
          "value": {
            "stringValue": "inbound"
          }
        },
        {
          "name": "targetId",
          "value": {
            "elementReference": "matchedLeadId"
          }
        },
        {
          "name": "sourceRecord",
          "value": {
            "elementReference": "mappingSourceRecord"
          }
        }
      ],
      "connector": {
        "targetReference": "FinalizeWorkflowActionLeadAuthorship"
      }
    },
    {
      "name": "FinalizeWorkflowActionLeadAuthorship",
      "label": "Finalize workflow-action Lead HubSpot authorship",
      "locationX": 220,
      "locationY": 1440,
      "actionName": "finalizeConnectorInboundRemoteIdentity",
      "actionType": "finalizeConnectorInboundRemoteIdentity",
      "inputParameters": [
        {
          "name": "targetFlowDeveloperName",
          "value": {
            "stringValue": "HubSpot_Lead_Contact_Outbound_Update"
          }
        },
        {
          "name": "targetFlowActionName",
          "value": {
            "stringValue": "PushLeadToHubSpotContact"
          }
        }
      ],
      "connector": {
        "targetReference": "FindLeadOwnerBinding"
      }
    },
    {
      "name": "ResolveDurableRemoteIdentity",
      "label": "Resolve authoritative durable remote identity",
      "locationX": 220,
      "locationY": 660,
      "actionName": "resolveConnectorRemoteIdentity",
      "actionType": "resolveConnectorRemoteIdentity",
      "inputParameters": [
        {
          "name": "connectorOwnerKey",
          "value": {
            "stringValue": "pingcap-hubspot-companion"
          }
        },
        {
          "name": "destinationSlotId",
          "value": {
            "stringValue": "hubspot-contact"
          }
        },
        {
          "name": "remoteId",
          "value": {
            "elementReference": "resolvedHubSpotId"
          }
        }
      ],
      "outputParameters": [
        {
          "name": "authorityState",
          "value": {
            "elementReference": "durableAuthorityState"
          }
        },
        {
          "name": "sourceObject",
          "value": {
            "elementReference": "durableSourceObject"
          }
        },
        {
          "name": "sourceRecordId",
          "value": {
            "elementReference": "durableSourceRecordId"
          }
        },
        {
          "name": "ownerLifecycle",
          "value": {
            "elementReference": "durableOwnerLifecycle"
          }
        },
        {
          "name": "mirrorStatus",
          "value": {
            "elementReference": "durableMirrorStatus"
          }
        }
      ],
      "connector": {
        "targetReference": "RouteDurableRemoteIdentity"
      }
    },
    {
      "name": "RecoverDurableRemoteIdentity",
      "label": "Recover authored durable remote identity",
      "locationX": 400,
      "locationY": 720,
      "actionName": "requestConnectorRemoteIdentityRecovery",
      "actionType": "requestConnectorRemoteIdentityRecovery",
      "inputParameters": [
        {
          "name": "destinationSlotId",
          "value": {
            "stringValue": "hubspot-contact"
          }
        },
        {
          "name": "remoteId",
          "value": {
            "elementReference": "resolvedHubSpotId"
          }
        }
      ],
      "outputParameters": [
        {
          "name": "recoveryState",
          "value": {
            "elementReference": "durableRecoveryState"
          }
        }
      ],
      "connector": {
        "targetReference": "RouteDurableRecovery"
      }
    }
  ],
  "customErrors": [
    {
      "name": "FailDurableOwnerDeleted",
      "label": "Durable HubSpot contact owner is deleted",
      "locationX": 940,
      "locationY": 720,
      "customErrorMessages": [
        {
          "errorMessage": "HubSpot workflow action durable identity belongs to a deleted NexusCRM record and requires explicit recovery",
          "statusCode": "HUBSPOT_WORKFLOW_ACTION_DURABLE_OWNER_DELETED"
        }
      ]
    },
    {
      "name": "FailDurableAuthorityUnavailable",
      "label": "Durable HubSpot contact authority is unavailable",
      "locationX": 1100,
      "locationY": 720,
      "customErrorMessages": [
        {
          "errorMessage": "HubSpot workflow action durable identity authority is suspended or inconsistent; refusing compatibility fallback",
          "statusCode": "HUBSPOT_WORKFLOW_ACTION_DURABLE_AUTHORITY_UNAVAILABLE"
        }
      ]
    },
    {
      "name": "FailMissingHydratedContact",
      "label": "Missing HubSpot contact enrichment",
      "locationX": 760,
      "locationY": 180,
      "customErrorMessages": [
        {
          "errorMessage": "workflow action did not include an auto-fetched HubSpot contact record; refusing to create a partial Lead shell",
          "statusCode": "HUBSPOT_WORKFLOW_ACTION_CONTACT_ENRICHMENT_MISSING"
        }
      ]
    },
    {
      "name": "FailInvalidCampaign",
      "label": "Invalid Campaign",
      "locationX": 760,
      "locationY": 240,
      "customErrorMessages": [
        {
          "errorMessage": "workflow action campaign_id does not identify a Campaign",
          "statusCode": "HUBSPOT_WORKFLOW_ACTION_INVALID_CAMPAIGN"
        }
      ]
    },
    {
      "name": "FailInvalidStatus",
      "label": "Invalid CampaignMember status",
      "locationX": 760,
      "locationY": 480,
      "customErrorMessages": [
        {
          "errorMessage": "workflow action status is not valid for the selected Campaign",
          "statusCode": "HUBSPOT_WORKFLOW_ACTION_INVALID_STATUS"
        }
      ]
    },
    {
      "name": "FailMissingPerson",
      "label": "No Lead or Contact matched",
      "locationX": 760,
      "locationY": 1080,
      "customErrorMessages": [
        {
          "errorMessage": "workflow action payload did not resolve to exactly one Lead or Contact",
          "statusCode": "HUBSPOT_WORKFLOW_ACTION_PERSON_NOT_FOUND"
        }
      ]
    },
    {
      "name": "FailAmbiguousPerson",
      "label": "Multiple Leads or Contacts matched",
      "locationX": 760,
      "locationY": 1440,
      "customErrorMessages": [
        {
          "errorMessage": "workflow action payload resolved to multiple Leads or Contacts",
          "statusCode": "HUBSPOT_WORKFLOW_ACTION_AMBIGUOUS_PERSON"
        }
      ]
    },
    {
      "name": "FailRemoteIdentityCollision",
      "label": "Remote id is unresolved while email belongs to an active person",
      "locationX": 940,
      "locationY": 1380,
      "customErrorMessages": [
        {
          "errorMessage": "HubSpot workflow action remote id is unresolved while the email already belongs to an active NexusCRM Lead or Contact",
          "statusCode": "HUBSPOT_WORKFLOW_ACTION_IDENTITY_UNRESOLVED"
        }
      ]
    },
    {
      "name": "FailStaleMergeAlias",
      "label": "Merged-away HubSpot id did not resolve to a local canonical person",
      "locationX": 940,
      "locationY": 1020,
      "customErrorMessages": [
        {
          "errorMessage": "workflow action merge alias resolved to a canonical HubSpot id with no active NexusCRM person",
          "statusCode": "HUBSPOT_WORKFLOW_ACTION_STALE_MERGE_ALIAS"
        }
      ]
    },
    {
      "name": "FailAmbiguousLeadOwner",
      "label": "Ambiguous workflow-action Lead owner binding",
      "locationX": 940,
      "locationY": 1920,
      "customErrorMessages": [
        {
          "errorMessage": "HubSpot owner id resolves to multiple active Lead owner bindings; refusing to assign an arbitrary workflow-action Lead owner",
          "statusCode": "HUBSPOT_OWNER_BINDING_AMBIGUOUS_LEAD"
        }
      ]
    }
  ]
}
