Unauthorize-401 Error ,QuickBooks

2.6k Views Asked by At

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:

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 !!

1

There are 1 best solutions below

1
On BEST ANSWER

Your code looks fine; when there is a 401 error from QuickBooks Online, there can be two reasons:

  1. The access token is invalid;
  2. The sandbox server is having a problem.

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:

  1. Go to Intuit's status page: http://status.developer.intuit.com/ and see if there is any issue with Sandbox server
  2. If you believe the sandbox is not available, go to API explorer: https://developer.intuit.com/v2/apiexplorer?apiname=V3QBO#?id=Account and see if it worked
  3. Try POSTMAN(or simple cUrl), adding the access token, access secrets, consumer secrets and consumer key and make a sample call to see if it can goes through(make sure it is pointing to the sandbox url).
  4. If it didn't go through, and a 401 status code is returned, regenerate the access tokens. The best way to do it for sandbox is using the OAuth Playground. In the dashboard in your app, there is a link called "Test with OAuth Playground and OpenID Playground". Click on the OAuth Playground, change the access token duration from 120 to 15552000 and complete the OAuth flow. Now a new token will be available for you to test.
  5. If neither above works, create a ticket for intuit QuickBooks Online team.