Reputation: 34884
Is there any way to find out what the duration of the access token is (when it's valid) in case I'm using https://appcenter.intuit.com/Playground/OAuth/IA or the amount of days left (180 days or less) in case I'm using their API from my client in, say, Python?
Upvotes: 0
Views: 139
Reputation: 4205
I am pretty sure you can't query for (I just quickly checked the docs again but anyone correct me if I am wrong) the token expiry.
When persisting the token make sure to record the created date. Next, establish a daily task to check if any of the tokens are approaching a 30 day expiry (set a criteria like 40 days until expiry). If the token hits that criteria call the API reconnect service.
Here is an example Cron rake task that you can adapt for Python.
task :renew_access_tokens => :environment do
range = (Time.now-175.days)..(Time.now-140.days)
accounts = Account.where(qbo_token_created_at: range)
accounts.each do |account|
response = Quickbooks::Base.new(account, :access_token).service.reconnect
account.qbo_token = response.token
account.qbo_secret = response.secret
account.qbo_token_created_at = Time.now
end
end
Upvotes: 1