# API error

**URL:** <https://community.hubspot.com/t/api-error/79044>\
**Category:** APIs & Integrations\
**Tags:** professional\
**Created:** [April 11, 2023, 9:49am UTC](https://community.hubspot.com/t/api-error/79044 "2023-04-11T09:49:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![VMoonSGF](https://avatars.discourse-cdn.com/v4/letter/v/77aa72/32.png) [@VMoonSGF](https://community.hubspot.com/u/VMoonSGF)\
**Post date:** [April 11, 2023, 9:49am UTC](https://community.hubspot.com/t/api-error/79044/1 "2023-04-11T09:49:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![altoption](https://avatars.discourse-cdn.com/v4/letter/a/7bcc69/32.png) [@altoption](https://community.hubspot.com/u/altoption)\
**Post date:** [April 11, 2023, 1:05pm UTC](https://community.hubspot.com/t/api-error/79044/2 "2023-04-11T13:05:15Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![VMoonSGF](https://avatars.discourse-cdn.com/v4/letter/v/77aa72/32.png) [@VMoonSGF](https://community.hubspot.com/u/VMoonSGF)\
**Post date:** [April 11, 2023, 1:26pm UTC](https://community.hubspot.com/t/api-error/79044/3 "2023-04-11T13:26:18Z")

</div>

It’s not a live api\_key  
Thanks though 🙂

---

<div class="post-metadata">

**Author:** ![andreaska](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/andreaska/32/198312_2.png) [@andreaska](https://community.hubspot.com/u/andreaska)\
**Post date:** [April 11, 2023, 1:24pm UTC](https://community.hubspot.com/t/api-error/79044/4 "2023-04-11T13:24:30Z")

</div>

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
