# Primary Label Workflow Won't Branch Properly

**URL:** <https://community.hubspot.com/t/primary-label-workflow-wont-branch-properly/135314>\
**Category:** APIs & Integrations\
**Tags:** python, object\
**Created:** [June 27, 2025, 10:48am UTC](https://community.hubspot.com/t/primary-label-workflow-wont-branch-properly/135314 "2025-06-27T10:48:26Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![RPerez14](https://avatars.discourse-cdn.com/v4/letter/r/90ced4/32.png) [@RPerez14](https://community.hubspot.com/u/RPerez14)\
**Post date:** [June 27, 2025, 10:48am UTC](https://community.hubspot.com/t/primary-label-workflow-wont-branch-properly/135314/1 "2025-06-27T10:48:26Z")

</div>

I’m creating a workflow that checks whether a deal has a primary company label or not, and then it adds the deals to an active list to be manually reviewed. When I run test cases through the workflow, they all move through “none met” when they should be moving through the “yes” or “no” branches, so I think it has something to do with the property not being accessible. I created a property to store a boolean for this workflow and it hasn’t been populated by any other means. I’ve declared the right data output by naming the property and the boolean datatype, and the output is in the form of a dictionary. The code is listed below:

import requests

PRIMARY\_LABEL\_ID = 1

def get\_headers(api\_key):  
return {  
‘Authorization’: f’Bearer {api\_key}',  
‘Content-Type’: ‘application/json’  
}

def get\_company\_associations(deal\_id, headers):  
url = f’[https://api.hubapi.com/crm/v4/objects/deals/{deal\_id}/associations/companies](https://api.hubapi.com/crm/v4/objects/deals/%7Bdeal_id%7D/associations/companies)’  
params = {‘limit’: 100}  
response = requests.get(url, headers=headers, params=params)  
response.raise\_for\_status()  
return response.json().get(‘results’, [])

def has\_primary\_company(associations):  
for assoc in associations:  
label\_ids = assoc.get(‘associationSpec’, {}).get(‘labelIds’, assoc.get(‘labelIds’, []))  
if PRIMARY\_LABEL\_ID in label\_ids:  
return “Yes”  
return “No”

def main(input):  
deal\_id = input.get(‘inputFields’, {}).get(‘hs\_object\_id’)  
api\_key = ‘pat-na1-e08350ef-4f05-4dd1-8295-3d398d3fcd47’ # replace with secure token in production

if not api\_key:  
return {  
“outputFields”: {  
“primary\_company\_associated”: “No”,  
“error”: “Missing HubSpot access token in secrets”  
}  
}

if not deal\_id:  
return {  
“outputFields”: {  
“primary\_company\_associated”: “No”,  
“error”: “Missing hs\_object\_id input field”  
}  
}

try:  
headers = get\_headers(api\_key)  
associations = get\_company\_associations(deal\_id, headers)  
is\_primary = has\_primary\_company(associations)

return {  
“outputFields”: {  
“primary\_company\_associated”: is\_primary,  
“error”: “YAY! no error” # always include error field for consistency  
}  
}

except Exception as e:  
return {  
“outputFields”: {  
“primary\_company\_associated”: “No”,  
“error”: str(e)  
}  
}

---

<div class="post-metadata">

**Author:** ![GiantFocal](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/giantfocal/32/41969_2.png) [@GiantFocal](https://community.hubspot.com/u/GiantFocal)\
**Post date:** [June 27, 2025, 11:58am UTC](https://community.hubspot.com/t/primary-label-workflow-wont-branch-properly/135314/2 "2025-06-27T11:58:09Z")

</div>

Hi @RPerez14,

Just a couple of things to double-check:

1. First, the PRIMARY\_LABEL\_ID = 1 in your code indicates you’re aiming to find an association label with that ID. Have you verified that this ID exactly matches the primary company label ID in your HubSpot portal?
2. You mentioned you’ve created a boolean property named primary\_company\_associated. While your Python code outputs “Yes” or “No”. HubSpot’s boolean properties generally require “true” or “false” in lowercase, not as strings.
