Bad Grant Type error for hubspot API access Token


#1

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


"BAD Authorization Code" issue
#3

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-httr