APIs & Integrations

basware_hubspot
Member

Bad Grant Type error for hubspot API access Token

I am trying to get access token as per the developer forms but everytime i bumped into this error .

here's how i am trying to get the access token . Any idea what am i doing wrong ?

library(httr)
Auth_token_url = 'https://api.hubapi.com/oauth/v1/token'

headers_api = c(``Content-Type`` = 'application/x-www-form-urlencoded;charset=utf-8')

parameters = list(
grant_type= 'authorization_code', client_id``= 'xxxxxxx',``client_secret = 'xxxx',
redirect_uri` = 'https://www.example.com/',`code`` = 'xxxxx')

GetToken <- httr::POST(url = Auth_token_url, httr::add_headers(.headers=headers_api), body=parameters, httr::authenticate('client_id', 'client_secret') )

GetToken_text=content(GetToken, "text")

GetToken

GetToken_text

0 Upvotes
4 Replies 4
cbarley
HubSpot Alumni
HubSpot Alumni

Bad Grant Type error for hubspot API access Token

Hi @pan999, while I don't know much about using R to generate access tokens, that message from HubSpot's servers means that your grant_type parameter isn't present or are malformed. Taking a look at the httr docs, I'd try to make the request as simple as possible and try work back from there. This section seems to be what you're looking for: https://cran.r-project.org/web/packages/httr/vignettes/quickstart.html#request-body

I'd also try checking out this post I found about OAuth here: https://support.rstudio.com/hc/en-us/articles/217952868-Generating-OAuth-tokens-for-a-server-using-h...

0 Upvotes
Ilya3
Member

Bad Grant Type error for hubspot API access Token

Hi. When trying to retrieve access_token also getting the same error. 
(using Postman or curl)

curl -H 'Content-Type:application/x-www-form-urlencoded' -X POST -d '{"grant_type":"authorization_code","client_id":"3f1a03fe-0433-41ea-8387-81cbb639a26b","client_secret":"my_client_secret","redirect_uri":"https://localhost:3000/","code":"my_auth_code"}' https://api.hubapi.com/oauth/v1/token
NSingh4
Member

Bad Grant Type error for hubspot API access Token

How did you solve it getting same error.

 

0 Upvotes
NSingh4
Member

Bad Grant Type error for hubspot API access Token

How did you solve it ? i am also getting the same error

 

0 Upvotes