My issue seems very similar to this one link to similar question, but the suggested solution does not seem to solve my issue.
The suggested solution assumes that I already have the access token and refresh token. To get those tokens, you need an authorization code which is delivered after being directed to the Quickbooks website and upon logging in and being redirected back to your app.
My question is, what redirect URI should I use if I'm executing this code from R Studio Pro, and once I'm redirected, how could I retrieve that authentication code? I hope that makes sense.
library(httr) library(httpuv) library(curl) library(jsonlite) library(base64enc) endPoint <- oauth_endpoint( request = NULL, authorize = "https://appcenter.intuit.com/connect/oauth2", access = "https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer" ) App <- oauth_app( "QBOR Dev", key = my_key, secret = my_secret, redirect_uri = "https://developer.intuit.com/v2/OAuth2Playground/RedirectUrl" ) QBOtoken <- oauth2.0_token( endpoint = endPoint, app = App, scope = "com.intuit.quickbooks.accounting", type = "code", cache = TRUE )
Suggested Solution Link
library(httr) library(httpuv) library(curl) library(jsonlite) library(base64enc) #Client ID and Client Secret were retrieved from the online explorer clientID <- "<ClientID>" clientSecret <- "<ClientSecret>" scope <- "com.intuit.quickbooks.accounting" tokens <- read.csv("tokens.csv") RefreshToken <- as.character(tokens$RefreshToken) AccessToken <- as.character(tokens$AccessToken) authorize <- base64enc::base64encode(charToRaw(paste0(clientID,":",clientSecret))) oauth_refresh <- httr::POST("https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer", add_headers('Content-Type'= "application/x-www-form-urlencoded", 'Accept'= 'application/json', 'Authorization'= paste0('Basic ',authorize) ), body = list('grant_type'='refresh_token', 'refresh_token'=RefreshToken), encode = "form") oaJSON <- fromJSON(content(oauth_refresh, as = "text")) RefreshToken <- oaJSON[["refresh_token"]] AccessToken <- oaJSON[["access_token"]] tokens <- as.data.frame(list('RefreshToken'=RefreshToken,'AccessToken'=AccessToken)) write.csv(tokens,file = "tokens.csv", row.names = F) datas <- httr::GET("https://sandbox-quickbooks.api.intuit.com/v3/company/<ID>/query?query=SELECT%20%2a%20FROM%20Customer", accept_json(), add_headers('Authorization'= paste0("Bearer ",AccessToken)) ) #datas$status_code j_son <- content(datas, as = "text") customers <- fromJSON(j_son) customer_df <- customers$QueryResponse$Customer