### Complete Workflow Example with PrintNode API (Python) Source: https://context7.com/printnode/printnode-python/llms.txt A comprehensive example demonstrating a full workflow: creating a child account, setting up API keys, and then listing available computers and printers for that account. This requires the 'printnodeapi' library. ```python from printnodeapi import Gateway # Initialize with parent account API key parent_gateway = Gateway(apikey='parent_api_key') # Create child account for a new customer customer_account = parent_gateway.CreateAccount( firstname='ACME', lastname='Corporation', email='admin@acme.com', password='secure_password', creator_ref='acme_corp', api_keys=['Production'], tags={'customer_id': 'ACME-001', 'plan': 'enterprise'} ) child_id = customer_account['Account']['id'] production_key = customer_account['Account']['ApiKeys']['Production'] print(f"Created account {child_id} with API key") # Connect as child account child_gateway = Gateway(apikey=production_key) # Wait for customer to install PrintNode client and connect computers # ... (In real scenario, this happens asynchronously) ... # List available computers and printers computers = child_gateway.computers() print(f"Found {len(computers)} computers") for computer in computers: print(f"\nComputer: {computer.name}") printers = child_gateway.printers(computer=computer.id) for printer in printers: print(f" - {printer.name} (ID: {printer.id})") ``` -------------------------------- ### Get Latest Client for OS in Python Source: https://context7.com/printnode/printnode-python/llms.txt Fetches the most recent version of the PrintNode client for a specified operating system. The function returns a client object containing detailed information, including the version, filename, download URL, and SHA-1 hash. Examples are provided for both Windows and macOS. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Get latest Windows client windows_client = gateway.clients(os='windows') print(f"Latest Windows client: {windows_client.version}") print(f"Filename: {windows_client.filename}") print(f"Download URL: {windows_client.url}") print(f"SHA-1: {windows_client.sha_1}") # Get latest macOS client osx_client = gateway.clients(os='osx') print(f"\nLatest macOS client: {osx_client.version}") print(f"Filename: {osx_client.filename}") ``` -------------------------------- ### Pagination for Large Result Sets (Python) Source: https://context7.com/printnode/printnode-python/llms.txt Handles large lists of resources by using pagination parameters. This Python example utilizes the 'printnodeapi' library and accepts 'limit' and 'after' parameters for fetching data in chunks. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Get first 10 print jobs first_page = gateway.printjobs(limit=10) print(f"First page: {len(first_page)} jobs") # Get next 10 print jobs after the last ID if first_page: last_id = first_page[-1].id next_page = gateway.printjobs(limit=10, after=last_id) print(f"Next page: {len(next_page)} jobs") # Get results in descending order recent_jobs = gateway.printjobs(limit=5, dir='desc') for job in recent_jobs: print(f"{job.id}: {job.title}") # Output: # First page: 10 jobs # Next page: 10 jobs # 251160: Report Oct 2024 # 251159: Invoice #999 # 251158: Shipping Label # 251157: Employee List # 251156: Product Catalog ``` -------------------------------- ### List All Print Jobs (Python) Source: https://context7.com/printnode/printnode-python/llms.txt Retrieves a list of all print jobs associated with the account. The response can be filtered and paginated. This example shows how to fetch the first 5 jobs and print their basic details. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Get all print jobs printjobs = gateway.printjobs() for job in printjobs[:5]: # Show first 5 print(f"ID: {job.id}") print(f"Title: {job.title}") print(f"Printer: {job.printer.name}") print(f"State: {job.state}") print(f"Created: {job.create_timestamp}") print("---") ``` -------------------------------- ### List Download Clients in Python Source: https://context7.com/printnode/printnode-python/llms.txt Retrieves a list of all available PrintNode client downloads. The function returns a list of client objects, each containing details such as ID, edition, version, operating system, filename, and enabled status. The example iterates through the first three clients to display their properties. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Get all available clients all_clients = gateway.clients() for client in all_clients[:3]: print(f"ID: {client.id}") print(f"Edition: {client.edition}") print(f"Version: {client.version}") print(f"OS: {client.os}") print(f"Filename: {client.filename}") print(f"Enabled: {client.enabled}") print("---") ``` -------------------------------- ### Create PrintNode API Key with Python Source: https://github.com/printnode/printnode-python/blob/master/README.md Creates a new API key for a PrintNode account. The function takes a reference for the new API key as an argument. The example demonstrates creating a new 'Development' API key and then printing the account's updated list of API keys. ```python from printnodeapi import Gateway gateway = Gateway(url='https://api.printnode.com',apikey='secretAPIKey') new_account = gateway.CreateAccount( firstname="A", lastname="Person", password="password", email="aperson@emailprovider.com", tags={"Likes":"Something"}, api_keys=["Production"] ) new_account_gateway = Gateway(url='https://api.printnode.com',apikey='secretAPIKey',child_id=new_account["Account"]["id"]) new_account_gateway.CreateApiKey("Development") print(new_account_gateway.account.api_keys) new_account_gateway.DeleteAccount() ``` -------------------------------- ### Retrieve Clients using Python Source: https://github.com/printnode/printnode-python/blob/master/README.md Retrieves client information using the PrintNode Python API. This function can fetch all clients for an account, the most recent version for a specified OS, or clients within a given range of IDs. The example demonstrates fetching clients by ID and by OS. ```python from printnodeapi import Gateway gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey') for client in gateway.clients(client_ids="11-12"): print(client.id) print(gateway.clients(os="windows").os) ``` -------------------------------- ### GET /printjobs Source: https://context7.com/printnode/printnode-python/llms.txt Retrieves a list of all print jobs associated with the account. ```APIDOC ## List All Print Jobs ### Description Retrieves all print jobs submitted to the PrintNode service for the authenticated account. ### Method GET ### Endpoint /printjobs ### Parameters #### Query Parameters None ### Response #### Success Response (200) - **Array of PrintJob objects**: Each object contains details about a print job, including ID, title, printer name, state, and creation timestamp. #### Response Example ```json [ { "id": 251153, "title": "Invoice #12345", "printer": {"name": "HP LaserJet Pro"}, "state": "done", "create_timestamp": "2024-10-28T10:15:30.087Z" }, { "id": 251152, "title": "Report Q3 2024", "printer": {"name": "HP LaserJet Pro"}, "state": "done", "create_timestamp": "2024-10-28T09:45:12.234Z" } ] ``` ``` -------------------------------- ### Get Account Tag Value Source: https://context7.com/printnode/printnode-python/llms.txt Retrieves the value associated with a specific account tag. This example shows how to fetch the values for 'department' and 'location' tags. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Get tag value department = gateway.tag('department') location = gateway.tag('location') print(f"Department: {department}") print(f"Location: {location}") ``` -------------------------------- ### Retrieve Printer Details by ID or Computer Source: https://github.com/printnode/printnode-python/blob/master/README.md Illustrates fetching printer information using the PrintNode API. It shows how to get a specific printer by its ID and how to list all printers attached to a specific computer. ```python from printnodeapi import Gateway gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey') print(gateway.printers(printer=50120).name) for printer in gateway.printers(computer=10027): print(printer.name) ``` -------------------------------- ### GET /printjobs Source: https://context7.com/printnode/printnode-python/llms.txt Filters and retrieves print jobs associated with a specific computer. ```APIDOC ## Get Print Jobs for Specific Computer ### Description Retrieves a list of print jobs filtered by the computer they were sent to. ### Method GET ### Endpoint /printjobs ### Parameters #### Query Parameters - **computer** (integer) - Required - The ID of the computer to filter print jobs by. ### Response #### Success Response (200) - **Array of PrintJob objects**: Each object contains details about a print job associated with the specified computer. #### Response Example ```json [ { "title": "Invoice #12345", "state": "done", "printer": {"name": "HP LaserJet Pro"} }, { "title": "Report Q3 2024", "state": "done", "printer": {"name": "HP LaserJet Pro"} }, { "title": "Shipping Manifest", "state": "error", "printer": {"name": "Canon ImageRunner"} } ] ``` ``` -------------------------------- ### Get Computer by Name using Python Source: https://context7.com/printnode/printnode-python/llms.txt Retrieves a specific computer from PrintNode by its name. This function requires an API key for authentication and returns a list of computers matching the provided name. If no computer is found, an empty list is returned. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Get computer by name (returns list) computers = gateway.computers(computer='Office-PC-01') if computers: computer = computers[0] print(f"Found computer: {computer.name} (ID: {computer.id})") else: print("Computer not found") ``` -------------------------------- ### Get Specific Download Clients by ID Range (Python) Source: https://context7.com/printnode/printnode-python/llms.txt Retrieves specific client download information using a range of client IDs. Requires the 'printnodeapi' library. It takes a client_ids string as input and returns a list of client objects. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Get clients in ID range clients = gateway.clients(client_ids='11-13') for client in clients: print(f"ID {client.id}: {client.edition} {client.version} for {client.os}") # Output: # ID 13: printnode 4.7.2 for linux # ID 12: printnode 4.7.2 for windows # ID 11: printnode 4.7.1 for osx ``` -------------------------------- ### GET /states Source: https://context7.com/printnode/printnode-python/llms.txt Retrieves the state history for a specific print job. ```APIDOC ## Get Print Job States ### Description Fetches the complete history of state changes for a given print job, showing when it transitioned through different stages like 'new', 'queued', and 'done'. ### Method GET ### Endpoint /states ### Parameters #### Query Parameters - **printjob** (integer) - Required - The ID of the print job for which to retrieve state history. ### Response #### Success Response (200) - **Array of State objects**: Each object represents a state transition and includes the state name, a message, the timestamp, and the client version that reported the state. #### Response Example ```json [ { "state": "new", "message": "PrintJob created", "create_timestamp": "2024-10-28T10:15:30.087Z", "client_version": "4.7.2" }, { "state": "queued", "message": "PrintJob queued for printing", "create_timestamp": "2024-10-28T10:15:31.123Z", "client_version": "4.7.2" }, { "state": "done", "message": "PrintJob completed successfully", "create_timestamp": "2024-10-28T10:15:45.456Z", "client_version": "4.7.2" } ] ``` ``` -------------------------------- ### Get All Scale Measurements Source: https://context7.com/printnode/printnode-python/llms.txt Reads measurements from all connected scales associated with a specific computer. It requires the computer ID as input and outputs details for each scale including device name, vendor, mass, measurement unit, and product. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Get all scales for a computer scales = gateway.scales(computer=10027) for scale in scales: print(f"Device: {scale.device_name}") print(f"Vendor: {scale.vendor}") print(f"Mass: {scale.mass}") print(f"Measurement: {scale.measurement}") print(f"Product: {scale.product}") print("---") ``` -------------------------------- ### GET /states Source: https://context7.com/printnode/printnode-python/llms.txt Retrieves state history for multiple print jobs within a given range. ```APIDOC ## Get States for Multiple Print Jobs ### Description Retrieves the state history for a specified range or list of print jobs. ### Method GET ### Endpoint /states ### Parameters #### Query Parameters - **printjobs** (string) - Required - A comma-separated string of print job IDs (e.g., "251153,251154,251155"). ### Response #### Success Response (200) - **Object**: Keys are print job IDs, and values are arrays of State objects for each respective print job. #### Response Example ```json { "251153": [ { "state": "done", "message": "PrintJob completed successfully", "create_timestamp": "2024-10-28T10:15:45.456Z", "client_version": "4.7.2" } ], "251154": [ { "state": "error", "message": "Printer offline", "create_timestamp": "2024-10-28T11:00:00.123Z", "client_version": "4.7.2" } ] } ``` ``` -------------------------------- ### Get API Key Value in Python Source: https://context7.com/printnode/printnode-python/llms.txt Retrieves the value of a specific API key associated with the authenticated account. This function can be used to fetch keys by their name, such as 'Production' or 'Development'. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Get API key value production_key = gateway.api_key('Production') development_key = gateway.api_key('Development') print(f"Production Key: {production_key}") print(f"Development Key: {development_key}") ``` -------------------------------- ### Lookup PrintNode API Key with Python Source: https://github.com/printnode/printnode-python/blob/master/README.md Retrieves the value of a specific PrintNode API key. This function takes the API key identifier as an argument and returns its corresponding value. The example shows how to create an account with an API key and then retrieve it. ```python from printnodeapi import Gateway gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey') new_account = gateway.CreateAccount( firstname="A", lastname="Person", password="password", email="aperson@emailprovider.com", tags={"Likes":"Something"}, api_keys=["Production"] ) new_account_gateway = Gateway(url='https://api.printnode.com',apikey='secretAPIKey',child_id=new_account["Account"]["id"]) print(new_account_gateway.api_key("Production")) new_account_gateway.DeleteAccount() ``` -------------------------------- ### Modify Child Account Details Source: https://context7.com/printnode/printnode-python/llms.txt Updates account information for a child account. This example first creates a child account and then demonstrates how to obtain a Gateway object for that child account to modify its details. Note: The specific modification calls are not shown in the provided snippet but implied. ```python from printnodeapi import Gateway gateway = Gateway(apikey='parent_api_key') # Create child account new_account = gateway.CreateAccount( firstname='Alice', lastname='Brown', email='alice.brown@example.com', password='password789' ) # Create gateway for child account child_gateway = Gateway(apikey='parent_api_key', child_id=new_account['Account']['id']) ``` -------------------------------- ### GET /printjobs Source: https://context7.com/printnode/printnode-python/llms.txt Filters and retrieves print jobs associated with a specific printer. ```APIDOC ## Get Print Jobs for Specific Printer ### Description Retrieves a list of print jobs filtered by the specific printer they were sent to. ### Method GET ### Endpoint /printjobs ### Parameters #### Query Parameters - **printer** (integer) - Required - The ID of the printer to filter print jobs by. ### Response #### Success Response (200) - **Array of PrintJob objects**: Each object contains details about a print job sent to the specified printer. #### Response Example ```json [ { "title": "Invoice #12345", "state": "done" }, { "title": "Report Q3 2024", "state": "done" }, { "title": "Employee Roster", "state": "done" } ] ``` ``` -------------------------------- ### Get Print Job States Source: https://context7.com/printnode/printnode-python/llms.txt Retrieves the states for a range of print jobs using set notation. It iterates through the states and prints the latest state information for each print job. ```python states_map = gateway.states('251150-251155') for printjob_states in states_map: if len(printjob_states) > 0: latest_state = printjob_states[-1] print(f"PrintJob {latest_state.print_job_id}: {latest_state.state}") ``` -------------------------------- ### Authenticate PrintNode API Gateway with Child Account Access Source: https://github.com/printnode/printnode-python/blob/master/README.md Provides examples of authenticating the PrintNode API Gateway with access to child accounts. This can be done using a child email, child reference, or child ID in conjunction with an API key. ```python Gateway(apikey='api-key',child_email='c_email') Gateway(apikey='api-key',child_ref='c_creator_ref') Gateway(apikey='api-key',child_id='c_id') ``` -------------------------------- ### Get Specific Scale Reading Source: https://context7.com/printnode/printnode-python/llms.txt Retrieves measurement data from a specific scale device identified by its computer ID, device name, and device number. It outputs the current weight and the age of the data. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Get specific scale by device name and number scales = gateway.scales(computer=10027, dev_name='usb-scale-01', dev_num=0) if scales: scale = scales[0] print(f"Current weight: {scale.mass} {scale.measurement}") print(f"Age of data: {scale.age_of_data}ms") ``` -------------------------------- ### GET /printjobs Source: https://context7.com/printnode/printnode-python/llms.txt Retrieves details of a specific print job using its unique ID. ```APIDOC ## Get Specific Print Job by ID ### Description Fetches the detailed information for a single print job, identified by its unique ID. ### Method GET ### Endpoint /printjobs ### Parameters #### Query Parameters - **printjob** (integer) - Required - The ID of the specific print job to retrieve. ### Response #### Success Response (200) - **PrintJob object**: An object containing all details of the specified print job, including its state, content type, source, associated printer, computer, options, and quantity. #### Response Example ```json { "id": 251153, "title": "Invoice #12345", "content_type": "pdf_uri", "source": "PythonApiClient", "state": "done", "printer": { "name": "HP LaserJet Pro", "computer": {"name": "Office-PC-01"} }, "options": {"copies": 2, "duplex": "long-edge"}, "qty": 1 } ``` ``` -------------------------------- ### Get States for Multiple Print Jobs (Python) Source: https://context7.com/printnode/printnode-python/llms.txt Retrieves state information for a range of print jobs. This function can be used to efficiently fetch the status of multiple jobs simultaneously, reducing API call overhead. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Example: Get states for a range of print jobs (IDs 251153 to 251155) # Note: The actual API call to get states for multiple jobs would require specific parameters # not fully detailed in the provided text. Assuming a hypothetical multi-job state retrieval. # Hypothetical example structure (actual implementation may vary based on API) # printjob_ids = [251153, 251154, 251155] # all_states = gateway.states(printjob_ids=printjob_ids) # For demonstration, we'll simulate processing if the API supported batch retrieval directly here. print("Fetching states for multiple print jobs is initiated. Details would follow based on API response.") ``` -------------------------------- ### Get Print Jobs for Specific Printer (Python) Source: https://context7.com/printnode/printnode-python/llms.txt Retrieves print jobs targeting a specific printer. Filters jobs using the 'printer' ID. This allows for focusing on the queue of a single device. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Get print jobs for specific printer printjobs = gateway.printjobs(printer=50120) print(f"Total jobs for printer: {len(printjobs)}") for job in printjobs[:3]: print(f"{job.title} - {job.state}") ``` -------------------------------- ### Get Account Tag Value using Python Source: https://github.com/printnode/printnode-python/blob/master/README.md Retrieves the value of a specific account tag using its name. This function requires an API key and the printnodeapi Gateway to access account-specific tags. ```python from printnodeapi import Gateway gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey') print(gateway.tag("Likes")) ``` -------------------------------- ### Delete API Key in Python Source: https://context7.com/printnode/printnode-python/llms.txt Removes a specific API key from the authenticated account. The key is identified by its name. The example demonstrates creating an API key and then immediately deleting it to show the effect on the account's available API keys. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Create and then delete an API key gateway.CreateApiKey('Temporary') print(f"Before deletion: {gateway.account.api_keys}") gateway.DeleteApiKey('Temporary') print(f"After deletion: {gateway.account.api_keys}") ``` -------------------------------- ### Get Print Jobs for Specific Computer (Python) Source: https://context7.com/printnode/printnode-python/llms.txt Retrieves print jobs associated with printers on a particular computer. Requires the 'computer' ID as a filter parameter. This is useful for managing print queues on a specific machine. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Get print jobs for specific computer printjobs = gateway.printjobs(computer=10027) for job in printjobs: print(f"{job.title} - {job.state} - Printer: {job.printer.name}") ``` -------------------------------- ### Get Printer by ID using Python Source: https://context7.com/printnode/printnode-python/llms.txt Retrieves a specific printer using its unique ID. This operation requires an API key. The function returns detailed information about the printer, including its name, description, associated computer ID, and printing capabilities. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Get printer by ID printer = gateway.printers(printer=50120) print(f"Printer: {printer.name}") print(f"Description: {printer.description}") print(f"Computer ID: {printer.computer.id}") print(f"Capabilities: {printer.capabilities}") ``` -------------------------------- ### Modify Client Downloads using Python Source: https://github.com/printnode/printnode-python/blob/master/README.md Modifies the download enablement status for specified clients using the PrintNode Python API. It takes a client ID and a boolean value (True/False) to set the download status. The example shows disabling downloads for a client and then verifying the change. ```python from printnodeapi import Gateway gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey') gateway.ModifyClientDownloads(11,False) print(gateway.clients(client_ids=11)[0].enabled) ``` -------------------------------- ### Get Printer by Name on Specific Computer using Python Source: https://context7.com/printnode/printnode-python/llms.txt Finds a printer by its name on a specific computer, identified by the computer's ID. This function requires an API key for authentication. It returns the name and ID of the found printer, or a message if the printer is not found. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Get printer by name on specific computer printers = gateway.printers(computer=10027, printer='HP LaserJet Pro') if printers: printer = printers[0] print(f"Found: {printer.name} (ID: {printer.id})") else: print("Printer not found") ``` -------------------------------- ### Get Print Job States by ID (Python) Source: https://context7.com/printnode/printnode-python/llms.txt Retrieves the state history for a specific print job identified by its ID. The 'states' method returns a list of state objects, each containing details like state, message, and timestamp. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Get states for specific print job printjob_id = 251153 states_list = gateway.states(printjob_id) # states_list is a list of print jobs, each containing a list of states if states_list and len(states_list) > 0: states = states_list[0] for state in states: print(f"State: {state.state}") print(f"Message: {state.message}") print(f"Timestamp: {state.create_timestamp}") print(f"Client Version: {state.client_version}") print("---") ``` -------------------------------- ### Get Specific Print Job by ID (Python) Source: https://context7.com/printnode/printnode-python/llms.txt Retrieves detailed information about a single print job using its unique ID. The 'printjob' parameter filters the request. This is useful for checking the status and metadata of a particular job. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Get specific print job printjob = gateway.printjobs(printjob=251153) print(f"PrintJob ID: {printjob.id}") print(f"Title: {printjob.title}") print(f"Content Type: {printjob.content_type}") print(f"Source: {printjob.source}") print(f"State: {printjob.state}") print(f"Printer: {printjob.printer.name}") print(f"Computer: {printjob.printer.computer.name}") print(f"Options: {printjob.options}") print(f"Quantity: {printjob.qty}") ``` -------------------------------- ### Delete PrintNode API Key with Python Source: https://github.com/printnode/printnode-python/blob/master/README.md Deletes a specified API key from a PrintNode account. The function requires the API key to be deleted as an argument. The example shows deleting the 'Production' API key and then printing the remaining API keys. ```python from printnodeapi import Gateway gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey') new_account = gateway.CreateAccount( firstname="A", lastname="Person", password="password", email="aperson@emailprovider.com", tags={"Likes":"Something"}, api_keys=["Production"] ) new_account_gateway = Gateway(url='https://api.printnode.com',apikey='secretAPIKey',child_id=new_account["Account"]["id"]) new_account_gateway.DeleteApiKey("Production") print(new_account_gateway.account.api_keys) new_account_gateway.DeleteAccount() ``` -------------------------------- ### Get Specific PrintNode Computer by ID Source: https://context7.com/printnode/printnode-python/llms.txt Retrieves details for a single PrintNode computer using its unique identifier. This method allows for targeted access to a specific computer's properties, including its ID, name, IP addresses (IPv4 and IPv6), and connection state. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Get computer by ID computer = gateway.computers(computer=10027) print(f"Computer ID: {computer.id}") print(f"Name: {computer.name}") print(f"IP Address: {computer.inet}") print(f"IPv6 Address: {computer.inet6}") print(f"State: {computer.state}") ``` -------------------------------- ### Modify PrintNode Account Details with Python Source: https://github.com/printnode/printnode-python/blob/master/README.md Modifies the details of an existing PrintNode account. You can update one or more fields such as first name, last name, password, or email by providing the new values as arguments. The example demonstrates changing the first name and printing the updated value. ```python from printnodeapi import Gateway gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey') new_account = gateway.CreateAccount( firstname="A", lastname="Person", password="password", email="aperson@emailprovider.com", tags={"Likes":"Something"} ) new_account_gateway = Gateway(url='https://api.printnode.com',apikey='secretAPIKey',child_id=new_account["Account"]["id"]) new_account_gateway.ModifyAccount(firstname="B") print(new_account_gateway.account.firstname) new_account_gateway.DeleteAccount() ``` -------------------------------- ### Initialize PrintNode API Gateway with API Key Source: https://github.com/printnode/printnode-python/blob/master/README.md Demonstrates the basic initialization of the PrintNode API Gateway using an API key. The Gateway is the primary object for interacting with the PrintNode API. ```python from printnodeapi.Gateway import Gateway my_account_gateway = Gateway(apikey='my_api_key') ``` -------------------------------- ### Create PrintNode Account with Python Source: https://github.com/printnode/printnode-python/blob/master/README.md Creates a new PrintNode account using the provided details. Optional parameters like creator reference, API keys, and tags can be included. The function returns the newly created account information and allows for subsequent operations on this account. ```python from printnodeapi import Gateway gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey') new_account = gateway.CreateAccount( firstname="A", lastname="Person", password="password", email="aperson@emailprovider.com", tags={"Likes":"Something"} ) new_account_gateway = Gateway(url='https://api.printnode.com',apikey='secretAPIKey',child_id=new_account["Account"]["id"]) print(new_account_gateway.account.firstname) new_account_gateway.DeleteAccount() ``` -------------------------------- ### Create or Update Account Tags Source: https://context7.com/printnode/printnode-python/llms.txt Adds or updates tags for the PrintNode account. It demonstrates creating multiple tags with key-value pairs and then verifies their creation by printing all account tags. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Create/modify a tag gateway.ModifyTag('department', 'sales') gateway.ModifyTag('location', 'headquarters') gateway.ModifyTag('subscription_tier', 'premium') # Verify tags were created print(gateway.account.tags) ``` -------------------------------- ### Retrieve Specific Computer Details Source: https://github.com/printnode/printnode-python/blob/master/README.md Demonstrates how to fetch details for a specific computer using its ID. The code initializes the Gateway and then calls the `computers` method with a computer ID to retrieve and print the computer's name. ```python from printnodeapi import Gateway gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey') print(gateway.computers(computer=10027).name) ``` -------------------------------- ### Initialize PrintNode Gateway with Client Key Source: https://context7.com/printnode/printnode-python/llms.txt Initializes the PrintNode API gateway using a client key for delegated authentication. This method is employed when a client application is authorized to act on behalf of a user without direct access to their credentials. It allows access to account information. ```python from printnodeapi import Gateway # Initialize with client key gateway = Gateway(clientkey='ck-abc123def456ghi789jkl') # Access account information print(gateway.account.firstname) ``` -------------------------------- ### Initialize PrintNode Gateway with API Key Source: https://context7.com/printnode/printnode-python/llms.txt Initializes the PrintNode API gateway using an API key for authentication. This is the primary method for authenticating programmatic access to the PrintNode service. It allows for direct interaction with account resources. ```python from printnodeapi import Gateway # Initialize with API key gateway = Gateway(apikey='your_secret_api_key') # Access account information print(gateway.account.firstname) print(gateway.account.email) print(gateway.account.id) ``` -------------------------------- ### Initialize PrintNode Gateway with Email and Password Source: https://context7.com/printnode/printnode-python/llms.txt Initializes the PrintNode API gateway using email and password credentials. This method is suitable for authenticating user accounts directly. It provides access to account details like name, total prints, and credits. ```python from printnodeapi import Gateway # Initialize with email and password gateway = Gateway(email='user@example.com', password='secure_password') # Access account details account = gateway.account print(f"Account: {account.firstname} {account.lastname}") print(f"Total prints: {account.total_prints}") print(f"Credits: {account.credits}") ``` -------------------------------- ### Create Print Job using Python Source: https://github.com/printnode/printnode-python/blob/master/README.md This class is used to create a new print job. It supports creating jobs via a URI, base64 encoded data, or raw binary data. Optional parameters include printer, job type, title, and other settings. An API key and the printnodeapi Gateway are required. ```python from printnodeapi import Gateway gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey') print(gateway.PrintJob(printer=50120,options={"copies":2},uri="a.pdf")) ``` -------------------------------- ### Create API Key in Python Source: https://context7.com/printnode/printnode-python/llms.txt Generates a new API key for the authenticated account. The key is associated with a specified name (e.g., 'Staging'). The function returns the newly created API key and allows for verification by checking the account's list of API keys. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Create new API key new_key = gateway.CreateApiKey('Staging') print(f"New API key created: {new_key}") # Verify API key was created print(gateway.account.api_keys) ``` -------------------------------- ### Generate Client Key in Python Source: https://context7.com/printnode/printnode-python/llms.txt Creates a client key, which is used for delegated authentication. This key is generated using the account's API key and requires parameters like UUID, edition, and version. The generated client key can then be used to instantiate a new Gateway object for authentication. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Generate client key client_key = gateway.clientkey( uuid='0a756864-602e-428f-a90b-842dee47f57e', edition='printnode', version='4.7.2' ) print(f"Client Key: {client_key}") # Use client key to authenticate client_gateway = Gateway(clientkey=client_key) print(f"Authenticated as: {client_gateway.account.email}") ``` -------------------------------- ### Alternate PrintNode API Gateway Authentication Methods Source: https://github.com/printnode/printnode-python/blob/master/README.md Illustrates alternative methods for authenticating the PrintNode API Gateway besides using an API key. These include using email and password, or a client key. ```python Gateway(email='email',password='password') Gateway(clientkey='ckey') ``` -------------------------------- ### Generate Client Key using Python Source: https://github.com/printnode/printnode-python/blob/master/README.md Generates a client key for an account using the PrintNode Python API. This function requires the account's UUID, edition, and version. It initializes a Gateway with an API key and then calls the clientkey method. The result is printed and the account is subsequently deleted. ```python from printnodeapi import Gateway gateway=Gateway(url='https://api.printnode.com',apikey='secretAPIKey') new_account = gateway.CreateAccount( firstname="A", lastname="Person", password="password", email="aperson@emailprovider.com", tags={"Likes":"Something"}, api_keys=["Production"] ) new_account_gateway = Gateway(url='https://api.printnode.com',apikey='secretAPIKey',child_id=new_account["Account"]["id"]) new_clientkey = new_account_gateway.clientkey( uuid="0a756864-602e-428f-a90b-842dee47f57e", edition="printnode", version="4.7.2") print(new_clientkey) new_account_gateway.DeleteAccount() ``` -------------------------------- ### Access Child Account Source: https://context7.com/printnode/printnode-python/llms.txt Connects to a previously created child account to perform operations as that account. It first creates a child account and then initializes a new Gateway object with the parent API key and the child account ID to switch context. ```python from printnodeapi import Gateway gateway = Gateway(apikey='parent_api_key') # Create child account new_account = gateway.CreateAccount( firstname='Bob', lastname='Johnson', email='bob.johnson@example.com', password='password456' ) child_id = new_account['Account']['id'] # Create gateway for child account child_gateway = Gateway(apikey='parent_api_key', child_id=child_id) # Perform operations as child account print(f"Child account name: {child_gateway.account.firstname}") print(f"Child account email: {child_gateway.account.email}") ``` -------------------------------- ### List All Printers using Python Source: https://context7.com/printnode/printnode-python/llms.txt Fetches a list of all printers accessible through the PrintNode API. It requires an API key for authentication. The function iterates through the returned printers, printing their details such as ID, name, description, associated computer, default status, and current state. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Get all printers printers = gateway.printers() for printer in printers: print(f"ID: {printer.id}") print(f"Name: {printer.name}") print(f"Description: {printer.description}") print(f"Computer: {printer.computer.name}") print(f"Default: {printer.default}") print(f"State: {printer.state}") print("---") ``` -------------------------------- ### Create Child Account Source: https://context7.com/printnode/printnode-python/llms.txt Creates a new sub-account (child account) under the current account. This function allows specifying account details such as name, email, password, creator reference, API keys, and tags. The output includes the new account's ID, email, API keys, and tags. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Create child account with tags and API keys new_account = gateway.CreateAccount( firstname='Jane', lastname='Smith', email='jane.smith@example.com', password='secure_password123', creator_ref='customer_12345', api_keys=['Production', 'Development'], tags={'customer_id': '12345', 'plan': 'business'} ) print(f"Account ID: {new_account['Account']['id']}") print(f"Email: {new_account['Account']['email']}") print(f"API Keys: {new_account['Account']['ApiKeys']}") print(f"Tags: {new_account['Account']['Tags']}") ``` -------------------------------- ### List Printers for Specific Computer using Python Source: https://context7.com/printnode/printnode-python/llms.txt Fetches all printers associated with a particular computer, identified by its ID. Authentication with an API key is necessary. The output lists the names of the printers and indicates if each one is set as the default printer for that computer. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Get all printers for a computer printers = gateway.printers(computer=10027) for printer in printers: print(f"{printer.name} - Default: {printer.default}") ``` -------------------------------- ### Error Handling with PrintNode API (Python) Source: https://context7.com/printnode/printnode-python/llms.txt Demonstrates how to handle API errors using custom exception types provided by the 'printnodeapi' library. It covers authentication, client, server, and network errors, as well as handling specific lookup errors. ```python from printnodeapi import Gateway, Unauthorized, ClientError, ServerError, NetworkError try: # Attempt to connect with invalid credentials gateway = Gateway(apikey='invalid_api_key') account = gateway.account except Unauthorized as e: print(f"Authentication failed: {e.message}") print(f"Status code: {e.status_code}") print(f"Error code: {e.code}") except ClientError as e: print(f"Client error: {e.message}") except ServerError as e: print(f"Server error: {e.message}") except NetworkError as e: print(f"Network error: {e}") # Try to get non-existent printer try: gateway = Gateway(apikey='valid_api_key') printer = gateway.printers(printer=99999) except LookupError as e: print(f"Printer not found: {e}") # Output: # Authentication failed: Invalid credentials # Status code: 401 # Error code: AuthenticationError ``` -------------------------------- ### Submit Print Job with Binary Data using Python Source: https://context7.com/printnode/printnode-python/llms.txt Submits a print job using raw binary data from a file. This function requires an API key and the printer ID. The code snippet shows how to open a file in binary read mode and read its content. Further steps would involve passing this binary content to the PrintJob constructor. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Read binary file with open('/path/to/document.pdf', 'rb') as f: binary_content = f.read() ``` -------------------------------- ### Access Account Information via Gateway Source: https://github.com/printnode/printnode-python/blob/master/README.md Shows how to access account-specific information, such as the account ID and modifying tags, after initializing the Gateway object. This assumes the Gateway is already authenticated. ```python my_account_id = my_account_gateway.account.id new_tag = my_account_gateway.ModifyTag("Likes","PrintNode") ``` -------------------------------- ### Initialize PrintNode Gateway for Child Account Access Source: https://context7.com/printnode/printnode-python/llms.txt Initializes the PrintNode API gateway to access child accounts using a parent API key. It supports specifying the child account via email, a custom reference, or its ID. This is useful for managing sub-accounts within a parent account structure. ```python from printnodeapi import Gateway # Access child account by email gateway = Gateway(apikey='parent_api_key', child_email='child@example.com') # Access child account by creator reference gateway = Gateway(apikey='parent_api_key', child_ref='my_child_ref') # Access child account by ID gateway = Gateway(apikey='parent_api_key', child_id=67890) # Verify child account access print(gateway.account.email) print(gateway.account.creator_email) ``` -------------------------------- ### Enable or Disable Client Downloads (Python) Source: https://context7.com/printnode/printnode-python/llms.txt Controls which client versions are available for download by enabling or disabling them. This function requires the 'printnodeapi' library and takes a client_id and an enabled boolean as input. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Disable old client version result = gateway.ModifyClientDownloads(client_id=10, enabled=False) print(f"Client 10 disabled: {result}") # Check status clients = gateway.clients(client_ids=10) if clients: print(f"Client 10 enabled status: {clients[0].enabled}") # Re-enable client gateway.ModifyClientDownloads(client_id=10, enabled=True) # Output: # Client 10 disabled: [{'id': 10, 'enabled': False, ...}] # Client 10 enabled status: False ``` -------------------------------- ### Submit Print Job with Python using PrintNode Source: https://context7.com/printnode/printnode-python/llms.txt Submits a print job to the first available printer using the PrintNode API. It retrieves available printers, creates a PrintJob object with specified details (printer ID, title, type, URI, options), and then submits it. The code also includes logic to fetch and display the states of the submitted print job after a short delay. ```python if computers and len(computers) > 0: all_printers = child_gateway.printers() if all_printers: target_printer = all_printers[0] # Submit print job printjob = child_gateway.PrintJob( printer=target_printer.id, title='Welcome Document', job_type='pdf', uri='https://example.com/welcome.pdf', options={'copies': 1} ) print(f"\nSubmitted print job {printjob.id}") print(f"Status: {printjob.state}") # Check print job states import time time.sleep(2) # Wait for processing states = child_gateway.states(printjob.id) if states and len(states) > 0: for state in states[0]: print(f" {state.state}: {state.message}") ``` -------------------------------- ### Submit Print Job with Binary Data (Python) Source: https://context7.com/printnode/printnode-python/llms.txt Submits a print job containing binary content, such as a PDF file. Requires the printer ID, title, job type, and binary data. The 'options' parameter allows for further customization like the number of copies. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Assume binary_content is loaded here # binary_content = b'...your PDF content...' printjob = gateway.PrintJob( printer=50120, title='Shipping Label', job_type='pdf', binary=binary_content, qty=5, options={'copies': 1} ) print(f"PrintJob ID: {printjob.id}") print(f"Quantity: {printjob.qty}") ``` -------------------------------- ### List All PrintNode Computers Source: https://context7.com/printnode/printnode-python/llms.txt Retrieves a list of all computers associated with the authenticated PrintNode account. For each computer, it displays its ID, name, hostname, connection state, client version, and creation timestamp. This function is essential for managing printing endpoints. ```python from printnodeapi import Gateway gateway = Gateway(apikey='your_secret_api_key') # Get all computers computers = gateway.computers() for computer in computers: print(f"ID: {computer.id}") print(f"Name: {computer.name}") print(f"Hostname: {computer.hostname}") print(f"State: {computer.state}") print(f"Version: {computer.version}") print(f"Created: {computer.create_timestamp}") print("---") ```