'Python QuickBooks API
I have a problem working with python-quickbooks package, I try to follow the docs: https://pypi.org/project/python-quickbooks/
Here is my code:
from django.conf import settings
from intuitlib.client import AuthClient
from quickbooks import QuickBooks
from quickbooks.objects.account import Account
auth_client = AuthClient(
client_id=settings.QUICKBOOKS_CLIENT_ID,
client_secret=settings.QUICKBOOKS_CLIENT_SECRET,
environment='sandbox',
redirect_uri=settings.QUICKBOOKS_REDIRECT_URI,
)
client = QuickBooks(
auth_client=auth_client,
refresh_token=settings.QUICKBOOKS_REFRESH_TOKEN,
company_id=settings.QUICKBOOKS_REALM_ID
)
account = Account()
account.from_json(
{
"AccountType": "Accounts Receivable",
"Name": "MyJobs"
}
)
account.save(qb=client)
However, this results in error:
What am I doing wrong here?
Solution 1:[1]
You have to provide ACCESS_TOKEN in AuthClient.
In order to get an access token, you have to pass authorization. You can check details about the authorization process here https://developer.intuit.com/app/developer/qbo/docs/develop/authentication-and-authorization/oauth-2.0-playground
Also here is a repo with an example of how to use AuthClient: https://github.com/IntuitDeveloper/SampleOAuth2_UsingPythonClient
from intuitlib.client import AuthClient
from quickbooks.client import QuickBooks, Environments
auth_client = AuthClient(CLIENT_ID, CLIENT_SECRET, REDIRECT_URL, Environments.SANDBOX, ACCESS_TOKEN)
qbo_client = QuickBooks(
auth_client=auth_client,
refresh_token=REFRESH_TOKEN,
company_id=REALM_ID,
)
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | maden-maxi |