I'm currently working on building an application for QuickBooks that allows users to get data from their QuickBooks account simply using natural language. In the few weeks I've been working on this project, I've had to familiarize myself with some tools I've never used before, and structure my approach to building the application. In the time I've spent working on this app, I've spent time using the QuickBooks API, Flask, LangChain, and OpenAI API. Furthermore, working on this project has allowed me to further develop my ability to approach my work in a structured way, such as defining the scope of my project, setting goals, and tracking my progress.
I used the Intuit OAuth2 Python Client SDK provided by Intuit themselves to interact with its API. The official documentation can be found here: https://oauth-pythonclient.readthedocs.io/en/latest/user-guide.html. In a nutshell, the library allows the app to direct the user to the authentication page, retrieves the access tokens and information identifying the user's company, and fetches the data from QuickBooks.
Combined with the Python web framework Flask, I built a basic web page that I could use to test the functionality of the app. I used Flask to handle my app's routing. This is done by using Flask's route() decorator:
@app.route("/")
def hello_world():
return "<p>Hello, World!</p>"
In this example, when the user navigates to the root directory of the application the hello_world() function will be executed, and "Hello, World!" will print on the user's screen.
Finally, I used LangChain and the OpenAI API to enable the application to take in a natural language input to generate the right query and obtain the data the user wants. Because of the way the QuickBooks API is structured, this was a multi-step process.
The QuickBooks API query language is similar to SQL, only that it does not offer the same complexity that SQL does, meaning the queries that can be used to get data from QuickBooks is limited. Because of this, I designed the app to first fetch the entire data table that is needed in its json format, then extract the desired data from the json itself, instead of getting all of the data in one query. Here is the documentation for the QuickBooks query operations: https://developer.intuit.com/app/developer/qbo/docs/learn/explore-the-quickbooks-online-api/data-queries.
To incorporate natural language to generate the query, I used LangChain's OpenAI library to have OpenAI's gpt-4o model to extract the desired entity from the natural language query, then used that to query the QuickBooks API. Because the json file that is obtained from the API is very messy I convert it into a simpler dataframe using Pandas. My next objective is to now use the natural language input to query the desired data from the simplified dataframe.