# Primary Label Workflow Won't Branch Properly

**URL:** <https://community.hubspot.com/t/primary-label-workflow-wont-branch-properly/135307>\
**Category:** 💬 RevOps Discussions\
**Tags:** revops\
**Created:** [June 27, 2025, 9:30am UTC](https://community.hubspot.com/t/primary-label-workflow-wont-branch-properly/135307 "2025-06-27T09:30:00Z")\
**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, 9:30am UTC](https://community.hubspot.com/t/primary-label-workflow-wont-branch-properly/135307/1 "2025-06-27T09:30:00Z")

</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)  
}  
}

 ![issueworkflow.py.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/5/d/5d24852e6b04528a8b52eb5f35b96a3f7dfc427d.png)  
issue workflow (unresponsive UI)  
 ![correctworkingworkflow.py.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/6/7/67465e302ddd0a67cb75944cbe645d05290a73e8.png)  
correct workflow (responsive UI)  
 ![Screenshot 2025-06-27 102615.png](https://d2qpr2jzcazej7.cloudfront.net/original/3X/1/c/1c44797fda93ab0256f902c462959b0b86517b87.png)  
property settings

---

<div class="post-metadata">

**Author:** ![karstenkoehler](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/karstenkoehler/32/68554_2.png) [@karstenkoehler](https://community.hubspot.com/u/karstenkoehler)\
**Post date:** [June 27, 2025, 10:49am UTC](https://community.hubspot.com/t/primary-label-workflow-wont-branch-properly/135307/2 "2025-06-27T10:49:10Z")

</div>

Hi @RPerez14,

No need to cross-post – but I’ll reply here as well.

Why not just use a branch?

 ![](https://d2qpr2jzcazej7.cloudfront.net/original/3X/a/1/a19ca4c0162cdac1525f40acdfd4e7ae3dd3179a.png)

This would be a lot less prone to error.

Best regards!
