CLI Examples ============ This section provides practical examples of using the ABConnect command-line interface. .. contents:: :local: :depth: 2 Quick Start Examples -------------------- Basic Commands ~~~~~~~~~~~~~~ .. code-block:: bash # Get your user profile ab me # Look up company types ab lookup company-types # Search for companies ab api raw GET /companies/search --params '{"page": 1, "per_page": 20}' # Get company by ID ab company 12345 Working with Companies ---------------------- Search and Filter ~~~~~~~~~~~~~~~~~ .. code-block:: bash # Search companies by name ab api raw GET /companies/search --params '{"name": "ABC Corp", "active": true}' # Get company details ab api raw GET /companies/12345/details # Get company setup data ab api raw GET /company/12345/setupdata Managing Contacts ~~~~~~~~~~~~~~~~~ .. code-block:: bash # Search contacts for a company ab api raw GET /contacts/search --params '{"companyId": "12345"}' # Create new contact ab api raw POST /contacts --data '{ "firstName": "John", "lastName": "Doe", "email": "john.doe@example.com", "companyId": "12345" }' # Update contact ab api raw PUT /contacts/67890 --data '{"phone": "+1-555-123-4567"}' Working with Jobs ----------------- Job Operations ~~~~~~~~~~~~~~ .. code-block:: bash # Get job details ab api raw GET /job/JOB-2024-001 # Get job timeline ab api raw GET /job/JOB-2024-001/timeline # Update job status ab api raw POST /job/JOB-2024-001/status/quote --data '{"status": "Quoted"}' Creating Jobs ~~~~~~~~~~~~~ .. code-block:: bash # Create a new job (save data in a file for complex requests) cat > job_data.json << EOF { "type": "Standard", "customerId": "CUST123", "origin": { "address": "123 Main St", "city": "New York", "state": "NY", "zip": "10001" }, "destination": { "address": "456 Oak Ave", "city": "Los Angeles", "state": "CA", "zip": "90001" } } EOF ab api raw POST /job/save --data @job_data.json Lookup Operations ----------------- Master Constants ~~~~~~~~~~~~~~~~ .. code-block:: bash # Get all available lookup types ab endpoints --filter lookup # Common lookup operations ab lookup company-types ab lookup job-status-types ab lookup freight-types ab lookup container-types # Output as JSON for processing ab lookup company-types --format json > company_types.json # Pretty print JSON output ab lookup company-types --format json | jq '.' File Operations --------------- Loading and Processing Files ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: bash # Load and display CSV file ab load contacts.csv # Load Excel file with specific sheet ab load sales_report.xlsx --sheet "Q1 Sales" # Convert CSV to JSON ab load data.csv --format json > data.json # Preview first few rows ab load large_file.csv --limit 10 # Specify encoding for problematic files ab load legacy_data.csv --encoding latin-1 Quote Operations ---------------- Getting Quotes ~~~~~~~~~~~~~~ .. code-block:: bash # Quick quote with basic parameters ab quote qq \ --customer CUST123 \ --origin-zip 10001 \ --destination-zip 90001 \ --weight 1000 \ --pieces 5 # Quote request from file cat > quote_request.json << EOF { "customerId": "CUST123", "originZip": "10001", "destinationZip": "90001", "items": [ {"weight": 500, "class": "85"}, {"weight": 300, "class": "70"} ] } EOF ab quote qr --file quote_request.json Advanced Usage -------------- Pagination ~~~~~~~~~~ .. code-block:: bash # Get first page of results ab api raw GET /companies/search --params '{"page": 1, "per_page": 100}' # Get specific page ab api raw GET /companies/search --params '{"page": 5, "per_page": 100}' # Script to get all pages page=1 while true; do result=$(ab api raw GET /companies/search --params "{\"page\": $page, \"per_page\": 100}") if [ -z "$result" ] || [ "$result" = "[]" ]; then break fi echo "$result" ((page++)) done Filtering and Searching ~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: bash # Complex search with multiple filters ab api raw GET /jobs/search --params '{ "status": "active", "createdAfter": "2024-01-01", "customerId": "CUST123", "sortBy": "createdAt", "sortOrder": "desc", "page": 1, "per_page": 50 }' Working with JSON Output ~~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: bash # Extract specific fields with jq ab lookup company-types --format json | jq '.[] | {id: .id, name: .name}' # Count results ab api raw GET /companies/search --params '{"active": true}' | jq '. | length' # Filter and format ab api raw GET /contacts/search | jq '.[] | select(.email != null) | .email' Environment Management ---------------------- Switching Environments ~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: bash # Check current configuration ab config # Use staging environment for a single command ABC_ENVIRONMENT=staging ab me # Use production environment ABC_ENVIRONMENT=production ab company 12345 # Enable debug logging ABC_LOG_LEVEL=DEBUG ab api raw GET /companies/search Scripting Examples ------------------ Batch Processing ~~~~~~~~~~~~~~~~ .. code-block:: bash #!/bin/bash # Process companies from a CSV file while IFS=, read -r company_id company_name; do echo "Processing $company_name (ID: $company_id)" # Get company details details=$(ab api raw GET /companies/$company_id/details) # Save to file echo "$details" > "company_${company_id}.json" done < companies.csv Export Data ~~~~~~~~~~~ .. code-block:: bash #!/bin/bash # Export all active companies to CSV echo "ID,Name,Code,Type,Created" > active_companies.csv page=1 while true; do companies=$(ab api raw GET /companies/search --params "{\"active\": true, \"page\": $page}") if [ -z "$companies" ] || [ "$companies" = "[]" ]; then break fi echo "$companies" | jq -r '.[] | [.id, .name, .code, .type, .createdAt] | @csv' >> active_companies.csv ((page++)) done echo "Export complete: active_companies.csv" Error Handling -------------- Checking Command Status ~~~~~~~~~~~~~~~~~~~~~~~ .. code-block:: bash # Check if command succeeded if ab company 12345; then echo "Company found" else echo "Company not found or error occurred" fi # Capture output and errors output=$(ab api raw GET /companies/invalid-id 2>&1) if [ $? -ne 0 ]; then echo "Error occurred: $output" fi Logging and Debugging ~~~~~~~~~~~~~~~~~~~~~ .. code-block:: bash # Enable debug logging ABC_LOG_LEVEL=DEBUG ab api raw GET /companies/search # Save logs to file ABC_LOG_LEVEL=DEBUG ab company 12345 2> debug.log # Verbose output for troubleshooting ab api raw GET /companies/search --verbose Integration Examples -------------------- CI/CD Pipeline ~~~~~~~~~~~~~~ .. code-block:: bash #!/bin/bash # Example CI/CD script # Set environment export ABC_ENVIRONMENT=staging # Verify connection if ! ab me > /dev/null 2>&1; then echo "Failed to authenticate" exit 1 fi # Run data validation ab api raw GET /companies/search --params '{"active": true}' | \ jq '.[] | select(.type == null)' > invalid_companies.json if [ -s invalid_companies.json ]; then echo "Found companies with missing type" exit 1 fi echo "Validation passed" Monitoring Script ~~~~~~~~~~~~~~~~~ .. code-block:: bash #!/bin/bash # Monitor job statuses while true; do pending=$(ab api raw GET /jobs/search --params '{"status": "pending"}' | jq '. | length') active=$(ab api raw GET /jobs/search --params '{"status": "active"}' | jq '. | length') echo "$(date): Pending: $pending, Active: $active" # Alert if too many pending if [ "$pending" -gt 100 ]; then echo "ALERT: Too many pending jobs!" fi sleep 300 # Check every 5 minutes done See Also -------- - :doc:`cli` - Complete CLI command reference - :doc:`quickstart_cli` - Getting started with the CLI - :doc:`installation` - Installation and setup instructions