In this article, we will learn how to fetch access token from Quickbooks Online in ASP.NET MVC Web application using SDK.
if you didn’t know how to integrate Quickbooks online using SDK, then you can find it here.
public static string RealmId = ""; public static string Access_token = ""; public static string Refresh_token = ""; public static string clientid = ConfigurationManager.AppSettings["clientid"]; public static string clientsecret = ConfigurationManager.AppSettings["clientsecret"]; public static string redirectUrl = ConfigurationManager.AppSettings["redirectUrl"]; public static string environment = ConfigurationManager.AppSettings["appEnvironment"]; public static string QboBaseUrl = ConfigurationManager.AppSettings["QboBaseUrl"];
//Instantiate object public static OAuth2Client auth2Client = new OAuth2Client(clientid, clientsecret, redirectUrl, environment);
public ActionResult InitiateAuth() { List<OidcScopes> scopes = new List<OidcScopes>(); scopes.Add(OidcScopes.Accounting); string authorizeUrl = auth2Client.GetAuthorizationURL(scopes); return Redirect(authorizeUrl); }
public async Task<ActionResult> QboCallBack() { string code = Request.QueryString["code"] ?? "none"; string realmId = Request.QueryString["realmId"] ?? "none"; if (code != "none" && realmId != "none") { RealmId = realmId; var tokenResponse = await auth2Client.GetBearerTokenAsync(code); if (!string.IsNullOrWhiteSpace(tokenResponse.AccessToken)) { Access_token = tokenResponse.AccessToken; } if (!string.IsNullOrWhiteSpace(tokenResponse.RefreshToken)) { Refresh_token = tokenResponse.RefreshToken; } } return RedirectToAction("index", "Home"); }
Now we can use access token and realmId for using QuickBooks Online API and refresh token for refreshing/requesting a new access token.
I store access token, realmId and refresh token in global variables, we can store it in session, cookies or database according to your need, and then use it as needed for using QuickBooks Online API.
You can find the more detailed documentation here.
In this article, we have to show Create and Used PIPE in angular
In this article, we have to show Create and Used PIPE in angular
In this article, we have to show Create and Used PIPE in angular
View Comments
Thanks, this was very helpful!
what are the nuget libraries used in here?
you can use IppDotNetSdkForQuickBooksApiV3.
i wouldnot like to use OAuth2Client, so how to connect qbo
You have to use OAuth2Client for
1. Authorization using authOAuth 2.0
2. Access all Quickbooks API using SDK.
another option is authOAuth 1.0 but Quickbooks discontinued all support for OAuth 1.0. After December 17th, 2019.
You can try with Rest API instead of SDK