### Install Project Dependencies Source: https://github.com/healthitau/pyconnectwise/blob/main/README.md Install all project dependencies, including development-specific ones, using Poetry. Ensure you have Poetry installed. ```bash pip install -r requirements.txt ``` ```bash poetry install --with=dev ``` -------------------------------- ### Install pyConnectWise Source: https://github.com/healthitau/pyconnectwise/blob/main/README.md Commands to install the library using pip or poetry. ```bash pip install pyconnectwise ``` ```bash poetry add pyconnectwise ``` -------------------------------- ### Install Development Tools Source: https://github.com/healthitau/pyconnectwise/blob/main/README.md Install Poetry and Pre-Commit using pipx for managing Python tools. This is typically done on apt-based systems. ```bash sudo apt install pipx pipx install poetry pipx install pre-commit ``` -------------------------------- ### Install Git Hooks Source: https://github.com/healthitau/pyconnectwise/blob/main/README.md Install Git pre-commit hooks to ensure code quality and consistency before committing changes. This command should be run after installing pre-commit. ```bash pre-commit install ``` -------------------------------- ### Fetching all agreements and their additions Source: https://github.com/healthitau/pyconnectwise/blob/main/README.md This example demonstrates fetching all agreements using pagination and then iterating through each agreement to retrieve its associated additions. ```python agreements = api.finance.agreements.paginated(1, 1000) for agreement in agreements.all(): additions = api.finance.agreements.id(agreement.id).additions.get() ``` -------------------------------- ### Retrieve Automate API Resources Source: https://context7.com/healthitau/pyconnectwise/llms.txt Examples of fetching various resources from the Automate API using the automate_client instance. ```python # Network devices network_devices = automate_client.networkdevices.get() # Scripting scripts = automate_client.scripts.get() script_folders = automate_client.scriptfolders.get() # Patch management patch_actions = automate_client.patchactions.get() # User management users = automate_client.users.get() user_classes = automate_client.userclasses.get() permissions = automate_client.permissions.get() # System information statistics = automate_client.statistics.get() system_info = automate_client.system.get() # Commands commands = automate_client.commands.get() # Data views dataviews = automate_client.dataviews.get() dataview_folders = automate_client.dataviewfolders.get() ``` -------------------------------- ### Get many records from ConnectWise Manage and Automate Source: https://github.com/healthitau/pyconnectwise/blob/main/README.md Use the .get() method on an endpoint to retrieve multiple records. For ConnectWise Manage, it's typically /company/companies, and for Automate, it's /clients. ```python ### Manage ### # sends GET request to /company/companies endpoint companies = manage_api_client.company.companies.get() ``` ```python ### Automate ### # sends GET request to /clients endpoint clients = automate_api_client.clients.get() ``` -------------------------------- ### Retrieve Multiple Records Source: https://context7.com/healthitau/pyconnectwise/llms.txt Fetch lists of records from Manage or Automate endpoints using the get() method. ```python # ConnectWise Manage - Get all companies companies = manage_client.company.companies.get() for company in companies: print(f"Company: {company.name} (ID: {company.id})") # ConnectWise Manage - Get all service tickets tickets = manage_client.service.tickets.get() for ticket in tickets: print(f"Ticket #{ticket.id}: {ticket.summary}") # ConnectWise Automate - Get all clients clients = automate_client.clients.get() for client in clients: print(f"Client: {client.name}") # ConnectWise Automate - Get all computers computers = automate_client.computers.get() for computer in computers: print(f"Computer: {computer.computer_name}") ``` -------------------------------- ### Accessing child endpoints in ConnectWise Manage Source: https://github.com/healthitau/pyconnectwise/blob/main/README.md Traverse down endpoint paths using the .id(id)..get() pattern. This example shows fetching sites for a specific company. ```python # equivalent to GET /company/companies/250/sites sites = manage_api_client.company.companies.id(250).sites.get() ``` -------------------------------- ### Filter ConnectWise Automate Records Source: https://context7.com/healthitau/pyconnectwise/llms.txt Retrieve specific records by applying condition parameters to the get method. ```python # ConnectWise Automate - Get clients with condition (note: singular 'condition') filtered_clients = automate_client.clients.get(params={ 'condition': 'Name like "%Acme%"' }) # ConnectWise Automate - Get online computers online_computers = automate_client.computers.get(params={ 'condition': 'Status = "Online"' }) ``` -------------------------------- ### Get records with query parameters in ConnectWise Source: https://github.com/healthitau/pyconnectwise/blob/main/README.md Pass a dictionary of parameters to the .get() method to filter or modify the request. Note the difference in parameter names: 'conditions' for Manage and 'condition' for Automate. ```python ### Manage ### # sends GET request to /company/companies with a conditions query string conditional_company = manage_api_client.company.companies.get(params={ 'conditions': 'company/id=250' }) ``` ```python ### Automate ### # sends GET request to /clients endpoint with a condition query string # note that the Automate API expects the string 'condition' where-as the Manage API expects the string 'conditions' conditional_client = automate_api_client.clients.get(params={ 'condition': 'company/id=250' }) ``` -------------------------------- ### Get a single record by ID from ConnectWise Manage and Automate Source: https://github.com/healthitau/pyconnectwise/blob/main/README.md Retrieve a specific record by its ID using the .id(id).get() method. For Manage, it's /company/companies/{id}, and for Automate, it's /clients/{id}. ```python ### Manage ### # sends GET request to /company/companies/{id} endpoint company = manage_api_client.company.companies.id(250).get() ``` ```python ### Automate ### # sends GET request to /clients/{id} endpoint client = automate_api_client.clients.id(250).get() ``` -------------------------------- ### Get service tickets with a specific ID condition Source: https://github.com/healthitau/pyconnectwise/blob/main/README.md Retrieve service tickets where the ID is greater than 1000 by providing a 'conditions' parameter to the .get() method. ```python tickets = api.service.tickets.get(params={ 'conditions': 'id > 1000' }) ``` -------------------------------- ### Execute Complete ConnectWise Manage Workflow Source: https://context7.com/healthitau/pyconnectwise/llms.txt Demonstrates client initialization, paginated agreement retrieval, ticket filtering, and company data lookup with error handling. ```python from pyconnectwise import ConnectWiseManageAPIClient from pyconnectwise.exceptions import NotFoundException # Initialize client client = ConnectWiseManageAPIClient( company_name="mycompany", manage_url="na.myconnectwise.net", client_id="your-client-id", public_key="your-public-key", private_key="your-private-key" ) # Get all agreements and their additions agreements = client.finance.agreements.paginated(1, 1000) for agreement in agreements.all(): print(f"Agreement: {agreement.name} (ID: {agreement.id})") additions = client.finance.agreements.id(agreement.id).additions.get() for addition in additions: print(f" - Addition: {addition.description}, Quantity: {addition.quantity}") # Find and update high-priority open tickets open_tickets = client.service.tickets.get(params={ 'conditions': 'status/name!="Closed" AND priority/id<=2', 'orderBy': 'priority/id asc' }) for ticket in open_tickets: print(f"High priority ticket #{ticket.id}: {ticket.summary}") # Add a note or update as needed # Get company with all related data company_id = 250 try: company = client.company.companies.id(company_id).get() print(f"\nCompany: {company.name}") sites = client.company.companies.id(company_id).sites.get() print(f"Sites: {len(sites)}") contacts = client.company.contacts.get(params={ 'conditions': f'company/id={company_id}' }) print(f"Contacts: {len(contacts)}") except NotFoundException: print(f"Company {company_id} not found") ``` -------------------------------- ### Initialize ConnectWise Manage API Client Source: https://github.com/healthitau/pyconnectwise/blob/main/README.md Instantiate the ConnectWiseManageAPIClient with your instance credentials and configuration. ```python from pyconnectwise import ConnectWiseManageAPIClient # init client manage_api_client = ConnectWiseManageAPIClient( # your company name, # manage instance url, # your api client id, # your api public key, # your api private key, # optionally, a Config object for customizing API interactions. See [Additional Configuration]. ) ``` -------------------------------- ### Initialize ConnectWise Automate API Client Source: https://github.com/healthitau/pyconnectwise/blob/main/README.md Instantiate the ConnectWiseAutomateAPIClient with your instance credentials and configuration. ```python from pyconnectwise import ConnectWiseAutomateAPIClient # init client automate_api_client = ConnectWiseAutomateAPIClient( # your automate url # your client id # automate api username # automate api password, # optionally, a Config object for customizing API interactions. See [Additional Configuration]. ) ``` -------------------------------- ### Configure API client Source: https://context7.com/healthitau/pyconnectwise/llms.txt Customize client behavior such as retry settings by passing a Config object during initialization. ```python from pyconnectwise.config import Config from pyconnectwise import ConnectWiseManageAPIClient # Create configuration with custom retry settings config = Config( max_retries=5 # Number of retries for HTTP 500 errors (default: 3) ) # Apply configuration to client manage_client = ConnectWiseManageAPIClient( company_name="mycompany", manage_url="na.myconnectwise.net", client_id="your-client-id", public_key="your-public-key", private_key="your-private-key", config=config ) # The client will automatically retry up to 5 times on server timeout errors ``` -------------------------------- ### Run Code Generation Source: https://github.com/healthitau/pyconnectwise/blob/main/README.md Generate code using the pyconnectwise_generator. You need to provide the path to the schema file as an argument. ```bash poetry run python -m pyconnectwise_generator ``` -------------------------------- ### Configuring pyConnectWise clients with additional options Source: https://github.com/healthitau/pyconnectwise/blob/main/README.md Instantiate a Config object with desired settings, such as max_retries, and pass it to the client constructor for customized API interaction. ```python from pyconnectwise import ConnectWiseManageAPIClient, ConnectWiseAutomateAPIClient from pyconnectwise.config import Config # create an instance of Config with your own changes... config = Config(max_retries = 5) # ... and hand off to the clients during initialization manage_api_client = ConnectWiseManageAPIClient(config = config) automate_api_client = ConnectWiseAutomateAPIClient(config = config) ``` -------------------------------- ### Run Project Tests Source: https://github.com/healthitau/pyconnectwise/blob/main/README.md Execute all project tests using pytest. This command is run via the Poetry executable. ```bash poetry run pytest ``` -------------------------------- ### Create Records with POST Source: https://context7.com/healthitau/pyconnectwise/llms.txt Submit new records to the API by passing a data dictionary to the post() method. ```python # ConnectWise Manage - Create a new company new_company = manage_client.company.companies.post(data={ "name": "Acme Corporation", "identifier": "ACME", "status": {"id": 1}, # Active status "types": [{"id": 1}], # Company type "site": { "name": "Main Office", "addressLine1": "123 Main Street", "city": "Austin", "state": "TX", "zip": "78701", "country": {"id": 1} } }) print(f"Created company ID: {new_company.id}") # ConnectWise Manage - Create a new service ticket new_ticket = manage_client.service.tickets.post(data={ "summary": "Network connectivity issue", "company": {"id": 250}, "board": {"id": 1}, "status": {"id": 1}, "priority": {"id": 3}, "initialDescription": "User reports intermittent network drops" }) print(f"Created ticket #{new_ticket.id}") # ConnectWise Automate - Create a new client new_client = automate_client.clients.post(data={ "Name": "New Client Inc", "ExternalID": "NC001" }) print(f"Created client ID: {new_client.id}") ``` -------------------------------- ### Update Records with PUT and PATCH Source: https://context7.com/healthitau/pyconnectwise/llms.txt Perform full record replacements using put() or partial updates using patch() with JSON Patch format. ```python # ConnectWise Manage - Full update with PUT updated_company = manage_client.company.companies.id(250).put(data={ "id": 250, "name": "Acme Corporation Updated", "identifier": "ACME", "status": {"id": 1}, "phoneNumber": "555-123-4567", "website": "https://www.acme.com" }) print(f"Updated company: {updated_company.name}") # ConnectWise Manage - Partial update with PATCH # PATCH uses JSON Patch format (RFC 6902) patched_ticket = manage_client.service.tickets.id(12345).patch(data=[ {"op": "replace", "path": "/status/id", "value": 2}, {"op": "replace", "path": "/priority/id", "value": 1} ]) print(f"Patched ticket status: {patched_ticket.status}") ``` -------------------------------- ### Handle Pagination with PaginatedResponse Source: https://context7.com/healthitau/pyconnectwise/llms.txt Use the paginated() method to manage large datasets, supporting manual page navigation or automatic iteration across all pages. ```python # Initialize paginated response (page 1, 100 items per page) paginated_companies = manage_client.company.companies.paginated(1, 100) # Access data from current page current_page_data = paginated_companies.data print(f"Page has {len(current_page_data)} companies") # Check pagination status print(f"Has next page: {paginated_companies.has_next_page}") print(f"Has previous page: {paginated_companies.has_prev_page}") # Navigate to next page if paginated_companies.has_next_page: paginated_companies.get_next_page() print(f"Now on page with {len(paginated_companies.data)} companies") # Navigate to previous page if paginated_companies.has_prev_page: paginated_companies.get_previous_page() # Iterate over items on current page only for company in paginated_companies: print(f"Company: {company.name}") # Iterate over ALL items across ALL pages automatically paginated_tickets = manage_client.service.tickets.paginated(1, 1000) for ticket in paginated_tickets.all(): print(f"Processing ticket #{ticket.id}: {ticket.summary}") # With query parameters paginated_active = manage_client.company.companies.paginated(1, 500, params={ 'conditions': 'status/name="Active"' }) for company in paginated_active.all(): print(f"Active company: {company.name}") ``` -------------------------------- ### Access Automate API endpoints Source: https://context7.com/healthitau/pyconnectwise/llms.txt Retrieve data from various ConnectWise Automate modules using organized endpoint properties. ```python # Client management clients = automate_client.clients.get() client = automate_client.clients.id(1).get() # Computer management computers = automate_client.computers.get() computer = automate_client.computers.id(1).get() drives = automate_client.drives.get() software = automate_client.computers.software.get() # Contact management contacts = automate_client.contacts.get() # Location and group management locations = automate_client.locations.get() groups = automate_client.groups.get() # Monitoring monitors = automate_client.monitors.get() ``` -------------------------------- ### Access Manage API endpoints Source: https://context7.com/healthitau/pyconnectwise/llms.txt Retrieve data from various ConnectWise Manage modules using organized endpoint properties. ```python # Company endpoints - companies, contacts, configurations, sites companies = manage_client.company.companies.get() contacts = manage_client.company.contacts.get() configurations = manage_client.company.configurations.get() # Service endpoints - tickets, boards, priorities, statuses tickets = manage_client.service.tickets.get() boards = manage_client.service.boards.get() priorities = manage_client.service.priorities.get() # Finance endpoints - agreements, invoices, billing agreements = manage_client.finance.agreements.get() invoices = manage_client.finance.invoices.get() billing_cycles = manage_client.finance.billing_cycles.get() # Project endpoints - projects, phases, tasks projects = manage_client.project.projects.get() # Time endpoints - time entries, work types time_entries = manage_client.time.entries.get() # Sales endpoints - opportunities, activities opportunities = manage_client.sales.opportunities.get() # Schedule endpoints - calendar, scheduled entries schedule_entries = manage_client.schedule.entries.get() # System endpoints - members, callbacks, info members = manage_client.system.members.get() ``` -------------------------------- ### Working with paginated responses in ConnectWise Manage Source: https://github.com/healthitau/pyconnectwise/blob/main/README.md Utilize the .paginated() method for efficient handling of large datasets. It supports accessing current page data, navigating between pages, and iterating over all items. ```python # initialize a PaginatedResponse instance for /company/companies, starting on page 1 with a pageSize of 100 paginated_companies = manage_api_client.company.companies.paginated(1,100) # access the data from the current page using the .data field page_one_data = paginated_companies.data # if there's a next page, retrieve the next page worth of data paginated_companies.get_next_page() # if there's a previous page, retrieve the previous page worth of data paginated_companies.get_previous_page() # iterate over all companies on the current page for company in paginated_companies: # ... do things ... # iterate over all companies in all pages # this works by yielding every item on the page, then fetching the next page and continuing until there's no data left for company in paginated_companies.all(): # ... do things ... ``` -------------------------------- ### Retrieve Single Record by ID Source: https://context7.com/healthitau/pyconnectwise/llms.txt Fetch a specific record by its ID using the id() method. ```python # ConnectWise Manage - Get a specific company by ID company = manage_client.company.companies.id(250).get() print(f"Company Name: {company.name}") print(f"Company Status: {company.status}") print(f"Company Phone: {company.phone_number}") # ConnectWise Manage - Get a specific ticket by ID ticket = manage_client.service.tickets.id(12345).get() print(f"Ticket Summary: {ticket.summary}") print(f"Ticket Status: {ticket.status}") # ConnectWise Automate - Get a specific client by ID client = automate_client.clients.id(250).get() print(f"Client Name: {client.name}") # ConnectWise Automate - Get a specific computer by ID computer = automate_client.computers.id(100).get() print(f"Computer Name: {computer.computer_name}") ``` -------------------------------- ### Access Nested Child Endpoints Source: https://context7.com/healthitau/pyconnectwise/llms.txt Use method chaining with the id() method to target specific child resources of a parent entity. ```python # Get sites for a specific company: /company/companies/{id}/sites company_id = 250 sites = manage_client.company.companies.id(company_id).sites.get() for site in sites: print(f"Site: {site.name}, Address: {site.address_line1}") # Get notes for a specific company company_notes = manage_client.company.companies.id(250).notes.get() for note in company_notes: print(f"Note: {note.text}") # Get groups for a specific company company_groups = manage_client.company.companies.id(250).groups.get() # Get additions for a specific agreement: /finance/agreements/{id}/additions additions = manage_client.finance.agreements.id(100).additions.get() for addition in additions: print(f"Addition: {addition.description}") # ConnectWise Automate - Get documents for a client documents = automate_client.clients.id(250).documents.get() # ConnectWise Automate - Get drives for a specific computer drives = automate_client.computers.id(100).drives.get() for drive in drives: print(f"Drive: {drive.letter}") ``` -------------------------------- ### Handle API exceptions Source: https://context7.com/healthitau/pyconnectwise/llms.txt Catch specific exception classes to handle different HTTP status codes and access response details. ```python from pyconnectwise.exceptions import ( AuthenticationFailedException, PermissionsFailedException, NotFoundException, MalformedRequestException, ConflictException, ServerError, ObjectExistsError ) try: # Attempt to get a company that may not exist company = manage_client.company.companies.id(99999).get() print(f"Found company: {company.name}") except AuthenticationFailedException as e: print(f"Authentication failed (401): {e.message()}") print(f"Check your API credentials") except PermissionsFailedException as e: print(f"Permission denied (403): {e.message()}") print(f"You may not have access to this resource") except NotFoundException as e: print(f"Resource not found (404): {e.message()}") print(f"The requested company does not exist") except MalformedRequestException as e: print(f"Bad request (400): {e.message()}") print(f"Details: {e.details()}") except ObjectExistsError as e: print(f"Object already exists: {e.message()}") except ConflictException as e: print(f"Conflict (409): {e.message()}") except ServerError as e: print(f"Server error (500): {e.message()}") # Retries are handled automatically based on config.max_retries # Access response details from any exception try: company = manage_client.company.companies.id(99999).get() except NotFoundException as e: print(f"Status code: {e.response.status_code}") print(f"Response text: {e.response.text}") print(f"Sanitized URL: {e._get_sanitized_url()}") ``` -------------------------------- ### Filter Results with Query Parameters Source: https://context7.com/healthitau/pyconnectwise/llms.txt Apply filtering conditions to API requests using the params argument. ```python # ConnectWise Manage - Get companies with conditions active_companies = manage_client.company.companies.get(params={ 'conditions': 'status/name="Active"' }) # ConnectWise Manage - Get tickets with multiple conditions urgent_tickets = manage_client.service.tickets.get(params={ 'conditions': 'priority/name="Priority 1 - Critical" AND status/name!="Closed"', 'orderBy': 'id desc' }) # ConnectWise Manage - Get tickets with ID > 1000 tickets = manage_client.service.tickets.get(params={ 'conditions': 'id > 1000' }) ``` -------------------------------- ### Update a company record Source: https://context7.com/healthitau/pyconnectwise/llms.txt Use the patch method on a company ID to perform partial updates using JSON patch operations. ```python patched_company = manage_client.company.companies.id(250).patch(data=[ {"op": "replace", "path": "/phoneNumber", "value": "555-987-6543"} ]) ``` -------------------------------- ### Delete records Source: https://context7.com/healthitau/pyconnectwise/llms.txt Remove specific records by calling the delete method on the corresponding ID-specific endpoint. ```python # ConnectWise Manage - Delete a company note manage_client.company.companies.id(250).notes.id(100).delete() print("Note deleted successfully") # ConnectWise Manage - Delete a ticket manage_client.service.tickets.id(12345).delete() print("Ticket deleted successfully") # ConnectWise Automate - Delete a client (use with caution) automate_client.clients.id(500).delete() print("Client deleted successfully") ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.