The Pythonic Way of Accounting: Sage Intacct SDK for Python
Fyle's Sage Intacct SDK provides an intuitive way of integrating with Sage Intacct, making the process a breeze.
Introduction
Hello everyone, my name is Ashwin and I joined Fyle as an intern back in May 2019. It feels like a long time ago now 😛 At that time, I still had two years left to complete my college education. During my internship with Team Integrations, I was given the challenge of building an integration with Sage Intacct. Initially, I started by experimenting with a Python script and once we gained more knowledge about Sage Intacct APIs, we progressed towards building our own SDK. In this blog, I'll share the process and benefits of creating the Sage Intacct SDK.
Sage Intacct is a cloud-based financial management software for small and mid-sized businesses. It provides features for accounting, financial reporting, and analytics. Sage Intacct also integrates with other software solutions to streamline business processes.
Where does Fyle come into the picture?
Fyle integrates with Sage Intacct to streamline the process of managing expenses and accounting. The integration enables businesses to automatically sync expense data between Fyle and Sage Intacct, eliminating the need for manual data entry and reducing errors.
Why did we build an SDK?
Building SDK simplifies the process of integrating with Sage Intacct, allowing developers to focus on building solutions directly rather than dealing with the complexities of the software's API and reducing the learning curve.
Also, Sage Intacct does not have an official SDK for Python. We’ve open-sourced the SDK and it eases building integrations with Sage Intacct and also allows developers to contribute to the SDK's development and improvement.
How does it look to Integrate with Sage Intacct without this SDK?
Integrating with Sage Intacct without a dedicated SDK can be challenging in a few aspects. This can be time-consuming and complex, especially for developers who are not familiar with the intricacies of the Sage Intacct API.
Developers need to understand the API documentation and manually construct API requests and parse responses. They also need to handle authentication and error handling, which can be tedious and error-prone.
Also, Sage Intacct's API is based on XML, which is not as commonly used as other data interchange formats such as JSON.
I’ll add one example to create an Employee in Sage Intacct
To authenticate with Sage Intacct's API and establish a session, we need to send our API credentials (a few IDs, passwords, etc). The response will include a session key that we can use in subsequent requests to identify and authorize the session.
curl -X POST \\
'<https://api.intacct.com/ia/xml/xmlgw.phtml>' \\
-H 'Content-Type: application/xml' \\
-d '<?xml version="1.0" encoding="UTF-8"?>
<request>
<control>
<uniqueid>false</uniqueid>
<dtdversion>3.0</dtdversion>
<includewhitespace>false</includewhitespace>
</control>
<operation transaction="false">
<authentication>
<sessionid>{0}</sessionid>
</authentication>
<content>
<function controlid="test">
<getAPISession/>
</function>
</content>
</operation>
</request>
'
This is how the payload would look like
<request>
<control>...</control>
<operation>
<authentication>...</authentication>
<content>
<function controlid="XYZ">
<create>
<EMPLOYEE>
<PERSONALINFO>
<CONTACTNAME>John Smith</CONTACTNAME>
</PERSONALINFO>
<EMPLOYEEID>E1234</EMPLOYEEID>
<LOCATIONID>L1234</LOCATIONID>
<DEPARTMENTID>D1234</DEPARTMENTID>
</EMPLOYEE>
</create>
</function>
</content>
</operation>
</request>
The response we receive will also be in XML format.
Interacting with the help of our SDK
With the SDK, developers can use pre-built functions and objects to interact with Sage Intacct's API, rather than manually constructing API requests and parsing responses. The SDK also handles authentication and error handling, which reduces the risk of errors and improves the overall reliability of the integration.
We’ll do the same operation that we did previously, but with the SDK involvement now
sage_intacct_connection = SageIntacctSDK(
sender_id='XYZ',
sender_password='XYZ',
user_id='XYZ',
company_id='XYZ',
user_password='XYZ'
)
employee_payload = {
'PERSONALINFO': {
'CONTACTNAME': 'John Smith'
},
'EMPLOYEEID': 'E1234',
'LOCATIONID': 'L1234',
'DEPARTMENTID': 'D1234'
}
sage_intacct_connection.employees.post(employee_payload)
As simple as it looks
Few more examples where it makes our lives easy
Search with a single filter
sage_intacct_connection.expense_reports.get('RECORDID', '4236')
Search by add / or filters
query_tuple_multiple =[('equalto', 'LIABILITYTYPE', 'Credit'), ('equalto', 'STATUS', 'active')]
sage_intacct_connection.charge_card_accounts.get_by_query(and_filter=query_tuple_multiple)
Get only requested fields
sage_intacct_connection.charge_card_accounts.get('RECORDNO', 5, fields=['RECORDNO', 'STATUS', 'EXP_YEAR', 'MAILADDRESS.COUNTRY'])
Get all data for a resource
sage_intacct_connection.tasks.get_all()
Send raw custom queries
raw_query = {
'query': {
'object': 'CREDITCARD',
'select': [
{
'field': 'RECORDNO'
}
],
'filter': {
'and': {
'equalto': [
{
'field': 'LIABILITYTYPE',
'value': 'Credit'
}
],
'or': {
'equalto': [
{
'field': 'RECORDNO',
'value': '6'
},
{
'field': 'STATUS',
'value': 'active'
}
]
}
}
}
}
}
sage_intacct_connection.api_base.format_and_send_request(raw_query)
How easy it is to contribute to our SDK?
Contributing to our SDK should be relatively easy if you know slightly about Sage Intacct APIs and obviously a bit of Python.
Let’s consider you want to add support for “Location Groups” (API doc)
First, you would create a new file named
location_groups.py
in thesageintacctsdk/apis
folderThen, you would create a class called
LocationGroups
that inherits from theApiBase
class which has all helper methods to do the post, search, filter etcWhen initializing the
ApiBase
class, you would pass in the dimension name for location groups, which in this case isLOCATIONGROUP
Then, export this class in
sageintacctsdk/apis/__init.py
and also reference the newly created class in the base file (sageintacctsdk.py
)Finally, you would export the
LocationGroups
class insageintacctsdk/apis/__init__.py
and reference it in the mainsageintacctsdk.py
file.With these steps complete, your new API support will be integrated into the SDK
Once you have made your changes to the SDK, you can submit a pull request (PR) to our repository on GitHub. In the PR, be sure to describe the changes you have made and any relevant context or reasoning behind those changes.
Our team will review the PR as quickly as possible and merge it into the master branch if everything looks good. Once the changes are merged, we will release the updated SDK to PyPI for all users to access.
Summary
To summarize, our SDK has been downloaded approximately 70,000 times to date and has been used in production at Fyle for three years, with great success. We currently have a total of 13 contributors, including members of the Fyle team.
If you're interested, you can check out our repository at the following link: https://github.com/fylein/sageintacct-sdk-py. We welcome contributions and would be happy to answer any questions. Feel free to reach out to me at ashwin.t@fylehq.com in case you have any doubts/questions/suggestions.