### Install Wheel Package Source: https://github.com/closeio/closeio-api/wiki/Publishing-instructions If the 'wheel' package is not installed, use this command to install it. This is required for building wheel artifacts. ```shell pip install wheel ``` -------------------------------- ### Install Twine Package Source: https://github.com/closeio/closeio-api/wiki/Publishing-instructions If the 'twine' package is not installed, use this command to install it. Twine is used for uploading Python packages to PyPI. ```shell pip install twine ``` -------------------------------- ### Fetch Leads with Search Syntax Source: https://github.com/closeio/closeio-api/blob/master/README.md Fetch multiple leads using the API's search syntax. This example demonstrates filtering by a custom field and status, sorting by update time, and selecting specific fields. ```python # fetch multiple leads (using search syntax) lead_results = api.get('lead', params={ '_limit': 10, '_fields': 'id,display_name,status_label', 'query': 'custom.my_custom_field:"some_value" status:"Potential" sort:updated' }) ``` -------------------------------- ### Install Close API Python Wrapper Source: https://github.com/closeio/closeio-api/blob/master/README.md Install the Close API Python wrapper using pip. This is the first step to using the client in your Python projects. ```bash pip install closeio ``` -------------------------------- ### Fetch Resources with GET Request Source: https://context7.com/closeio/closeio-api/llms.txt Use the get() method to retrieve resources. Supports query parameters for filtering, searching, pagination, and field selection. Returns paginated results with a 'has_more' indicator for list endpoints. ```python from closeio_api import Client api = Client('YOUR_API_KEY') # Fetch a single lead by ID lead = api.get('lead/lead_abcdefghijklmnop') print(lead['name']) # Output: "Sample Lead" # List leads with pagination leads = api.get('lead', params={'_limit': 10}) print(leads['has_more']) # Output: True or False for lead in leads['data']: print(lead['display_name']) # Search leads with query syntax and field selection results = api.get('lead', params={ '_limit': 10, '_fields': 'id,display_name,status_label', 'query': 'custom.my_custom_field:"some_value" status:"Potential" sort:updated' }) # Get recently updated opportunities opportunities = api.get('opportunity', params={ '_order_by': '-date_updated', '_limit': 5 }) # Fetch contacts for a specific lead contacts = api.get('contact', params={'lead_id': 'lead_abc123'}) ``` -------------------------------- ### Generate Package Artifacts Source: https://github.com/closeio/closeio-api/wiki/Publishing-instructions Use this command to create source distribution and wheel files for the package. Ensure you have the necessary build tools installed. ```shell python setup.py sdist bdist_wheel ``` -------------------------------- ### Get Recently Updated Opportunities Source: https://github.com/closeio/closeio-api/blob/master/README.md Retrieve a list of opportunities, ordered by update date in descending order and limited to 5 results. Uses the `get` method with query parameters. ```python # get 5 most recently updated opportunities opportunities = api.get('opportunity', params={'_order_by': '-date_updated', '_limit': 5}) ``` -------------------------------- ### Delete Resources with Close.io API Source: https://context7.com/closeio/closeio-api/llms.txt Use the `delete()` method to remove resources from Close. It returns an empty string on successful deletion (HTTP 204). The operation is irreversible. Includes examples for deleting leads, pipelines, and handling potential errors. ```python from closeio_api import Client, APIError api = Client('YOUR_API_KEY') # Delete a lead result = api.delete('lead/lead_abcdefghijklmnop') print(result) # Output: '' (empty string on success) # Delete a pipeline api.delete('pipeline/pipe_1234') # Delete with error handling try: api.delete('lead/lead_nonexistent') except APIError as e: print(f"Delete failed: {e.response.status_code}") ``` -------------------------------- ### Initialize Close API Client Source: https://context7.com/closeio/closeio-api/llms.txt Instantiate the Client class with your API key. Options include development mode, custom timezone offset, and customizing retry attempts. ```python from closeio_api import Client # Initialize the client with your API key api = Client('YOUR_API_KEY') # For development/testing against local API api_dev = Client('YOUR_API_KEY', development=True) # Custom timezone offset (hours from UTC) api_tz = Client('YOUR_API_KEY', tz_offset=-5) # Customize max retries for rate limiting api_retry = Client('YOUR_API_KEY', max_retries=10) ``` -------------------------------- ### Create Resources with POST Request Source: https://context7.com/closeio/closeio-api/llms.txt Use the post() method to create new resources. Pass a data dictionary to be serialized as JSON. Returns the created resource with server-generated fields. ```python from closeio_api import Client, ValidationError api = Client('YOUR_API_KEY') # Create a new lead new_lead = api.post('lead', data={ 'name': 'Acme Corporation', 'url': 'https://acme.com', 'description': 'Enterprise software company' }) print(f"Created lead: {new_lead['id']}") # Create a contact for a lead contact = api.post('contact', data={ 'lead_id': 'lead_abc123', 'name': 'John Doe', 'title': 'CEO', 'emails': [{'email': 'john@acme.com', 'type': 'office'}], 'phones': [{'phone': '+1-555-123-4567', 'type': 'mobile'}] }) # Create an opportunity opportunity = api.post('opportunity', data={ 'lead_id': 'lead_abc123', 'status_id': 'stat_active', 'value': 50000, 'value_period': 'one_time', 'confidence': 75 }) # Handle validation errors try: contact = api.post('contact', data={'name': 'Jane Doe'}) # Missing lead_id except ValidationError as e: print(f"Field errors: {e.field_errors}") # Output: {'lead': 'This field is required.'} ``` -------------------------------- ### Post a New Lead Source: https://github.com/closeio/closeio-api/blob/master/README.md Use the `post` method to create a new lead in Close. Provide lead data as a dictionary. ```python # post a lead lead = api.post('lead', data={'name': 'New Lead'}) ``` -------------------------------- ### Upload Release to PyPI Source: https://github.com/closeio/closeio-api/wiki/Publishing-instructions After generating the distribution artifacts, use this command to upload them to PyPI. Ensure your Twine credentials are configured. ```shell twine upload dist/* ``` -------------------------------- ### Configure Base API Client in Close.io Source: https://context7.com/closeio/closeio-api/llms.txt The `API` class allows for custom base URLs and advanced connection settings like timezone offset, maximum retries, and SSL verification. Use this for connecting to different API endpoints or fine-tuning connection behavior. ```python from closeio_api import API # Connect to a custom API endpoint api = API( base_url='https://api.close.com/api/v1/', api_key='YOUR_API_KEY', tz_offset=-8, # Pacific timezone max_retries=3, # Reduce retries verify=True # SSL verification ) # Use a different API key for a specific request result = api.get('lead', api_key='DIFFERENT_API_KEY') # Enable debug mode to print request details lead = api.get('lead/lead_abc123', debug=True) # Output: # ----------- HTTP Request ----------- # GET https://api.close.com/api/v1/lead/lead_abc123/ # Authorization: Basic ... # User-Agent: Close/2.1 python (python-requests/2.28.0) # X-TZ-Offset: -8 # ----------- /HTTP Request ----------- # Set custom timeout (in seconds) result = api.get('lead', timeout=30) ``` -------------------------------- ### Initialize Close API Client Source: https://github.com/closeio/closeio-api/blob/master/README.md Initialize the Close API client with your API key. This client object is used to make requests to the Close API. ```python from closeio_api import Client api = Client('YOUR_API_KEY') ``` -------------------------------- ### Update Resources with PUT Request Source: https://context7.com/closeio/closeio-api/llms.txt Use the put() method to update existing resources. Provide the resource ID in the endpoint and the fields to update in the data dictionary. Returns the complete updated resource. ```python from closeio_api import Client api = Client('YOUR_API_KEY') # Update a lead's name and status updated_lead = api.put('lead/lead_abcdefghijklmnop', data={ 'name': 'Acme Corporation (Enterprise)', 'status_id': 'stat_qualified' }) print(f"Updated: {updated_lead['name']}") # Update contact information updated_contact = api.put('contact/cont_abc123', data={ 'title': 'Chief Executive Officer', 'emails': [ {'email': 'john@acme.com', 'type': 'office'}, {'email': 'john.personal@gmail.com', 'type': 'home'} ] }) # Update opportunity value and confidence updated_opp = api.put('opportunity/oppo_xyz789', data={ 'value': 75000, 'confidence': 90 }) ``` -------------------------------- ### Handle API Errors with Close.io Client Source: https://context7.com/closeio/closeio-api/llms.txt The client provides `APIError` for general failures and `ValidationError` for HTTP 400 responses with field-level errors. This snippet demonstrates how to catch and handle these specific exceptions during API operations. ```python from closeio_api import Client, APIError, ValidationError api = Client('YOUR_API_KEY') try: # Attempt to create a resource lead = api.post('lead', data={'name': 'New Lead'}) except ValidationError as e: # HTTP 400 - Validation failed print(f"Validation errors: {e.errors}") print(f"Field errors: {e.field_errors}") # Access raw response print(f"Status: {e.response.status_code}") except APIError as e: # Other API errors (401, 403, 404, 500, etc.) print(f"API error: {e.response.status_code}") print(f"Response body: {e.response.text}") # The client automatically retries on: # - HTTP 429 (Rate Limited) - uses Retry-After header # - HTTP 503 (Service Unavailable) - exponential backoff # - HTTP 502/504 on GET requests - exponential backoff # - Connection errors - up to max_retries attempts ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.