chronox
chronox

Reputation: 117

Django: Pulling data from Quickbooks Online and Storing it into MySQL database

I recently have a Django project that requires me to pull data from Quickbooks Online and then storing it in MySQL database for later uses.

Following a tutorial that I found in https://github.com/sidecars/python-quickbooks, I was able to get my access and refresh token using

quickbooks-cli -p 8000 <Client ID> <Client Secret> 2

Here come a few questions I like to ask:

  1. Is there any implications setting http://localhost:8000 as one of my Redirect URIs in the Intuit Developer's Key section?
  2. What should I do with the access and refresh token? I think I need to continue from the "Accessing the API" section in https://github.com/sidecars/python-quickbooks but I have no idea which files to put the code mentioned in the documentation (I do not touch API in the past so some guidance is appreciated)
  3. I noticed there is a duration before the access and refresh token expires, so does it mean I have to change them every once in a while?

Thanks in advance.

Upvotes: 0

Views: 1157

Answers (1)

Keith Palmer Jr.
Keith Palmer Jr.

Reputation: 27982

Is there any implications setting http://localhost:8000 as one of my Redirect URIs in the Intuit Developer's Key section?

You won't be able to go live with that set (Intuit won't let you). But for development, it's fine.

Eventually you should swap that out for your production URL.

What should I do with the access and refresh token?

Here's what the docs you linked to them say:

  • "Store access_token and refresh_token for later use."

Also, you'll need to use the access token to access data via the API. From the docs:

session_manager = Oauth2SessionManager(
    client_id=realm_id,
    client_secret=CLIENT_SECRET,
    access_token=AUTH2_ACCESS_TOKEN,
)

from quickbooks import QuickBooks

 client = QuickBooks(
     sandbox=True,
     session_manager=session_manager,
     company_id=realm_id
 )

from quickbooks.objects.customer import Customer
customers = Customer.all(qb=client)

This is shown in the docs here: https://github.com/sidecars/python-quickbooks#accessing-the-api

I noticed there is a duration before the access and refresh token expires, so does it mean I have to change them every once in a while?

You have to refresh them, yes:

session_manager = Oauth2SessionManager(
       client_id=QUICKBOOKS_CLIENT_ID,
       client_secret=QUICKBOOKS_CLIENT_SECRET,
       base_url=callback_url,
   )

session_manager.refresh_access_token()

From the docs here: https://github.com/sidecars/python-quickbooks#refreshing-access-token

Upvotes: 1

Related Questions