Sync expenses
Your user authorizes your application to access their accounting service (e.g., QuickBooks Online, NetSuite) via an OAuth or similar authorization flow through Merge Link.
When creating expenses, you must specify the bank/debit/credit card account that the money is coming out of. This is the account(s) in your product! Before you can start syncing expenses over to your customer’s accounting application, you’ll need to identify which general ledger account represents your product’s account(s).
You’ll most likely be creating the account(s) through the POST /accounts endpoint for new customers. That said, you may have customers who have been using your product without direct API-based integrations. These customers will have already manually created a general ledger account for your product. So, you should first see if your customer has already created the account by either asking them in your UI or making a request to the GET /accounts endpoint to try to identify the account programmatically.
Once you’ve either created the account via POST /accounts or identified the account via GET /accounts, you’ll want to store the id
of the account to use when you create expenses!
The following steps will cover the business logic you will need to configure in your backend to interact with Merge’s Unified API.
“Settings” or “Master” data refers to all information related to vendors, accounts, and (in some cases) tracking categories. To do this, we will access four endpoints:
- The most important part of classifying an expense is the General Ledger account associated with the expense! You’ll use the GET /accounts endpoint to fetch all accounts set up in your customer's accounting platform.
- You may want to limit the options you show to your customer based on the
id
of the account. For instance, it may not make sense to showASSET
accounts as a way to classify an expense! - Follow the steps outlined in the “Sync Customers or Suppliers” use case to sync vendors in your system with the third party.
- If your customer has classes, locations, or departments configured, you can retrieve them from the accounting platform with GET /Tracking Categories.
Based on the data retrieved through the prior step, allow your customer to set configure rules related to the categorization of Expenses you’ll sync. How you configure these rules is up to you and will depend on your product!
- Your customers may only ever want to sync Expenses against a single General Ledger Account, in which case you could build a dropdown in your Settings page to select the Account.
- Your customer may want to categorize transactions based on conditional logic, such as If Location = New York, use XYZ Account. In this case you’ll want to build a more complex UI that allows your customer to configure these rules!
- Or your customer may want to categorize the transaction when they sync it to their Accounting, in which case you don’t need to build anything into your Settings page.
When your customer initiates spend-related transactions in your platform, such as credit card transactions or travel expenses, you’ll now be able to send them to your customer’s Accounting application with the correct classification via the POST /expenses endpoint.
You can either send these transactions automatically or have an admin manually initiate the sync from within your app.
After the initial pull of data, you’ll need to keep your settings data up to date by regularly fetching data from Merge. The modified_after
query parameter can be utilized on all of Merge’s GET endpoints to keep these subsequent processes more efficient. For a full overview of Merge’s syncing best practices, see our guide here!