{
  "apiVersion": 63,
  "status": "Active",
  "label": "HubSpot Owner Directory Sync",
  "description": "Daily scheduled owner-directory refresh that keeps HubSpotOwnerBinding__c aligned with HubSpot owners and records unresolved bootstrap cases as exceptions.",
  "runAtomically": false,
  "start": {
    "locationX": 40,
    "locationY": 0,
    "triggerType": "Scheduled",
    "schedule": {
      "frequency": "Daily",
      "startDate": "2026-06-12",
      "startTime": "00:15:00",
      "timezoneSidKey": "UTC"
    },
    "connectorSource": {
      "ownerPack": "hubspot-crm-connector",
      "profileName": "hubspot-crm-owners",
      "objectKey": "owners",
      "itemsPath": "results",
      "itemIdPath": "id"
    },
    "connector": {
      "targetReference": "FindExistingBinding"
    }
  },
  "variables": [
    {
      "name": "failureStatus",
      "dataType": "String"
    },
    {
      "name": "exceptionType",
      "dataType": "String"
    },
    {
      "name": "exceptionMessage",
      "dataType": "String"
    },
    {
      "name": "bindingId",
      "dataType": "String"
    }
  ],
  "recordLookups": [
    {
      "name": "FindExistingBinding",
      "label": "Find existing owner binding",
      "locationX": 40,
      "locationY": 120,
      "object": "HubSpotOwnerBinding__c",
      "filterLogic": "and",
      "filters": [
        {
          "field": "HubSpotOwnerId__c",
          "operator": "EqualTo",
          "value": {
            "elementReference": "$Record.id"
          }
        }
      ],
      "outputReference": "$existingBinding",
      "getFirstRecordOnly": true,
      "connector": {
        "targetReference": "CheckManualLock"
      }
    },
    {
      "name": "FindActiveUserByEmail",
      "label": "Find active User by HubSpot email",
      "locationX": 400,
      "locationY": 480,
      "object": "User",
      "filterLogic": "and",
      "filters": [
        {
          "field": "Email",
          "operator": "EqualTo",
          "value": {
            "elementReference": "$Record.email"
          }
        },
        {
          "field": "IsActive",
          "operator": "EqualTo",
          "value": true
        }
      ],
      "outputReference": "$matchedUser",
      "getFirstRecordOnly": true,
      "connector": {
        "targetReference": "CheckActiveUserMatch"
      }
    },
    {
      "name": "FindActiveUserByEmailDup",
      "label": "Find duplicate active User by HubSpot email",
      "locationX": 400,
      "locationY": 720,
      "object": "User",
      "filterLogic": "and",
      "filters": [
        {
          "field": "Email",
          "operator": "EqualTo",
          "value": {
            "elementReference": "$Record.email"
          }
        },
        {
          "field": "IsActive",
          "operator": "EqualTo",
          "value": true
        },
        {
          "field": "Id",
          "operator": "NotEqualTo",
          "value": {
            "elementReference": "$matchedUser.Id"
          }
        }
      ],
      "outputReference": "$matchedUserDup",
      "getFirstRecordOnly": true,
      "connector": {
        "targetReference": "CheckExactActiveUserMatch"
      }
    }
  ],
  "decisions": [
    {
      "name": "CheckManualLock",
      "label": "Existing binding manually locked?",
      "locationX": 40,
      "locationY": 240,
      "rules": [
        {
          "name": "ManualLockEnabled",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$existingBinding.ManualLock__c",
              "operator": "EqualTo",
              "rightValue": {
                "booleanValue": true
              }
            }
          ]
        }
      ],
      "defaultConnector": {
        "targetReference": "CheckOwnerCandidate"
      }
    },
    {
      "name": "CheckOwnerCandidate",
      "label": "Owner item eligible for PERSON email bootstrap?",
      "locationX": 220,
      "locationY": 360,
      "rules": [
        {
          "name": "UnsupportedOwnerType",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$Record.type",
              "operator": "NotEqualTo",
              "rightValue": {
                "stringValue": "PERSON"
              }
            }
          ],
          "connector": {
            "targetReference": "MarkUnsupportedOwnerType"
          }
        },
        {
          "name": "ArchivedOwner",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$Record.archived",
              "operator": "EqualTo",
              "rightValue": {
                "booleanValue": true
              }
            }
          ],
          "connector": {
            "targetReference": "MarkArchivedOwner"
          }
        },
        {
          "name": "MissingEmail",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$Record.email",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "MarkMissingEmail"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "FindActiveUserByEmail"
      }
    },
    {
      "name": "CheckActiveUserMatch",
      "label": "Active User match found?",
      "locationX": 400,
      "locationY": 600,
      "rules": [
        {
          "name": "MissingActiveUserMatch",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$matchedUser.Id",
              "operator": "IsBlank"
            }
          ],
          "connector": {
            "targetReference": "MarkMissingActiveUser"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "FindActiveUserByEmailDup"
      }
    },
    {
      "name": "CheckExactActiveUserMatch",
      "label": "Exactly one active User match?",
      "locationX": 400,
      "locationY": 840,
      "rules": [
        {
          "name": "AmbiguousActiveUserMatch",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$matchedUserDup.Id",
              "operator": "IsNotBlank"
            }
          ],
          "connector": {
            "targetReference": "MarkAmbiguousActiveUser"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "UpsertBoundBinding"
      }
    },
    {
      "name": "UpsertFailureBinding",
      "label": "Update existing failure binding or create new one?",
      "locationX": 40,
      "locationY": 1080,
      "rules": [
        {
          "name": "ExistingBindingPresentForFailure",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$existingBinding.Id",
              "operator": "IsNotBlank"
            }
          ],
          "connector": {
            "targetReference": "UpdateFailureBinding"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "CreateFailureBinding"
      }
    },
    {
      "name": "UpsertBoundBinding",
      "label": "Update existing bound binding or create new one?",
      "locationX": 400,
      "locationY": 1080,
      "rules": [
        {
          "name": "ExistingBindingPresentForBound",
          "conditionLogic": "and",
          "conditions": [
            {
              "leftValueReference": "$existingBinding.Id",
              "operator": "IsNotBlank"
            }
          ],
          "connector": {
            "targetReference": "UpdateBoundBinding"
          }
        }
      ],
      "defaultConnector": {
        "targetReference": "CreateBoundBinding"
      }
    }
  ],
  "formulas": [
    {
      "name": "hubSpotUserIdText",
      "dataType": "String",
      "expression": "TEXT($Record.userId)"
    }
  ],
  "assignments": [
    {
      "name": "MarkUnsupportedOwnerType",
      "label": "Classify non-PERSON owner as unsupported",
      "locationX": 40,
      "locationY": 480,
      "assignmentItems": [
        {
          "assignToReference": "failureStatus",
          "operator": "Assign",
          "value": {
            "stringValue": "unsupported"
          }
        },
        {
          "assignToReference": "exceptionType",
          "operator": "Assign",
          "value": {
            "stringValue": "UnsupportedOwnerType"
          }
        },
        {
          "assignToReference": "exceptionMessage",
          "operator": "Assign",
          "value": {
            "stringValue": "HubSpot owner type is not PERSON; directory bootstrap skips non-person owners."
          }
        }
      ],
      "connector": {
        "targetReference": "UpsertFailureBinding"
      }
    },
    {
      "name": "MarkArchivedOwner",
      "label": "Classify archived owner",
      "locationX": 220,
      "locationY": 480,
      "assignmentItems": [
        {
          "assignToReference": "failureStatus",
          "operator": "Assign",
          "value": {
            "stringValue": "archived"
          }
        },
        {
          "assignToReference": "exceptionType",
          "operator": "Assign",
          "value": {
            "stringValue": "LookupFailed"
          }
        },
        {
          "assignToReference": "exceptionMessage",
          "operator": "Assign",
          "value": {
            "stringValue": "HubSpot owner is archived; directory bootstrap does not auto-bind archived owners."
          }
        }
      ],
      "connector": {
        "targetReference": "UpsertFailureBinding"
      }
    },
    {
      "name": "MarkMissingEmail",
      "label": "Classify PERSON owner without usable email",
      "locationX": 220,
      "locationY": 600,
      "assignmentItems": [
        {
          "assignToReference": "failureStatus",
          "operator": "Assign",
          "value": {
            "stringValue": "unresolved"
          }
        },
        {
          "assignToReference": "exceptionType",
          "operator": "Assign",
          "value": {
            "stringValue": "LookupFailed"
          }
        },
        {
          "assignToReference": "exceptionMessage",
          "operator": "Assign",
          "value": {
            "stringValue": "HubSpot PERSON owner email is blank; auto-email bootstrap skipped."
          }
        }
      ],
      "connector": {
        "targetReference": "UpsertFailureBinding"
      }
    },
    {
      "name": "MarkMissingActiveUser",
      "label": "Classify missing active User match",
      "locationX": 580,
      "locationY": 600,
      "assignmentItems": [
        {
          "assignToReference": "failureStatus",
          "operator": "Assign",
          "value": {
            "stringValue": "unresolved"
          }
        },
        {
          "assignToReference": "exceptionType",
          "operator": "Assign",
          "value": {
            "stringValue": "MissingBinding"
          }
        },
        {
          "assignToReference": "exceptionMessage",
          "operator": "Assign",
          "value": {
            "stringValue": "No active local User matched the HubSpot owner email."
          }
        }
      ],
      "connector": {
        "targetReference": "UpsertFailureBinding"
      }
    },
    {
      "name": "MarkAmbiguousActiveUser",
      "label": "Classify ambiguous active User match",
      "locationX": 580,
      "locationY": 840,
      "assignmentItems": [
        {
          "assignToReference": "failureStatus",
          "operator": "Assign",
          "value": {
            "stringValue": "unresolved"
          }
        },
        {
          "assignToReference": "exceptionType",
          "operator": "Assign",
          "value": {
            "stringValue": "AmbiguousBinding"
          }
        },
        {
          "assignToReference": "exceptionMessage",
          "operator": "Assign",
          "value": {
            "stringValue": "Multiple active local Users matched the HubSpot owner email."
          }
        }
      ],
      "connector": {
        "targetReference": "UpsertFailureBinding"
      }
    },
    {
      "name": "CaptureExistingBindingId",
      "label": "Expose existing binding id for exception link",
      "locationX": 40,
      "locationY": 1320,
      "assignmentItems": [
        {
          "assignToReference": "bindingId",
          "operator": "Assign",
          "value": {
            "elementReference": "$existingBinding.Id"
          }
        }
      ],
      "connector": {
        "targetReference": "CreateFailureException"
      }
    }
  ],
  "loops": [],
  "recordCreates": [
    {
      "name": "CreateFailureBinding",
      "label": "Create non-bound owner binding",
      "locationX": 40,
      "locationY": 1200,
      "object": "HubSpotOwnerBinding__c",
      "inputAssignments": [
        {
          "field": "HubSpotOwnerId__c",
          "value": {
            "elementReference": "$Record.id"
          }
        },
        {
          "field": "HubSpotOwnerType__c",
          "value": {
            "elementReference": "$Record.type"
          }
        },
        {
          "field": "HubSpotUserId__c",
          "value": {
            "elementReference": "hubSpotUserIdText"
          }
        },
        {
          "field": "NormalizedEmail__c",
          "value": {
            "elementReference": "$Record.email"
          }
        },
        {
          "field": "CRMPrincipalType__c",
          "value": null
        },
        {
          "field": "CRMPrincipalId__c",
          "value": null
        },
        {
          "field": "BindingStatus__c",
          "value": {
            "elementReference": "failureStatus"
          }
        },
        {
          "field": "SourceOfTruth__c",
          "value": null
        },
        {
          "field": "LastSeenAt__c",
          "value": {
            "elementReference": "$Flow.CurrentDateTime"
          }
        },
        {
          "field": "LastVerifiedAt__c",
          "value": {
            "elementReference": "$Flow.CurrentDateTime"
          }
        }
      ],
      "assignRecordIdToReference": "bindingId",
      "connector": {
        "targetReference": "CreateFailureException"
      }
    },
    {
      "name": "CreateFailureException",
      "label": "Create owner binding exception",
      "locationX": 40,
      "locationY": 1440,
      "object": "HubSpotOwnerBindingException__c",
      "inputAssignments": [
        {
          "field": "Binding__c",
          "value": {
            "elementReference": "bindingId"
          }
        },
        {
          "field": "SourceObject__c",
          "value": {
            "stringValue": "owners"
          }
        },
        {
          "field": "SourceRecordId__c",
          "value": {
            "elementReference": "$Record.id"
          }
        },
        {
          "field": "HubSpotOwnerId__c",
          "value": {
            "elementReference": "$Record.id"
          }
        },
        {
          "field": "ExceptionType__c",
          "value": {
            "elementReference": "exceptionType"
          }
        },
        {
          "field": "Status__c",
          "value": {
            "stringValue": "open"
          }
        },
        {
          "field": "Message__c",
          "value": {
            "elementReference": "exceptionMessage"
          }
        },
        {
          "field": "FirstSeenAt__c",
          "value": {
            "elementReference": "$Flow.CurrentDateTime"
          }
        },
        {
          "field": "LastSeenAt__c",
          "value": {
            "elementReference": "$Flow.CurrentDateTime"
          }
        },
        {
          "field": "RetryCount__c",
          "value": 1
        }
      ]
    },
    {
      "name": "CreateBoundBinding",
      "label": "Create bound owner binding",
      "locationX": 400,
      "locationY": 1200,
      "object": "HubSpotOwnerBinding__c",
      "inputAssignments": [
        {
          "field": "HubSpotOwnerId__c",
          "value": {
            "elementReference": "$Record.id"
          }
        },
        {
          "field": "HubSpotOwnerType__c",
          "value": {
            "stringValue": "PERSON"
          }
        },
        {
          "field": "HubSpotUserId__c",
          "value": {
            "elementReference": "hubSpotUserIdText"
          }
        },
        {
          "field": "NormalizedEmail__c",
          "value": {
            "elementReference": "$Record.email"
          }
        },
        {
          "field": "CRMPrincipalType__c",
          "value": {
            "stringValue": "User"
          }
        },
        {
          "field": "CRMPrincipalId__c",
          "value": {
            "elementReference": "$matchedUser.Id"
          }
        },
        {
          "field": "BindingStatus__c",
          "value": {
            "stringValue": "bound"
          }
        },
        {
          "field": "SourceOfTruth__c",
          "value": {
            "stringValue": "auto_email"
          }
        },
        {
          "field": "LastSeenAt__c",
          "value": {
            "elementReference": "$Flow.CurrentDateTime"
          }
        },
        {
          "field": "LastVerifiedAt__c",
          "value": {
            "elementReference": "$Flow.CurrentDateTime"
          }
        }
      ]
    }
  ],
  "recordUpdates": [
    {
      "name": "UpdateFailureBinding",
      "label": "Refresh existing non-bound owner binding",
      "locationX": 40,
      "locationY": 1200,
      "object": "HubSpotOwnerBinding__c",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "$existingBinding.Id"
          }
        }
      ],
      "inputAssignments": [
        {
          "field": "HubSpotOwnerId__c",
          "value": {
            "elementReference": "$Record.id"
          }
        },
        {
          "field": "HubSpotOwnerType__c",
          "value": {
            "elementReference": "$Record.type"
          }
        },
        {
          "field": "HubSpotUserId__c",
          "value": {
            "elementReference": "hubSpotUserIdText"
          }
        },
        {
          "field": "NormalizedEmail__c",
          "value": {
            "elementReference": "$Record.email"
          }
        },
        {
          "field": "CRMPrincipalType__c",
          "value": null
        },
        {
          "field": "CRMPrincipalId__c",
          "value": null
        },
        {
          "field": "BindingStatus__c",
          "value": {
            "elementReference": "failureStatus"
          }
        },
        {
          "field": "SourceOfTruth__c",
          "value": null
        },
        {
          "field": "LastSeenAt__c",
          "value": {
            "elementReference": "$Flow.CurrentDateTime"
          }
        },
        {
          "field": "LastVerifiedAt__c",
          "value": {
            "elementReference": "$Flow.CurrentDateTime"
          }
        }
      ],
      "connector": {
        "targetReference": "CaptureExistingBindingId"
      }
    },
    {
      "name": "UpdateBoundBinding",
      "label": "Refresh existing bound owner binding",
      "locationX": 400,
      "locationY": 1200,
      "object": "HubSpotOwnerBinding__c",
      "filters": [
        {
          "field": "Id",
          "operator": "EqualTo",
          "value": {
            "elementReference": "$existingBinding.Id"
          }
        }
      ],
      "inputAssignments": [
        {
          "field": "HubSpotOwnerId__c",
          "value": {
            "elementReference": "$Record.id"
          }
        },
        {
          "field": "HubSpotOwnerType__c",
          "value": {
            "stringValue": "PERSON"
          }
        },
        {
          "field": "HubSpotUserId__c",
          "value": {
            "elementReference": "hubSpotUserIdText"
          }
        },
        {
          "field": "NormalizedEmail__c",
          "value": {
            "elementReference": "$Record.email"
          }
        },
        {
          "field": "CRMPrincipalType__c",
          "value": {
            "stringValue": "User"
          }
        },
        {
          "field": "CRMPrincipalId__c",
          "value": {
            "elementReference": "$matchedUser.Id"
          }
        },
        {
          "field": "BindingStatus__c",
          "value": {
            "stringValue": "bound"
          }
        },
        {
          "field": "SourceOfTruth__c",
          "value": {
            "stringValue": "auto_email"
          }
        },
        {
          "field": "LastSeenAt__c",
          "value": {
            "elementReference": "$Flow.CurrentDateTime"
          }
        },
        {
          "field": "LastVerifiedAt__c",
          "value": {
            "elementReference": "$Flow.CurrentDateTime"
          }
        }
      ]
    }
  ],
  "actionCalls": [],
  "customErrors": []
}
