I'd like to reach out to Quickbooks within my application to create some invoices. I can do this when I go generate a temporary AccessToken and AccessTokenSecret but those expire. How can I reliably and repeatedly make calls to the Quickbooks API?
Note: The "user" accessing the data from my application can be considered "system". I am using the Quickbooks API to simply streamline/automate a personal workflow.
string accessToken = "temporaryAccessToken"; //this expires
string accessTokenSecret = "temporaryAccessTokenSecret"; //this expires
string consumerKey = "myConsumerKey";
string consumerSecret = "myConsumerSecret";
m_OAuthRequestValidator = new OAuthRequestValidator(
accessToken, accessTokenSecret, consumerKey, consumerSecret);
string appToken = "myAppToken";
string companyID = "myCompanyID";
ServiceContext context = new ServiceContext(appToken, companyID, IntuitServicesType.QBD, m_OAuthRequestValidator);
DataService service = new DataService(context);
var customer = new Customer();
customer.GivenName = "Scout";
customer.FamilyName = "Berman";
Customer resultCustomer = service.Add(customer) as Customer;
This is documented in detail in Intuit's documentation.
You basically have two options:
1. If you're building a SaaS app:
Read the section about implementing OAuth in your application. It's vanilla OAuth with a couple of button widgets added to push Intuit's brand on people.
Basically, you embed a javascript script
tag in your header which pulls in Intuit's Javascript libraries, add a call to Intuit's Javascript setup()
method, and put a custom HTML tag in your web page. This gets you a nice pretty "Connect to QuickBooks" button.
When you click that button, it kicks off a standard OAuth process which gets you a long-lived (6 months) access token. Store the tokens in your app so that you can make calls at any time using these OAuth tokens.
2. If you're just building a one-off for your personal use:
You can get a 6-month token by using Intuit's playground tool:
In either situation:
You can make a REST API call to renew the token within 30 days of it's expiration date (e.g. you can just keep extending it to keep it valid forever and ever).