Primary Label Workflow Won't Branch Properly

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


issue workflow (unresponsive UI)

correct workflow (responsive UI)

property settings

Hi @RPerez14,

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

Why not just use a branch?

This would be a lot less prone to error.

Best regards!