Error on client.auth.oauth.tokens_api.create

Trying to create api token, I used a code from documentation and performed this:

token = settings.HUBSPOT_ACCESS_TOKEN

client = Client.create(api_key=token)

api_response = client.auth.oauth.tokens_api.create(

grant_type=“authorization_code”,

redirect_uri=self.REDIRECT_URI,

client_id=self.CLIENT_ID,

client_secret=self.CLIENT_SECRET,

code=request.query_params.get(“code”),

)

but the answer was AttributeError: ‘TokensApi’ object has no attribute ‘create’

outdated documentation? What is correct way to use this method via Python client?

My client has hubspot-api-client==5.1.0 version.

Hi @DReztsov

import http.client

conn = http.client.HTTPSConnection (api.hubapi.com)

payload = ‘grant_type=authorization_code&code=<please enter code here>&redirect_uri=<please enter redirect uri here>&client_id=<please enter client id here>&client_secret=<please enter client secret here>’
headers = {
‘content-type’: ‘application/x-www-form-urlencoded’
}
conn.request(“POST”, “/oauth/v1/token”, payload, headers)
res = conn.getresponse()
data = res.read()
print(data.decode(“utf-8”))

“Hope this will helps you out. Please mark it as Solution Accepted & Upvote to help other Community member.
Thanks!”

Hi, Gaurav. Of corse, request via http or requests works. It’s strange, that this endpoint and some others don’t work via client.

Thank you for assistance