ej2 / python-quickbooks

A Python library for accessing the Quickbooks API.
MIT License
394 stars 193 forks source link

Help with programmatically accessing API without human interaction #312

Closed SantosJ1 closed 10 months ago

SantosJ1 commented 1 year ago

Hi everyone,

Sorry if this is the wrong place to ask this but I am frankly at my wits end. I am trying to write a simple script using python to access the QBO API and ingest data from my QBO companies into an AWS account. However, I am struggling to get the script to authenticate programmatically without manually logging in and creating a new "refresh" token every 100 days. Does anyone have any ideas how to accomplish this?

ZedObaia commented 1 year ago

According to the FAQ

We recommend you always store and use the latest access_token and refresh_token value from the most recent server response when you refresh access tokens. If the refresh token hasn’t been used in the last 100 days, meaning a user hasn’t connected to your app and thus no API calls have been made, the refresh token expires. Your app’s access to the QuickBooks company terminates. Users will need to sign in and authorize your app again.

Refresh tokens Refresh tokens are valid for 100 days. This expiry date is rolling and gets extended each time it’s used to refresh an access token. Refresh tokens are only for getting new access tokens. As long as the refresh token itself hasn’t expired, each time you refresh your access token, your app periodically updates the refresh_token value. This is for security. When you get a new refresh token, the previous refresh token value automatically expires.

Meaning, as long as your app is running and you store the latest refresh token, you should be fine. if your app is not always active, I would suggest to setup a cron job to run daily to refresh and store the latest tokens.