Skip to content

QuickBooks Objects AuthorizationException in Production App (Works fine in Sandbox) #369

@EricZiola

Description

@EricZiola

Running this code from the documentation works perfectly in the sandbox, but throws an AuthorizationException when running in production workspace (I have verified that the client is authenticated properly) :

from quickbooks import QuickBooks
from quickbooks.objects import Vendor

# Initialize a QuickBooks client
client = QuickBooks(
    auth_client=auth_client,
    refresh_token=refresh_token,
    company_id=os.getenv("REALM_ID")
)

# Retrieve customers
customers = Customer.all(qb=client)
for customer in customers:
    print(customer)

AuthorizationException: QB Auth Exception 401: Application authentication failed

Accessing Wrong ClusterWrongClusterError: -11017-You have accessed the wrong server. You will now be redirected. , statusCode: 401"

This code works fine when I authenticate my client object in the sandbox workspace, all good there.

The code throws the above AuthorizationException when I authenticate the client to the production workspace.
I have confirmed that the client authorization is functioning properly by using the same access token to successfully perform a GET request manually to confirm authorization is functioning.

The following code receives a valid response from the server, confirming client authentication in production:

if ENVIRONMENT == "sandbox":    
    qb_base_url = "https://sandbox-quickbooks.api.intuit.com"
else:
    qb_base_url = "https://quickbooks.api.intuit.com"

headers = {
    "Authorization": f"Bearer {auth_client.access_token}",
    "Accept": "application/json"
}

select_statement = "SELECT * FROM Customer STARTPOSITION 1 MAXRESULTS 10"
select_url = f"{qb_base_url}/v3/company/{realm_id}/query?query={select_statement}"
response = requests.get(select_url, headers=headers, timeout=30)
pprint(response.json())

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions