Integrate QuickBooks Online To KRA eTIMS

QuickBooks Online is a powerful, cloud-based accounting software built for small businesses, freelancers, and entrepreneurs to easily manage their finances. In light of the requirement by KRA for businesses to be compliant with eTIMS, below are the steps one can follow when integrating the QuickBooks Online account:  

 

Step One

  • Navigate to the Intuit Developer Section.
  • Create an App.
  • Set up a valid redirect URI in your App settings.
 

We’ve published a GitHub repository that includes method definitions for obtaining the Authorization Code after your App has been set up. The getAuthCode function will return a URL which you can open using your browser

    def getAuthCode(self):
        params = {
            "client_id" : CLIENT_ID,
            "redirect_uri" : REDIRECT_URI,
            "response_type" : "code",
            "scope" : "com.intuit.quickbooks.accounting",
            "state" : "15874"
        }
        return "https://appcenter.intuit.com/connect/oauth2?" + urllib.parse.urlencode(params)
        
        #The method will return a URL i.e http://localhost/quickbooks/?code={Authorization Code}&state={State}&realmId={CompanyID}
QuickBooks Online Authorization Screen

Select the Connect option, this action will result in the browser redirecting to the redirect link you had set.

Step Two

We would need to exchange the Authorization Code for the Access Token.

    def getTokens(self):
        token_url = OAUTH_URL+"/oauth2/v1/tokens/bearer"
        auth = base64.b64encode(f"{CLIENT_ID}:{CLIENT_SECRET}".encode()).decode()

        headers = {
            "Authorization": f"Basic {auth}",
            "Content-Type": CONTENT_TYPE_FORM_URL_ENCODED
        }

        data = {
            "grant_type": "authorization_code",
            "code": AUTHORIZATION_CODE,
            "redirect_uri": REDIRECT_URI
        }

        response = requests.post(token_url, headers=headers, data=data)
        return response.json()

 

Step Three

With the Access Token, we can then proceed to getting the sales transactions.

    def getSalesReceipts(self, accessToken, companyID, maxResults):
        url = f"{SANDBOX_URL}company/{companyID}/query"
        headers = {
            "Authorization": f"Bearer {accessToken}",
            "Accept": "application/json",
            "Content-Type": CONTENT_TYPE_TEXT
        }

        query = "SELECT * FROM SalesReceipt ORDERBY TxnDate DESC MAXRESULTS "+maxResults
        response = requests.get(url, headers=headers, params={"query": query})
        return response.json()

 

Step Four

The result of Step Three above can then be submitted to our KRA Agent App which would then handle the submission to KRA eTIMS.

 

Github

Find the full codebase on Github

 

Symatech Labs is a Software Development company based in Nairobi, Kenya that specializes in Software Development, Mobile App Development, Web Application Development, Integrations, USSD and Consultancy.