Code Examples

Real-World Examples

Learn by example with practical, production-ready code snippets

Getting Started

Initializing the Client

Connect to your Acumatica instance and discover all available models and services

python
from easy_acumatica import AcumaticaClient

# Basic initialization
client = AcumaticaClient(
    base_url="https://your-instance.acumatica.com",
    username="api_user",
    password="secure_password",
    tenant="Company",
    branch="MAIN"
)

# The client automatically discovers all available models and services
print(f"Connected to: {client.base_url}")
print(f"Available services: {[attr for attr in dir(client) if not attr.startswith('_')]}")
print(f"Available models: {dir(client.models)}")
Service Operations

Calling Services

Use dynamically generated services to interact with your Acumatica data

Reading Data
python
# Get a single record by ID
customer = client.customers.get_by_id("ABCCOMP")
print(f"Customer: {customer.CustomerName}")
print(f"Balance: {customer.Balance}")

# Get multiple records
from easy_acumatica import QueryOptions

options = QueryOptions(top=10)
customers = client.customers.get_list(options)

for customer in customers:
    print(f"{customer.CustomerID}: {customer.CustomerName}")
Creating Records
python
# Create a new customer
new_customer = client.models.Customer(
    CustomerID="NEWCUST01",
    CustomerName="New Customer Inc.",
    CustomerClass="DEFAULT",
    Status="Active",
    MainContact={
        "Email": {"value": "contact@newcustomer.com"},
        "Phone1": {"value": "555-0100"}
    }
)

# Save to Acumatica
created = client.customers.put_entity(new_customer)
print(f"Created customer: {created.CustomerID}")
Updating Records
python
# Update an existing record
# Method 1: Fetch, modify, save
customer = client.customers.get_by_id("CUST001")
customer.CreditLimit = 50000
customer.Terms = "30D"

updated = client.customers.put_entity(customer)

# Method 2: Update specific fields only
update = client.models.Customer(
    id=customer.id,  # Use the internal ID
    CreditLimit=75000
)
updated = client.customers.put_entity(update)
Deleting Records
python
# Delete a record by ID
try:
    client.customers.delete_by_id("OLDCUST01")
    print("Customer deleted successfully")
except AcumaticaNotFoundError:
    print("Customer not found")
except AcumaticaAPIError as e:
    print(f"Delete failed: {e.message}")
Data Models

Building Models

Work with strongly-typed, auto-generated models that match your Acumatica instance

python
# Creating a simple model instance
bill = client.models.Bill(
    Type="Bill",
    Vendor="VENDOR01",
    Date="2024-01-15",
    Description="Office supplies",
    Amount=1250.00
)

# All fields are optional and type-hinted
invoice = client.models.Invoice(
    Customer="CUST001",
    Date="2024-01-20"
    # Other fields will use defaults
)
Generic Inquiries

Calling Generic Inquiries

Access your custom Generic Inquiries with auto-generated methods

Basic Inquiry Call
python
# Call a generic inquiry - methods are auto-generated
# from your instance's Generic Inquiries

# Simple inquiry call
results = client.inquiries.Account_Details()

# Process the results
for account in results['value']:
    print(f"Account: {account['AccountID']['value']}")
    print(f"Balance: {account['Balance']['value']}")

# Another inquiry
customer_list = client.inquiries.Customer_List()
for customer in customer_list['value']:
    print(customer['CustomerName']['value'])
Inquiry with Filters
python
from easy_acumatica import QueryOptions, F

# Generic inquiries support full OData operations
options = QueryOptions(
    filter=F.Balance > 10000,
    orderby="Balance desc",
    top=20
)

# Apply filters to inquiry
results = client.inquiries.Account_Details(options=options)

# Complex filtering on inquiry
options = QueryOptions(
    filter=(
        (F.AccountType == "Asset") & 
        (F.IsActive == True) &
        (F.Balance != 0)
    ),
    select=["AccountID", "AccountName", "Balance"],
    orderby=["AccountType", "AccountID"]
)

filtered_accounts = client.inquiries.Account_Summary(options=options)
OData Queries

Building Filters & QueryOptions

Create powerful, type-safe OData queries with the F factory and QueryOptions

Filter Examples
python
from easy_acumatica import F

# Basic equality
filter1 = F.CustomerID == "ABCCOMP"

# Comparison operators
filter2 = F.Balance > 1000
filter3 = F.DueDate <= "2024-12-31"
filter4 = F.Status != "Cancelled"

# Null checks
filter5 = F.DeletedDate == None
filter6 = F.Email != None

# Combining filters
combined = (F.Status == "Active") & (F.Balance > 0)
QueryOptions Examples
python
from easy_acumatica import QueryOptions, F

# Basic QueryOptions
options = QueryOptions(
    top=10,
    skip=0,
    orderby="CustomerName"
)

# With selection
options = QueryOptions(
    select=["CustomerID", "CustomerName", "Balance"],
    top=50
)

# With filter
options = QueryOptions(
    filter=F.Status == "Active",
    orderby="Balance desc"
)
Complete Examples

Full Workflow Examples

End-to-end examples showing complete integration patterns