APIs & Integrations

esthom
メンバー

Cannot get an access token - unknown grant type

解決

Hi,

I am trying to get access token for a user, but I keep receiving "status":"BAD_GRANT_TYPE","message":"missing or unknown grant type". I have tried encoding query params or passing them as one json param, but nothing worked.

payload = {
    'grant_type': 'authorization_code',
    'client_id': 'f6***',
    'client_secret': 'f2***',
    'redirect_uri': 'https://sc***/',
    'code': '5f***'
}
requests.post('https://api.hubapi.com/oauth/v1/token?', params=payload)
0 いいね!
1件の承認済みベストアンサー
3PETE
解決策
HubSpot Employee
HubSpot Employee

Cannot get an access token - unknown grant type

解決

@esthom Are you setting your content-type in the headers? Should be

Content-Type: application/x-www-form-urlencoded;charset=utf-8

Sometimes not having the correct content-type can throw off a server trying to read your request.

元の投稿で解決策を見る

14件の返信
IsaacTakushi
HubSpot Employee
HubSpot Employee

Cannot get an access token - unknown grant type

解決

Glad to hear it, @brij! I've deleted the post you requested.

Isaac Takushi

Associate Certification Manager
0 いいね!
brij
メンバー

Cannot get an access token - unknown grant type

解決

@Isaac_Takushi Thanks a lot!

0 いいね!
IsaacTakushi
HubSpot Employee
HubSpot Employee

Cannot get an access token - unknown grant type

解決

Hi, @brij.

Are you still experiencing this error? I was unsure whether your last post said you got it working.

The client_id you should use is located in your app settings. If you need help finding this, please share your developer Hub ID and app ID.

Isaac Takushi

Associate Certification Manager
0 いいね!
brij
メンバー

Cannot get an access token - unknown grant type

解決

It worked now, please remove my last response.

0 いいね!
IsaacTakushi
HubSpot Employee
HubSpot Employee

Cannot get an access token - unknown grant type

解決

Welcome, @brij.

Per this documentation, you must include grant_type, client_id, client_secret, redirect_uri, and code in the request body.

You are trying to include those parameters as headers, but the only header should be Content-Type: application/x-www-form-urlencoded;charset=utf-8.

Isaac Takushi

Associate Certification Manager
0 いいね!
yan_hero_power
メンバー

Cannot get an access token - unknown grant type

解決

Hi, I am encountering similar issues with the curl response. In POSTMAN I am able to get a successful response, but when I replicate the settings in PHP with cURL, I am getting a "BAD_GRANT_TYPE" response.

 

Content Type should be set properly in the request. But I notice in the curl response, it shows content_type = application/json, is that correct?

 

Do you have any suggestions? Thanks

 

Screen Shot 2019-09-21 at 1.19.42 AM.pngScreen Shot 2019-09-21 at 1.22.46 AM.pngScreen Shot 2019-09-21 at 1.24.10 AM.png

0 いいね!
brij
メンバー

Cannot get an access token - unknown grant type

解決

Not it says "{
"status": "BAD_CLIENT_ID",

"message": "missing or unknown client id","

I think it worked now I have to get new client id.

But the same client id was used to get the code.

0 いいね!
esthom
メンバー

Cannot get an access token - unknown grant type

解決

Thanks @pmanca, that worked fine!

0 いいね!
3PETE
解決策
HubSpot Employee
HubSpot Employee

Cannot get an access token - unknown grant type

解決

@esthom Are you setting your content-type in the headers? Should be

Content-Type: application/x-www-form-urlencoded;charset=utf-8

Sometimes not having the correct content-type can throw off a server trying to read your request.

samarr
メンバー

Cannot get an access token - unknown grant type

解決

I am facing this problem, even though supplying the required params in the header and request body respectively as follows:

 

ContentHeaderContentHeader

 

BodyBody

 

Here's the error I face:

Error WindowError Window

 

brij
メンバー

Cannot get an access token - unknown grant type

解決

But not working for me even after chnaging the order as follows:
grant_type=authorization_code
&client_id=xxx
&client_secret=xxx
&redirect_uri=https://api.hubapi.com/contacts/v1/lists/all/contacts/all
&code=code_here

And adding " Content-Type: application/x-www-form-urlencoded;charset=utf-8"

image

0 いいね!
適用対象外

Cannot get an access token - unknown grant type

解決

@pmanca I seem to be having the same issue. Not sure why however. the header on postman is as you describe it along with the body data.

header image: https://ibb.co/bOVrAm
body image: https://ibb.co/d6Rni6

Any ideas would be greatly appreciated.

thx

0 いいね!
macarlucho
メンバー

Cannot get an access token - unknown grant type

解決

Hi, I'm having the same problem with Postman, how could you solve it?

0 いいね!
3PETE
HubSpot Employee
HubSpot Employee

Cannot get an access token - unknown grant type

解決

@sphot Can you send along the full image of your body?

0 いいね!