API error

Hi all
I’m hoping someone can help - I’m very new to API’s but am giving it a go
I have the code but I am getting errors which I believe in part are caused by the Hubspot attribute not being correct and I’m not sure where to go from there
What I am basically looking to do is that if any contact’s Deal Stage is set to “Booked (100%)” then all other contacts that have a matching value in their “Department” and “Company name” fields will have a property named “Deal setup with other contact - do not call” updated to have the value “Yes”
This is my Python code
import hubspot

# Set up authentication with your access token hubspot = hubspot.Hubspot(api_key=‘pat-na1-988ff544-db7d-4746-aec8-92b36f8e163f’)

# Get the current contact’s ID from the workflow input current_contact_id = ‘{{contact.id}}’ # Get the current contact’s information current_contact = hubspot.contacts.get(current_contact_id)

# Get the current contact’s company and department information company_name = current_contact[‘properties’][‘company_name’][‘value’] department = current_contact[‘properties’][‘department’][‘value’]

# Look up the company ID by name companies = hubspot.companies.get_all() company_id = None for company in companies: if company[‘properties’][‘name’][‘value’] == company_name: company_id = company[‘id’] break if company_id is not None:

# Get all contacts at the company’s department response = hubspot.companies.get_all_contacts(company_id, department=department)

# Check if any of the contacts have a deal stage of “Booked” booked_contact_exists = False for contact in response: if “dealstage” in contact[“properties”] and contact[“properties”][“dealstage”][“value”] == “Booked”: booked_contact_exists = True break

# If a booked contact exists, update the “Booked with someone else - Do Not Call” property value for all contacts at the department if booked_contact_exists: for contact in response: if “Deal_setup_with_other_contact_-_do_not_call” in contact[“properties”]: contact[“properties”][“Deal_setup_with_other_contact_-_do_not_call”][“value”] = “Yes” hubspot.contacts.update(contact[“vid”], contact) else: print(“Company not found”)
Any help or hints would be muchly appreciated
Thanks

Vicki

I just wanted to say you should probably remove the api_key in your question for security reasons.

It’s not a live api_key
Thanks though :slightly_smiling_face:

Hi,

  • could you use the code formatting in your post to get a better overview of your source code
  • could you please add the full error message

Thanks,

Andreas