Business Accounts Service - Nioron07/Easy-Acumatica GitHub Wiki

This guide covers the BusinessAccountsService, which is your primary tool for retrieving business account records through the contract-based API.

1. Importing Helpers

Before you start, import the necessary query helpers. The BusinessAccountsService method relies on this to define query parameters.

from easy_acumatica.models.query_builder import QueryOptions
from easy_acumatica.models.filter_builder import F

2. Understanding the Service's Purpose

The BusinessAccountsService provides a method for retrieving business accounts, which can include customers, vendors, and combined customer/vendor records.

3. BusinessAccountsService Methods

The following table summarizes the primary method available in the BusinessAccountsService.

Method Description Key Parameters
.get_business_accounts() Retrieves a list of business accounts based on query options. api_version, options

4. Retrieving Business Accounts

The primary function of this service is to query for existing business accounts.

get_business_accounts(api_version, options)

This method retrieves a list of business accounts. You must use QueryOptions to filter, select, and expand the results. To retrieve a single account, you must filter by its BusinessAccountID.

Example 1: Get a list of all active vendor accounts

# 1. Define query options
query = (
    QueryOptions()
    .filter("Status eq 'Active' and Type eq 'Vendor'")
    .select("BusinessAccountID", "BusinessAccountName", "Status")
)

# 2. Retrieve the business accounts
try:
    vendors = client.business_accounts.get_business_accounts("24.200.001", options=query)
    for vendor in vendors:
        print(f"ID: {vendor['BusinessAccountID']['value']}, Name: {vendor['BusinessAccountName']['value']}")
except Exception as e:
    print(f"Failed to get business accounts: {e}")

Example 2: Get a single, specific business account by its ID

# 1. Define query options to filter by the specific ID
query = QueryOptions(filter=F.BusinessAccountID == "000001", expand=["MainContact"])

# 2. Retrieve the specific account
try:
    accounts = client.business_accounts.get_business_accounts("24.200.001", options=query)
    if accounts:
        # The result is a list, so we take the first item
        account = accounts[0]
        print(f"Retrieved Account: {account['BusinessAccountName']['value']}")
    else:
        print("Account not found.")
except Exception as e:
    print(f"Failed to get specific business account: {e}")