A few days back I was contacted by someone who wanted to get notified on Slack about new invoices created in Quickbooks online. In this post I am going to share how one can harness the power of Zapier to get notified on Slack about changes in Quickbooks. The work is done in Python.
I am going to use sample invoices that I made on Quickbooks online.
Before I move further, let me tell you about Quickbooks, Slack and Zapier.
What is Quickbooks?
Quickbooks is an online accounting software for small businesses which provides features like Invoice Management, Payroll Management, Inventory and a few others. Since it’s a SAAS based app so you use their services based on what you pay and available everywhere as long as you’re connected.
What is Slack?
Slack is a real time B2B messaging platforms that offers the concepts of teams and channels. You can share literally anything here. It has gain quite a popularity due to it’s sleek and enjoyable interface that brings colors in boring thing like a messaging platform.
What is Zapier?
If you have used IFTTT then Zapier should not be something alien for you. Zapier is an automation platform which provides easy to use interface to connecting different services and apps with help of triggers and action.
All these platforms provide APIs. If you want you can eliminate Zapier at all and can still achieve what we will achieve now. The advantage Zapier provides that it has already done all heavy lifting that’s required. Things like dealing with OAuth and other internals are usually catered by Zapier and being an end-user or even a developer one does not need to get worried about inner implementation as it’s totally abstract from you. Since Zapier is a platform, you can connect any other service later without worrying about coding implementation since you are going to use a single end-point, the Zapier API to connect your datasource.
First off, I created a few sample invoices as QBO(QuickBooks) is the datasource and we need to send this data to Slack via Zapier. Instead of scraping I am going to use QBO’s APIs. QBO’s APIs are REST APIs means you can use them in any language. After success oAuth it let you perform various actions given on platform. I am using Python and fortunately some kind soul made a wrapper of it, I just used it to access QBO. Why shouldn’t when all heavy lifting has already been done by the library 🙂
Like many platforms QBO also gives concept of creating Apps to interact with their platforms. Once you are registered and get access to the developer account, you can create a new App. It will provide you both development and production keys. Development keys only work with sandbox companies while production one work with your actual company created in Quickbooks. Since this is a command line script I needed access token already generated, at least for first time. Quickbooks provide OAuth Playground where you can authorize any app and get access token for a certain duration(max 6 months). There’s another awesome tool, Quickbooks API Explorer. If you already have created a company it will appear in the dropdown given on top. Since my task is to pull data and for that purpose their Query API works well. It provides an SQL like syntax to pull data.
Assuming you have installed Python Quickbooks library, below is the sample code to pull invoices.
from quickbooks import * CLIENT_KEY = "xxxx" CLIENT_SECRET = "xxx" REQUEST_TOKEN = 'xxx' REQUEST_TOKEN_PASSWORD = 'xxx' COMPANY_ID = 12345678910 def pull_invoice(client_key, client_secret, token, secret, company_id): try: client = QuickBooks( sandbox=False, consumer_key=client_key, consumer_secret=client_secret, access_token=token, access_token_secret=secret, company_id=company_id, minorversion=4 ) query = "SELECT * from invoice" result = client.query(query) data = result['QueryResponse'] total = data['totalCount'] invoices = data['Invoice'] for invoice in invoices: print(invoice) except Exception as ex: print(str(ex)) if __name__ == '__main__': # print() pull_invoice(CLIENT_KEY, CLIENT_SECRET, REQUEST_TOKEN, REQUEST_TOKEN_PASSWORD, COMPANY_ID)
After success authentication client queries invoices and returns in
dict format which you later can transform into JSON(Zapier prefers JSON format)
Ok QBO’s part is done. Actually, what I have not covered how to store the data fetched, stored in a database and present in form of REST URI to show data of individual invoices. You can use any technology here even PHP.
Now head on to Zapier part, Zapier also provided developer interface to interact with their platforms. You will create an App here as well which will later be used by your Zap(the Zap script).
First you will set fields of authentication. Instead of Oauth or Basic Authentication I preferred the default option that is No Auth Needed.
Next, to set triggers. I provided Basic Info and then assign the source for data pulling. You also need to provide sample results, just like I did below:
As you can see I provide a JSON Object. The interface then parse these fields and show when you are going to create a new Zap. Since this Zap was supposed to be used internally, the app remained private.
Creating a new Zap
Now time has come to test the entire integration via a Zap, the script that connects two apps or services. First I set an app for the trigger, it is none other than the app I just created. Do remember this is to pull data.
Next is setting destination app in Action section, in this step you push the data you pulled earlier in Trigger section. The idea is to auto pull latest invoice data after certain period and push as a message on a Slack channel. You can tell Zapier in which format your message should appear in the message template. Do notice the fields you had set while mapping fields in Sample Data section.
Test it and if all goes well you should be able to see something like this on your designated Slack channel:
This is first time I used all these platforms as a developer. I really loved how Zapier can integrate multiple platforms to automate various processes. Checkout various apps already there in their marketplace. It does not matter you’re an individual or a business, Zapier let you to utilize their platform to automate your tasks.