Error Connecting via Apps using Python

I am getting this error below when trying to connect to Hubspot using a private app created and Python.

"

Traceback (most recent call last):
File “C:\Users\Anthony.DESKTOP-ES5HL78\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\models.py”, line 971, in json
return complexjson.loads(self.text, **kwargs)
File “C:\Users\Anthony.DESKTOP-ES5HL78\AppData\Local\Programs\Python\Python310\lib\json\__init__.py”, line 346, in
loads
return _default_decoder.decode(s)
File “C:\Users\Anthony.DESKTOP-ES5HL78\AppData\Local\Programs\Python\Python310\lib\json\decoder.py”, line 337, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File “C:\Users\Anthony.DESKTOP-ES5HL78\AppData\Local\Programs\Python\Python310\lib\json\decoder.py”, line 355, in raw_decode
raise JSONDecodeError(“Expecting value”, s, err.value) from None
json.decoder.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File “C:\Users\Anthony.DESKTOP-ES5HL78\Documents\Scrapy\projects\auth.py”, line 22, in <module>
auth_token = get_auth_token()
File “C:\Users\Anthony.DESKTOP-ES5HL78\Documents\Scrapy\projects\auth.py”, line 15, in get_auth_token
response_dict = response.json()
File “C:\Users\Anthony.DESKTOP-ES5HL78\AppData\Local\Programs\Python\Python310\lib\site-packages\requests\models.py”, line 975, in json
raise RequestsJSONDecodeError(e.msg, e.doc, e.pos)
requests.exceptions.JSONDecodeError: Expecting value: line 1 column 1 (char 0)

" AND

“Error getting access token: b’{“status”:“BAD_GRANT_TYPE”,“message”:“missing or unknown grant type”,“correlationId”:“daab6538-15f6-4e5a-8172-c70ed3ef3376”}’
Error getting access token: b’{“status”:“BAD_GRANT_TYPE”,“message”:“missing or unknown grant type”,“correlationId”:“6c614382-cf20-47a0-827a-c48c7ac47056”}’
Error getting access token: b’{“status”:“BAD_GRANT_TYPE”,“message”:“missing or unknown grant type”,“correlationId”:“f3d91db5-1610-4b69-856a-d9ff16a7acee”}’
Error getting acce”

Here is my code: "

import requests

CLIENT_ID = ‘e2e6713e-0813-457a-b2c2-19ff2df1407c’

CLIENT_SECRET = ‘9b876b6e-835b-40ba-b48e-216010ce00ea’

ACCESS_TOKEN = ‘i provided access code as per app created’

def get_auth_token():

url = 'https://api.hubapi.com/oauth/v1/pat-eu1-6f9d23ad-ac6e-45a2-aaeb-a62b9554ce61'

data = {

    'grant\_type': 'client\_credentials',

    'client\_id': CLIENT\_ID,

    'client\_secret': CLIENT\_SECRET

}

response = requests.post(url, data=data)

response\_dict = response.json()

if 'access\_token' in response\_dict:

    return response\_dict\['access\_token']

else:

    print(f"Error: {response\_dict.get('error\_description')}")

    return None

auth_token = get_auth_token()

if auth_token:

print(auth\_token)

else:

print("Could not retrieve authentication token.")

"

Please assist?

Hi!

1. I think you need to check your URL because it currently contains your private app API key

2. You need to encode your POST request data as json

import json

url = "" # check your correct API URL here
data = {
 'grant_type': 'client_credentials',
 'client_id': CLIENT_ID,
 'client_secret': CLIENT_SECRET
}
headers = {'Content-type': 'application/json', 'Accept': 'application/json'}
response = requests.post(url, data=json.dumps(data), headers=headers)

Cheers,

Andreas

I am getting an error even without the URL, how would I incorporate your code into mine?

Hi,

I think we need to go back on step. What do you try to achieve with your code. It looks like at the moment, Hubspot does not support the client_credentails auth flow. It is only possible to authenticate via an HTTP redirect.

Please review the Working with OAuth documentation.

Cheers,

Andreas

PowerBI and Tableau does not have an integrated connector to Hubspot. I would like to build a data pipeline using Python to extract data from Hubspot into a SQL db to be able to connect to BI reporting tools. Please advice.

PowerBI and Tableau do not have an integrated connector to Hubspot. I want to build a Python data pipeline to extract data from Hubspot into a SQL DB to connect to BI reporting tools. Please advise.