javascriptgoogle-apps-scriptoauthquickbooksintuit-partner-platform

Connecting Quickbooks OAuth through Google Apps Script


I'm trying to connect Quickbooks API through OAuth. I've added the OAuth 2 library to the Apps Script and deployed the Web App. The Web App URL is what I'm using as an URI in the OAuthService call and I've also set it up in the Quickbooks URI parameters. I get the Quickbooks site to open to authorize, but then I keep getting errors from Google or Intuit.

Code looks like this:

function getAuthorizationUrl() {
  console.log('getAuthorizationUrl called');
  var service = getOAuthService();
  if (!service.hasAccess()) {
    var authorizationUrl = service.getAuthorizationUrl();
    return authorizationUrl;
  }
}

function getOAuthService() {
  var REDIRECT_URI = 'https://script.google.com/macros/s/[SCRIPT_ID]/usercallback/';
  return OAuth2.createService('QuickBooks')
      .setAuthorizationBaseUrl('https://appcenter.intuit.com/connect/oauth2')
      .setTokenUrl('https://oauth.platform.intuit.com/oauth2/v1/tokens/bearer')
      .setClientId(CLIENT_ID)
      .setClientSecret(CLIENT_SECRET)
      .setRedirectUri(REDIRECT_URI)
      .setCallbackFunction('authCallback')
      .setPropertyStore(PropertiesService.getUserProperties())
      .setScope('com.intuit.quickbooks.accounting')
      .setTokenHeaders({
        'Content-Type': 'application/x-www-form-urlencoded'
      });
}

I'm currently getting this error even though the URIs are the same in both ends.

Error message

The redirect_uri query parameter value is invalid. Make sure it is listed in the Redirect URIs section on your app's keys tab and matches it exactly. Click here to learn more about the redirect_uri query parameter.

Any suggestion? I've tried all possible configurations for the URI.

EDIT:

Solution: Use OAuth2.getRedirectUri()


Solution

  • Solution: Use OAuth2.getRedirectUri()