Companies Sub Service - Nioron07/Easy-Acumatica GitHub Wiki

This guide covers the CompaniesService, a specialized service for retrieving your organization's structure, including all companies and their associated branches.

1. Understanding the Service's Purpose

The CompaniesService provides a simple way to query the /CompaniesStructure endpoint. This is useful for administrative tasks or for integrations that need to be aware of the multi-company or multi-branch setup within your Acumatica instance.

2. Retrieving Company Structure

The service has one primary method for fetching this data.

get_structure(api_version)

This method retrieves a complete list of companies and their branches. It handles the API request, automatically expands the Results field from the endpoint, and returns it directly as a list.

Parameters

  • api_version (str): The API version segment (e.g., '24.200.001').

Returns

  • List[Dict[str, Any]]: A list of dictionaries, where each dictionary represents a company and contains details about its branches.

Example: Fetching and printing the company hierarchy

# 1. Call the get_structure method
try:
    company_hierarchy = client.companies.get_structure("24.200.001")

    # 2. Process and display the results
    print("--- Acumatica Company Hierarchy ---")
    for company in company_hierarchy:
        company_id = company.get('CompanyID', {}).get('value', 'N/A')
        print(f"\nCompany: {company_id}")

        branches = company.get('Branches', [])
        if not branches:
            print("  - No branches found for this company.")
            continue

        for branch in branches:
            branch_id = branch.get('BranchID', {}).get('value', 'N/A')
            print(f"  - Branch: {branch_id}")

except Exception as e:
    print(f"Failed to retrieve company structure: {e}")

# Expected Output:
#
# --- Acumatica Company Hierarchy ---
#
# Company: COMPANYA
#   - Branch: MAIN
#   - Branch: WAREHOUSE
#
# Company: COMPANYB
#   - Branch: HEADOFFICE