I'm trying to implement the Quickbooks API for Python, to generate invoices based on transactions, and send them to my quickbooks account. I'm using this python library for accessing the API, which is currently in version 0.5.1 and is available on PyPI. I'm having trouble connecting my application to Quickbooks Online.
I have created a developer account on Quickbooks, and have access to my app token, consumer key, and consumer secret. The guide on the library's github page, confuses me because, under "Connecting your application to Quickbooks Online", steps 1 and 2 seem related but somewhat independent of each other; mainly because of the re-initialization of the client variable.
Am I supposed to have multiple Quickbook objects named client, but re-initializing it throughout my code?
My code looks like this:
def create_invoice():
consumer_key = 'MY-CONSUMER-KEY'
consumer_secret = 'MY-CONSUMER-SECRET'
client = QuickBooks(
sandbox=True,
consumer_key=consumer_key,
consumer_secret=consumer_secret,
callback_url='https://sandbox-quickbooks.api.intuit.com',
)
authorize_url = client.get_authorize_url()
request_token = client.request_token
request_token_secret = client.request_token_secret
client = QuickBooks(
sandbox=True,
consumer_key=consumer_key,
consumer_secret=consumer_secret
)
client.authorize_url = authorize_url
client.request_token = request_token
client.request_token_secret = request_token_secret
client.set_up_service()
client.get_access_tokens(request.vars.oauth_verifier)
realm_id = request.vars.realmId
access_token = client.access_token
access_token_secret = client.access_token_secret
client = QuickBooks(
sandbox=True,
consumer_key=consumer_key,
consumer_secret=consumer_secret,
access_token=access_token,
access_token_secret=access_token_secret,
company_id=realm_id
)
invoice = Invoice()
line = SalesItemLine()
line.LineNum = 1
line.Description = "description"
line.Amount = 100
line.SalesItemLineDetail = SalesItemLineDetail()
item = Item.all(max_results=1, qb=client)[0]
line.SalesItemLineDetail.ItemRef = item.to_ref()
invoice.Line.append(line)
customer = Customer.all(max_results=1, qb=client)[0]
invoice.CustomerRef = customer.to_ref()
invoice.CustomerMemo = CustomerMemo()
invoice.CustomerMemo.value = "Customer Memo"
invoice.save(qb=client)
With this code I get the error:
KeyError: 'Decoder failed to handle oauth_token with data as returned by provider. A different decoder may be needed. Provider returned: oauth_problem=parameter_absent&oauth_parameters_absent=oauth_verifier'
Because I'm getting the error something has to be wrong, but I'm confused where to go now.