HubSpot API (Private App) – "Authentication credentials not found" error

Hi! I’m trying to test the HubSpot API by making the following request with a Python script:

import requests
url = "https://api.hubapi.com/crm/v3/objects/contacts?limit=100&archived=false"
headers = {“authorization”: “Bearer MY_TOKEN”}
response = requests.get(url, headers=headers)
print(response.text)

But I’m getting this error:

{
“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”: “019d7712-d98f-7622-ad7a-045a0bcb177b”,
“category”: “INVALID_AUTHENTICATION”
}

What should I check? I’ve already verified the token and it seems correct. I also checked the permissions granted when creating the private app (I gave it the “crm.objects.contacts.read” scope), so that looks fine too.

Is there anything else I should review?

Thanks, regards!

Hey @YamilAli2,

Welcome to the Community!

In the meantime, these resources that I’ve included below may be worth exploring!

I’m also tagg in some of our top contributors who may be able to help troubleshoot further:

Hey @SteveHTM, @zach_threadint, @Josh -- Do you have any suggestions for @YamilAli2 on this?

Thanks in advance!

Sam, Community Manager

@YamilAli2 - I hope I can give you a good Pyton example here. I use these techniques almost every day in Custom workflow steps, so I have some conventions that work well for me.

Header setup - via a stored Secret.

 #Get the API key as environment variable
 api_token=os.getenv('CUSTOM_TOKEN')
 #API Request Headers
 headers = {
 'Content-Type': 'application/json',
 'Authorization': 'Bearer ' + api_token,
 }

GET call via requests:

 try:
 response = requests.request("GET", request_url, headers=headers)
 Jresp = response.json()
 except:
 print(response)

As long as you have set up required scopes any specific API URL in your Legacy/Private app/Service Keys , all should see a positive response.

Hope this is helpful.

Steve

Hi! thanks, it worked perfectly! Regards!