Getting Unauthorize-401 Error.
I am working on QuickBooks Integration module .Everything working fine few days back on sandbox-US-company. Today I created new separate account for sandbox for testing purpose. For Older Account, Everything is going perfect .But for newly created account Unauthorize-401 issue is coming.
The steps I gone through follow, today: 1. Created account in developer.intuit.com/ 2. Under My App, Created new app for Accounting. 3. Under Sandbox, Added US Company. 4. From My Project, Hosted at my localhost .Done OAuth process to collect Access Token and Access Token Secret. 5. Now when I tried to get the list of Customer or (Other intuit object), Getting Unauthorize-401 Error.
Entire system of my project is perfectly working on the sandbox company created earlier. But for the today configured company, Unauthorize-401 Error is company.
Multiple links i Gone through ,But did't get rid of the issue facing, follows:
- Getting “Unauthorized-401” Error in .NET while accessing quickBooks data through Intuit API
- How to fix Unauthorized-401 error
- Unauthorized 401
In Advance, I thanks for getting me out from this issue.
CODE :
To Collect the DataService :
private DataService GetDataService()
{
try
{
string accessToken = AppSessions.QBAccessToken,
accessTokenSecret = AppSessions.QBAccessTokenSecret
, consumerKey = AppSessions.QBConsumerKey, consumerSecret = AppSessions.QBConsumerSecret
, realmId = AppSessions.QBCompanyCode;
OAuthRequestValidator oauthValidator = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);
var serviceType = IntuitServicesType.QBO;
var validator = new OAuthRequestValidator(accessToken, accessTokenSecret, consumerKey, consumerSecret);
var context = new ServiceContext(realmId, serviceType, validator);
context.IppConfiguration.BaseUrl.Qbo = AppSessions.IppConfigBaseURL;// "https://sandbox-quickbooks.api.intuit.com/";
return new DataService(context);
}
catch (Exception ex)
{
return null;
}
}
To Get the Customer List from Sandbox US Company :
public List<Customer> GetCustomer()
{
return service.FindAll(new NSQB.Customer(), StartPosition, MaxResult).ToList<NSQB.Customer>();
}
NOTE :
- I am using AppSessions static Class to Manage Session .
NSQB is alias for namespace used for QuickBook , i.e.
using NSQB = Intuit.Ipp.Data;
I discussed with Intuit Team .Quick-book System was in the Maintenance .
One of the response I Had over email by Quick-Books Team:
We had an outage today. Please retry. Do remember to change your base url to sandbox if you changed your prod keys to dev keys for testing with sandbox.
Outages cause 401 errors.
Maintenance Link they share about their Status Management.
Issue Still Exists !!
Your code looks fine; when there is a 401 error from QuickBooks Online, there can be two reasons:
What most developers didn't know is, when there is an outrage on sandbox server, the access token will be reset. It will result a previous working access token become invalid, i.e., the 401 error.
Here below are some steps I found very helpful when you see a 401 error: