APIs & Integrations

christos_jubile
Member

Fetch associated contacts to a company

Hello, 

I am using the code below to fetch the associated contacts to a company

 

def get_associated_contact_ids(access_token, company_id):
    client = HubSpot(access_token=access_token)

    try:
        api_response = client.crm.associations.v4.basic_api.get_page(object_type="company", object_id=company_id, to_object_type="contact", limit=500)
        pprint(api_response)
    except ApiException as e:
        print("Exception when calling basic_api->get_page: %s\n" % e)

 

But i am getting this error below

 

HTTP response headers: HTTPHeaderDict({'Date': 'Sat, 25 Nov 2023 15:24:33 GMT', 'Content-Type': 'application/json;charset=utf-8', 'Content-Length': '299', 'Connection': 'keep-alive', 'CF-Ray': '82bae6368c44ee73-ATH', 'CF-Cache-Status': 'DYNAMIC', 'Strict-Transport-Security': 'max-age=31536000; includeSubDomains; preload', 'Vary': 'origin, Accept-Encoding', 'Access-Control-Allow-Credentials': 'false', 'X-Content-Type-Options': 'nosniff', 'x-envoy-upstream-service-time': '2', 'x-evy-trace-listener': 'listener_https', 'x-evy-trace-route-configuration': 'listener_https/all', 'x-evy-trace-route-service-name': 'envoyset-translator', 'x-evy-trace-served-by-pod': 'iad02/hubapi-td/envoy-proxy-66c9b4c4f4-669hc', 'x-evy-trace-virtual-host': 'all', 'X-HubSpot-Auth-Failure': '401 Unauthorized', 'X-HubSpot-Correlation-Id': 'eeb419be-a703-4d5e-9d63-8189645133f1', 'x-request-id': 'eeb419be-a703-4d5e-9d63-8189645133f1', 'X-Trace': '2B0194903B6F899280C4C04807FBAF991F60E5C44B000000000000000000', 'Report-To': '{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=VzTz8XI2VngFpQedsPi0FMKGVMWQXcfl8onxe%2FqGQczAOYRTLzG7PU8Qu2X%2FiA8C1mR9HNdOjIRwJDSwvBXZOeU3skDKaJzaDMP5KPJnN5KjsUk2Q8YV0oD3viA0zbf7"}],"group":"cf-nel","max_age":604800}', 'NEL': '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}', 'Server': 'cloudflare'})
wlserver_local_celeryworker | HTTP response body: {"status":"error","message":"Authentication credentials not found. This API supports OAuth 2.0 authentication and you can find more details at https://developers.hubspot.com/docs/methods/auth/oauth-overview","correlationId":"eeb419be-a703-4d5e-9d63-8189645133f1","category":"INVALID_AUTHENTICATION"}

 

any ideas?

0 Upvotes
2 Replies 2
Jaycee_Lewis
Community Manager
Community Manager

Fetch associated contacts to a company

Hey, @christos_jubile Thanks for your question. Did you get this resolved? If not, I'd suggest looking at your token.

  • If using a token from a Public App, have you tried refreshing it?
  • If using a token from a Public App, have you tried removing and re-adding only the required scopes?
  • Have you created a Private App with only the required scopes to make a quick test with?
  • Double check that your token is getting sent in the request headers

Thanks! — Jaycee

linkedin

Jaycee Lewis

Developer Community Manager

Community | HubSpot

0 Upvotes
christos_jubile
Member

Fetch associated contacts to a company

Hello, Jaycee 

Thank you for your quick response
I have a private app with the above scopes
crm.lists.writecrm.lists.readcrm.objects.contacts.readcrm.objects.contacts.writecrm.objects.custom.readcrm.objects.custom.writecrm.objects.deals.readcrm.objects.deals.writeticketscrm.objects.owners.readcrm.objects.companies.readcrm.objects.companies.writecrm.schemas.contacts.readcrm.schemas.deals.writecrm.schemas.companies.readcrm.schemas.companies.writecrm.schemas.contacts.writecrm.schemas.deals.readcrm.schemas.line_items.readcrm.objects.quotes.readcrm.schemas.quotes.readcrm.objects.line_items.readcrm.objects.line_items.writecrm.objects.goals.readcrm.objects.quotes.writecrm.objects.feedback_submissions.readcrm.schemas.custom.writecrm.objects.marketing_events.readcrm.objects.marketing_events.writecrm.schemas.custom.read

What am I doing wrong?

Regards

0 Upvotes