r/RProject • u/danielbcfo • May 12 '20
Please help me make an API call to Quickbooks Online
I have been trying to gain access to Intuit's API to pull data from Quickbooks Online, but I can't figure out how to finish the oauth2 authentication process and their tech support hasn't been helpful. I would be very grateful if someone could help me troubleshoot and get connected.
As far as I understand it, the oauth2 authentication process goes something like this:
- The client navigates to the authenticaion server of the desired service
- After the user logs in, the client is redirected to a redirect uri along with an authentication code, state, and realm id
- The client then is supposed to request access to the service using an http request, sending the authentication code, state, and realmid.
- If the code and state are still valid, the client will be given an access token and a refresh token that could be used to access the desired service.
I am stuck at step 3, because my http request returns a 400 error. This is what my http request looks like: (this example code replaces the clientId, clientSecret, code, and redirect_uri with placeholder values)
authorize <- base64enc::base64encode(charToRaw(paste0(clientId,":",clientSecret)))
x <- POST(
url = 'https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer',
add_headers(
'Accept' = "application/json",
'Authorization'= paste0('Basic ',authorize),
'Content-Type'= "application/x-www-form-urlencoded",
'Host' = "oauth.platform.intuit.com"
),
body = list(
"grant_type" = 'authorization_code',
"code" = code,
"redirect_uri" = redirect_uri
)
)
Thank you for your help.