### Count and Get Options Example (Python) Source: https://api.truenas.com/v26.04/api_methods_virt.instance.get_instance Demonstrates using 'count' to get the number of matching instances and 'get' to retrieve the first matching instance with the virt.instance.get_instance method. ```python import zapi api = zapi.Client("api_truenas_v26_04") # Example: Get the count of instances matching certain criteria count_result = api.call("virt.instance.get_instance", options={ "count": True, "query-filters": { "status": "RUNNING" } }) print(f"Number of running instances: {count_result}") # Example: Get the first instance matching criteria first_instance = api.call("virt.instance.get_instance", options={ "get": True, "query-filters": { "name": "my_vm" } }) print(f"First matching instance: {first_instance}") ``` -------------------------------- ### JavaScript Example: Starting an Application Source: https://api.truenas.com/v26.04/api_methods_failover.disabled A JavaScript example for starting a TrueNAS application using the 'app.start' method. This requires the application's ID as a parameter. The response indicates whether the start operation was successful. Ensure the application is in a state where it can be started. ```javascript async function startApplication(appId) { const response = await fetch('/api/v2.0/app/start', { method: 'POST', headers: { 'Content-Type': 'application/json', // Include authentication headers if needed }, body: JSON.stringify({ id: appId }) }); const data = await response.json(); console.log(`Application ${appId} start response:`, data); // Handle the start operation result } // Example usage: // startApplication(123); // Replace 123 with the actual App ID ``` -------------------------------- ### POST vm.start Source: https://api.truenas.com/v26.04/api_events_container.metrics Starts a virtual machine, bringing it online. ```APIDOC ## POST vm.start ### Description Starts a virtual machine. ### Method POST ### Endpoint /vm.start ### Parameters None ### Request Example None ### Response #### Success Response (200) - **job_id** (integer) - The ID of the job. #### Response Example { "job_id": 789 } ``` -------------------------------- ### Example: Query Applications (Python) Source: https://api.truenas.com/v26.04/api_methods_disk.temperatures Demonstrates how to query information about installed applications on the TrueNAS system. This can be used to get details about running applications and their configurations. ```python import websocket import json ws = websocket.create_connection("ws://your_truenas_ip:port/websocket") request = { "jsonrpc": "2.0", "method": "app.query", "params": [], "id": 3 } ws.send(json.dumps(request)) result = ws.recv() print(result) ws.close() ``` -------------------------------- ### POST vm.start Source: https://api.truenas.com/v26.04/api_events_docker Starts a virtual machine. ```APIDOC ## POST vm.start ### Description Starts a virtual machine, bringing it into an operational state. ### Method POST ### Endpoint /api/truenas/v26.04/vm.start ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the virtual machine to start. ### Request Example { "id": 1 } ### Response #### Success Response (200) - **job_id** (integer) - The job ID for the start operation. #### Response Example { "job_id": 789 } ``` -------------------------------- ### Example Bootloader Configuration (UEFI) Source: https://api.truenas.com/v26.04/api_methods_vm.query Example of setting the bootloader to UEFI for a virtual machine. This enables modern UEFI booting capabilities. ```json { "bootloader": "UEFI" } ``` -------------------------------- ### Python: Get All System Certificates Source: https://api.truenas.com/v26.04/api_methods_pool.snapshottask.update Example of querying all system certificates using the `certificate.query` method in Python. This function returns a list of all installed certificates on the TrueNAS system, including their details and properties. ```python import websocket import json ws = websocket.create_connection("ws://your-truenas-ip:5000/websocket") request_payload = { "jsonrpc": "2.0", "method": "certificate.query", "params": [], "id": 1 } ws.send(json.dumps(request_payload)) result = ws.recv() print(result) ws.close() ``` -------------------------------- ### boot API Methods Source: https://api.truenas.com/v26.04/api_methods_virt.instance No description -------------------------------- ### GET /api/v2.0/service/started_or_enabled Source: https://api.truenas.com/v26.04/_sources/api_methods_service.started_or_enabled.rst Tests if a specified service is currently started or configured to start automatically on boot. Requires SERVICE_READ role. ```APIDOC ## GET /api/v2.0/service/started_or_enabled ### Description This endpoint checks if a given service is currently running or is enabled to start automatically upon system boot. It requires the user to have the SERVICE_READ role. ### Method GET ### Endpoint /api/v2.0/service/started_or_enabled ### Parameters #### Query Parameters - **service** (string) - Required - The name of the service to check. ### Request Example ``` { "service": "nginx" } ``` ### Response #### Success Response (200) - **result** (boolean) - True if the service is started or enabled, false otherwise. #### Response Example ```json { "result": true } ``` ``` -------------------------------- ### POST /vm.start Source: https://api.truenas.com/v26.04/api_events_iscsi.extent Starts a virtual machine. This powers on the VM, making it active and operational. ```APIDOC ## POST /vm.start ### Description Starts a virtual machine. ### Method POST ### Endpoint /vm.start ### Parameters #### Path Parameters - **id** (integer) - Required - The ID of the virtual machine to start. ### Request Example { "id": 1 } ### Response #### Success Response (200) - **job_id** (integer) - The ID of the job that was created to start the VM. #### Response Example { "job_id": 789 } ``` -------------------------------- ### app.available_space Source: https://api.truenas.com/v26.04/api_methods_system.general.country_choices Gets information about the available space for installing applications. ```APIDOC ## GET app.available_space ### Description Gets available space for application installation. ### Method GET ### Endpoint app.available_space ### Parameters No parameters. ### Request Example ```json {} ``` ### Response #### Success Response (200) - **available_space** (integer) - The amount of available space. #### Response Example ```json { "available_space": 100000000000 } ``` ``` -------------------------------- ### Query Options Example (Python) Source: https://api.truenas.com/v26.04/api_methods_virt.instance.get_instance Demonstrates how to use query options with the virt.instance.get_instance method in Python. This example shows how to select specific fields, order the results, and limit the number of returned items. ```python import zapi api = zapi.Client("api_truenas_v26_04") # Example: Select specific fields, order by name, and limit to 5 results instance_data = api.call("virt.instance.get_instance", id="your_instance_id", options={ "select": ["id", "name", "status"], "order_by": ["name"], "limit": 5 }) print(instance_data) ``` -------------------------------- ### virt.instance.start Source: https://api.truenas.com/v26.04/api_methods_virt.instance Starts a stopped virtual machine instance. ```APIDOC ## POST /api/v2.0/virt/instance/start ### Description Starts a virtual machine instance that is currently stopped. ### Method POST ### Endpoint /api/v2.0/virt/instance/start ### Parameters #### Request Body - **name** (string) - Required - The name or ID of the instance to start. ### Request Example ```json { "name": "vm-12345" } ``` ### Response #### Success Response (200) - **result** (boolean) - True if the instance was successfully started. #### Response Example ```json { "result": true } ``` ``` -------------------------------- ### Periodic Snapshot Task Schedule Start Times Source: https://api.truenas.com/v26.04/_sources/api_methods_replication.create.rst Examples of valid start times for periodic snapshot tasks. These are strings representing time in HH:MM format. ```json "06:30" ``` ```json "18:00" ``` ```json "23:00" ``` -------------------------------- ### GET /system/ready Source: https://api.truenas.com/v26.04/_sources/api_methods_system.ready.rst Returns a boolean indicating whether the system has completed boot and is ready to use. ```APIDOC ## GET /system/ready ### Description Returns a boolean indicating whether the system has completed boot and is ready to use. ### Method GET ### Endpoint /system/ready ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example None ### Response #### Success Response (200) - **ready** (boolean) - Whether the system has completed startup and is ready for use. #### Response Example { "ready": true } ``` -------------------------------- ### Query Applications Example Source: https://api.truenas.com/v26.04/api_methods_app.image.pull Example of querying the status and details of installed applications using the `app.query` method. This provides an overview of the application environment. ```json { "jsonrpc": "2.0", "method": "app.query", "params": [], "id": 1 } ``` -------------------------------- ### app.available_space Source: https://api.truenas.com/v26.04/api_methods_filesystem.statfs Gets the available space for an application. This informs about the space available for installation and operation. ```APIDOC ## GET app.available_space ### Description Gets the available space for an application. ### Method GET ### Endpoint app.available_space ### Parameters #### Path Parameters - **app_name** (string) - Required - The name of the application. ### Request Example ```json { "example": "" } ``` ### Response #### Success Response (200) - **available_space** (object) - The available space information. #### Response Example ```json { "available_space": { "available": 100000000000, "unit": "bytes" } } ``` ``` -------------------------------- ### Python Example: Starting an Application Source: https://api.truenas.com/v26.04/api_methods_boot.environment.activate This Python snippet shows how to start a TrueNAS application using the `app.start` method. It requires the application's ID or name. Ensure the application is correctly configured before attempting to start it. ```python import requests # Assume you have a WebSocket connection established and a session_id session_id = "YOUR_SESSION_ID" start_app_request = { "jsonrpc": "2.0", "method": "app.start", "params": [ "your_app_id_or_name" # e.g., "my-nextcloud-app" ], "id": 4 } # Send the request over the WebSocket connection print(f"Sending start app request: {start_app_request}") # Example response: # { # "jsonrpc": "2.0", # "result": null, # Success is indicated by null result for start operation # "id": 4 # } ``` -------------------------------- ### Query Init/Shutdown Scripts with Filters and Options Source: https://api.truenas.com/v26.04/api_methods_initshutdownscript.query This example demonstrates how to query init/shutdown scripts using filters and various options. It shows how to specify filters for script names, use OR conditions, and apply options like selecting specific fields, ordering, and pagination. This is useful for retrieving a subset of scripts based on complex criteria. ```python from middlewaredy.client import Client client = Client() # Example 1: Filter by name and select specific fields filters1 = [ ["name", "=", "my_script"], ] options1 = { "select": ["id", "name", "type"], "order_by": ["name"], "limit": 10 } result1 = client.call("initshutdownscript.query", filters1, options1) print(result1) # Example 2: Use OR condition and retrieve count filters2 = [ ["OR", [ ["type", "=", "COMMAND"] ], [ ["type", "=", "SCRIPT"] ] ] ] options2 = { "count": True } result2 = client.call("initshutdownscript.query", filters2, options2) print(result2) # Example 3: Get a single script by name using 'get' option filters3 = [ ["name", "=", "specific_script"] ] options3 = { "get": True } try: result3 = client.call("initshutdownscript.query", filters3, options3) print(result3) except Exception as e: print(f"Error getting script: {e}") # Example 4: Query with offset and limit for pagination filters4 = [] options4 = { "offset": 10, "limit": 5, "order_by": ["-id"] } result4 = client.call("initshutdownscript.query", filters4, options4) print(result4) ``` -------------------------------- ### Querying VM Devices with Ordering and Selection (Python) Source: https://api.truenas.com/v26.04/api_methods_vm.device.query Example demonstrating how to query VM devices with specific ordering and field selection. This function utilizes the 'order_by' and 'select' options to refine the query results. ```python from pydantic import BaseModel from typing import List, Dict, Any, Union class VMDeviceQueryOptions(BaseModel): extra: Dict[str, Any] = {} order_by: List[str] = [] select: List[str] = [] count: bool = False get: bool = False offset: int = 0 limit: int = 0 force_sql_filters: bool = False class VMDeviceQueryFilters(BaseModel): filters: List[List[Union[str, int, List]]] options: VMDeviceQueryOptions = VMDeviceQueryOptions() def query_vm_devices_ordered_selected(filters: List[List[Union[str, int, List]]], options: VMDeviceQueryOptions = VMDeviceQueryOptions()) -> List[Dict[str, Any]]: """ Queries VM devices with specified filters, ordering, and field selection. Args: filters: A list of filters for query results. options: Query options including pagination, ordering, and specific fields to select. Returns: A list of dictionaries representing the query results with selected fields. """ # Placeholder for actual API call print(f"Querying with filters: {filters}") print(f"And options: {options.dict()}") # In a real scenario, this would involve an API client call like: # return api_client.post('/vm/device/query', json={'filters': filters, 'options': options.dict()}) return [] # Example Usage: example_filters_3 = [] # No specific filters, applying options to all devices example_options_3 = VMDeviceQueryOptions( order_by=["size", "-devname", "nulls_first:-expiretime"], select=["username", "Authentication.status"] ) results_3 = query_vm_devices_ordered_selected(example_filters_3, example_options_3) print(f"Results 3: {results_3}") ``` -------------------------------- ### Example CD-ROM Device Configuration Source: https://api.truenas.com/v26.04/api_methods_vm.query Example of configuring a CD-ROM device for a virtual machine. It specifies the device type and the path to the CD-ROM image. The path must not contain '{' or '}' and should start with '/mnt/'. ```json { "dtype": "CDROM", "path": "/mnt/iso/my_os.iso" } ``` -------------------------------- ### Configure SMB Share for User Home Directories (JSON Example) Source: https://api.truenas.com/v26.04/api_methods_sharing.smb.create Sets up the SMB share to store user home directories. This changes the share name to 'homes' and creates dynamic shares based on usernames. Requires valid user home directories and shells for authentication. ```json { "home": true } ``` -------------------------------- ### JavaScript Example: Starting an Application Source: https://api.truenas.com/v26.04/api_events_truecommand This JavaScript code illustrates how to start a TrueNAS application using the `app.start` method. It requires the application ID as input. ```javascript const ws = new WebSocket("ws://localhost:8000/websocket"); ws.onopen = () => { const request = { "jsonrpc": "2.0", "method": "app.start", "params": [123], // Replace 123 with the actual App ID "id": 1 }; ws.send(JSON.stringify(request)); }; ws.onmessage = (event) => { console.log(JSON.parse(event.data)); }; ws.onerror = (error) => { console.error("WebSocket Error: ", error); }; ``` -------------------------------- ### filesystem.acltemplate.get_instance with Query Options Source: https://api.truenas.com/v26.04/api_methods_filesystem.acltemplate.get_instance Illustrates the use of query options with filesystem.acltemplate.get_instance. It shows how to specify fields to select, order the results, and apply limits for pagination or specific result retrieval. ```python import json args = { "id": 1, "options": { "select": [ "id", "name", "acltype", "acl.tag", "acl.type", "acl.perms" ], "order_by": [ "acl.tag", "-acl.perms" ], "limit": 10, "offset": 0, "count": False, "get": False, "force_sql_filters": False } } print(json.dumps(truenas.call_api('filesystem.acltemplate.get_instance', args))) ``` -------------------------------- ### NVMe-oF Namespace Get Instance Example Source: https://api.truenas.com/v26.04/api_methods_nvmet.namespace.get_instance Example demonstrating how to retrieve an NVMe-oF namespace instance using its ID and various query options. This includes specifying fields to select, ordering the results, and applying filters. The example illustrates the structure of the request payload. ```python from pprint import pprint from middlewaredy.client import Client async def main(): async with Client() as client: pprint(await client.call("nvmet.namespace.get_instance", 1, { "select": ["id", "nsid", "subsys.name"], "order_by": ["-id"], "extra": { "allow_any_host": True } })) if __name__ == "__main__": import asyncio asyncio.run(main()) ``` -------------------------------- ### Example Version Values (String) Source: https://api.truenas.com/v26.04/_sources/api_methods_app.create.rst Illustrates example string values for the 'version' parameter, indicating the application version to install. The version string must be at least 1 character long. Examples include 'latest' and specific version numbers like '1.2.3'. ```string "latest" ``` ```string "1.2.3" ``` -------------------------------- ### VM Configuration Parameters - Python Example Source: https://api.truenas.com/v26.04/api_events_vm.query This Python snippet demonstrates how to configure various parameters for a virtual machine, including CPU settings, memory, bootloader, and advanced features. It covers options like CPU mode, model, topology, pinning, memory allocation, bootloader type, and Hyper-V enlightenments. ```python vm_config = { "name": "my_vm", "memory": 2048, # 2GB RAM "vcpus": 2, "cores": 1, "threads": 1, "cpu_mode": "HOST-MODEL", "cpu_model": None, # Use hypervisor default "cpuset": None, # No CPU pinning "nodeset": None, # No NUMA node constraints "enable_cpu_topology_extension": False, "pin_vcpus": False, "suspend_on_snapshot": False, "trusted_platform_module": False, "min_memory": 1024, # Minimum memory for ballooning "hyperv_enlightenments": True, "bootloader": "UEFI", "bootloader_ovmf": "OVMF_CODE.fd", "autostart": True, "hide_from_msr": False, "ensure_display_device": True, "time": "LOCAL", "shutdown_timeout": 120, "arch_type": None, # Use hypervisor default "machine_type": None # Use hypervisor default } ``` -------------------------------- ### SMB Query Options Example (Python) Source: https://api.truenas.com/v26.04/api_methods_sharing.smb.query Shows how to define query options for the sharing.smb.query API. This example includes ordering by 'size' and reverse ordering by 'devname', along with specific field selection and pagination parameters. ```python options = { "order_by": ["size", "-devname"], "select": ["id", "name", "size"], "limit": 10, "offset": 0 } ``` -------------------------------- ### SMB Share Path Examples Source: https://api.truenas.com/v26.04/api_events_sharing.smb.query Examples of valid local server paths for SMB shares. Paths must start with '/mnt/' and be within a ZFS pool, or be the string 'EXTERNAL' for DFS proxy shares. ```text "/mnt/dozer/SHARE" ``` ```text "EXTERNAL" ``` -------------------------------- ### Get Single API Key Source: https://api.truenas.com/v26.04/api_methods_api_key.query This example shows how to use the 'get' option to retrieve only the first API key that matches the specified filters. This is useful when you expect a unique result or only need one record. ```python api_key.query( filters=[ ["id", "=", 123] ], options={ "get": True } ) ``` -------------------------------- ### Querying VM Devices with Pagination (Python) Source: https://api.truenas.com/v26.04/api_methods_vm.device.query Example demonstrating how to query VM devices with pagination using 'limit' and 'offset' options. This is useful for handling large datasets by retrieving results in chunks. ```python from pydantic import BaseModel from typing import List, Dict, Any, Union class VMDeviceQueryOptions(BaseModel): extra: Dict[str, Any] = {} order_by: List[str] = [] select: List[str] = [] count: bool = False get: bool = False offset: int = 0 limit: int = 0 force_sql_filters: bool = False class VMDeviceQueryFilters(BaseModel): filters: List[List[Union[str, int, List]]] options: VMDeviceQueryOptions = VMDeviceQueryOptions() def query_vm_devices_paginated(filters: List[List[Union[str, int, List]]], options: VMDeviceQueryOptions = VMDeviceQueryOptions()) -> List[Dict[str, Any]]: """ Queries VM devices with specified filters and pagination options. Args: filters: A list of filters for query results. options: Query options including limit and offset for pagination. Returns: A list of dictionaries representing a page of query results. """ # Placeholder for actual API call print(f"Querying with filters: {filters}") print(f"And options: {options.dict()}") # In a real scenario, this would involve an API client call like: # return api_client.post('/vm/device/query', json={'filters': filters, 'options': options.dict()}) return [] # Example Usage: example_filters_4 = [] # No specific filters example_options_4 = VMDeviceQueryOptions( limit=10, offset=20 ) results_4 = query_vm_devices_paginated(example_filters_4, example_options_4) print(f"Results 4 (Page 3 of 10 items): {results_4}") ``` -------------------------------- ### List Available Applications Example Source: https://api.truenas.com/v26.04/api_methods_app.image.pull Example of listing available applications that can be installed or managed using the `catalog.apps` method. This helps in discovering software options within TrueNAS. ```json { "jsonrpc": "2.0", "method": "catalog.apps", "params": [], "id": 1 } ``` -------------------------------- ### GET /system.ready Source: https://api.truenas.com/v26.04/api_methods_user.set_password Checks if the system is ready. This endpoint is used to determine if the system has completed its startup process and is ready to accept requests. It provides readiness status. ```APIDOC ## GET /system.ready ### Description Checks if the system is ready. ### Method GET ### Endpoint /system.ready ### Parameters None ### Request Example None ### Response #### Success Response (200) - **ready** (boolean) - True if the system is ready, false otherwise. #### Response Example { "ready": true } ``` -------------------------------- ### GET /vm/get_vm_memory_info Source: https://api.truenas.com/v26.04/_sources/api_methods_vm.get_vm_memory_info.rst Retrieves memory information for a specified VM if it is about to be started. All memory values are returned in bytes. ```APIDOC ## GET /vm/get_vm_memory_info ### Description Returns memory information for `vm_id` VM if it is going to be started. All memory attributes are expressed in bytes. ### Method GET ### Endpoint /vm/get_vm_memory_info ### Parameters #### Query Parameters - **id** (integer) - Required - ID of the virtual machine to get memory information for. ### Request Example ```json { "id": 1 } ``` ### Response #### Success Response (200) - **minimum_memory_requested** (integer | null) - Minimum memory requested by the VM. - **total_memory_requested** (integer | null) - Total memory requested by the VM. #### Response Example ```json { "minimum_memory_requested": 1073741824, "total_memory_requested": 2147483648 } ``` ``` -------------------------------- ### Pagination Example (Python) Source: https://api.truenas.com/v26.04/api_methods_virt.instance.get_instance Provides an example of implementing pagination using 'offset' and 'limit' with the virt.instance.get_instance method to retrieve data in chunks. ```python import zapi api = zapi.Client("api_truenas_v26_04") page_size = 10 current_offset = 0 # Fetch first page instances_page1 = api.call("virt.instance.get_instance", options={ "limit": page_size, "offset": current_offset }) print(f"Page 1: {instances_page1}") # Fetch second page current_offset += page_size instances_page2 = api.call("virt.instance.get_instance", options={ "limit": page_size, "offset": current_offset }) print(f"Page 2: {instances_page2}") ``` -------------------------------- ### Get Application Available Space Example Source: https://api.truenas.com/v26.04/api_methods_app.image.pull Example of retrieving the available disk space for applications using the `app.available_space` method. This helps in capacity planning and monitoring storage usage. ```json { "jsonrpc": "2.0", "method": "app.available_space", "params": [], "id": 1 } ``` -------------------------------- ### Get Application Instance Example Source: https://api.truenas.com/v26.04/api_methods_app.image.pull Example of retrieving details about a specific running application instance using the `app.get_instance` method. This provides information about the application's configuration and status. ```json { "jsonrpc": "2.0", "method": "app.get_instance", "params": [ 123 ], "id": 1 } ``` -------------------------------- ### Virtual Machine Autostart and Display Settings Source: https://api.truenas.com/v26.04/_sources/api_methods_vm.get_instance.rst Configuration for automatic virtual machine startup and display device behavior. ```APIDOC ## PUT /websites/api_truenas_v26_04 (Example - Conceptual) ### Description Updates virtual machine autostart and display device settings. ### Method PUT ### Endpoint /websites/api_truenas_v26_04 ### Parameters #### Request Body - **autostart** (boolean) - Required - Whether to automatically start the VM when the host system boots. Default: true. - **hide_from_msr** (boolean) - Optional - Whether to hide hypervisor signatures from guest OS MSR access. Default: false. - **ensure_display_device** (boolean) - Optional - Controls the behavior of the display device. (Further details not provided in the input). ### Request Example ```json { "autostart": false, "hide_from_msr": true } ``` ### Response #### Success Response (200) - **message** (string) - Confirmation message indicating the settings have been updated. #### Response Example ```json { "message": "VM settings updated successfully." } ``` ``` -------------------------------- ### Get Available IP Choices Example Source: https://api.truenas.com/v26.04/api_methods_app.image.pull Example of retrieving available IP address choices for applications using the `app.ip_choices` method. This is useful when configuring network settings for applications. ```json { "jsonrpc": "2.0", "method": "app.ip_choices", "params": [], "id": 1 } ``` -------------------------------- ### POST container.start Source: https://api.truenas.com/v26.04/api_events_app.query Starts a container. ```APIDOC ## POST container.start ### Description Starts a previously stopped container. ### Method POST ### Endpoint /api/container.start ### Parameters ### Request Example { "example": "" } ### Response #### Success Response (200) - **message** (string) - Confirmation message #### Response Example { "message": "Container started" } ``` -------------------------------- ### Get Boot Environment State Example Source: https://api.truenas.com/v26.04/api_methods_app.image.pull Example of retrieving the current state of a boot environment using the `boot.get_state` method. This provides information about the active or selected boot environment. ```json { "jsonrpc": "2.0", "method": "boot.get_state", "params": [], "id": 1 } ``` -------------------------------- ### GET /system.ready Source: https://api.truenas.com/v26.04/api_methods_nfs.client_count Checks if the system is ready. ```APIDOC ## GET /system.ready ### Description Checks if the system is ready. ### Method GET ### Endpoint /system.ready ### Parameters None ### Request Example ```json {} ``` ### Response #### Success Response (200) - **ready** (boolean) - Indicates if the system is ready. #### Response Example ```json { "ready": true } ``` ``` -------------------------------- ### Example virt.volume.get_instance Usage with Select and Get Source: https://api.truenas.com/v26.04/api_methods_virt.volume.get_instance Shows how to use virt.volume.get_instance to retrieve specific fields ('username', 'Authentication.status') and return only the first matching JSON object. The 'get' option ensures only one result is returned. ```python from pprint import pprint # Example: Get a specific volume and select specific fields # # The select option accepts a list of strings, specifying the exact fields to # include in the query return. The dot '.' character may be used to explicitly # select only subkeys of the query result. # # The get option returns the JSON object of the first result matching the # specified query-filters. The query fails if the specified query-filters # return no results. # # Example values: # ["username", "Authentication.status"] result = await Calls.virt.volume.get_instance({ "select": [ "username", "Authentication.status" ], "get": True }) pprint(result) ``` -------------------------------- ### Example Options for kerberos.keytab.query Source: https://api.truenas.com/v26.04/api_methods_kerberos.keytab.query Illustrates how to configure query options for 'kerberos.keytab.query', including ordering by multiple fields with reverse sort and nulls first, selecting specific fields, and setting limits. ```json { "extra": {}, "order_by": [ "size", "-devname", "nulls_first:-expiretime" ], "select": [ "username", "Authentication.status" ], "count": false, "get": false, "offset": 0, "limit": 10, "force_sql_filters": false } ``` -------------------------------- ### Example Usage of container.query with Filters and Options Source: https://api.truenas.com/v26.04/api_methods_container.query A complete example showing how to combine filters and options to query container data. This demonstrates a practical application of the container.query parameters. ```python filters = [["name", "=", "my_container"]] options = { "select": ["id", "name", "description"], "order_by": ["-id"], "limit": 1 } # Assuming 'api' is an initialized API client object # results = api.container.query(filters=filters, options=options) ``` -------------------------------- ### Example API Call: Start Application Source: https://api.truenas.com/v26.04/api_events Illustrates the API call to start an application using the 'app.start' method. This typically requires the application's ID or other identifying information. ```json { "jsonrpc": "2.0", "method": "app.start", "params": [123], "id": 3 } ``` -------------------------------- ### Example Train Values (String) Source: https://api.truenas.com/v26.04/_sources/api_methods_app.create.rst Demonstrates example string values for the 'train' parameter, which specifies the catalog train to install from. It must be at least 1 character long. Common values include 'stable' and 'enterprise'. ```string "stable" ``` ```string "enterprise" ``` -------------------------------- ### iscsi.initiator.query Example with Filters and Options Source: https://api.truenas.com/v26.04/api_methods_iscsi.initiator.query Demonstrates how to query iSCSI initiators using specific filters and query options. This includes examples of simple equality filters and more complex OR conditions, alongside options for selecting fields, ordering, and pagination. ```json { "filters": [ ["name", "=", "bob"] ], "options": { "select": ["id", "initiators"], "order_by": ["-id"], "limit": 10, "offset": 0 } } ``` ```json { "filters": [ ["OR", [ [["name", "=", "bob"]], [["name", "=", "larry"]] ]] ], "options": { "select": ["initiators", "comment"], "count": true } } ``` -------------------------------- ### Get First Matching User Object Source: https://api.truenas.com/v26.04/api_methods_user.query This example demonstrates how to retrieve the entire JSON object of the first user that matches the specified filter. The 'get' option is set to True. The query will fail if no users match the filter. ```Python import ixnetwork.api api = ixnetwork.api.Session(address='localhost', port=8080) filters = [ ["name", "=", "bob"] ] first_user = api.user.query(filters=filters, get=True) print(first_user) ``` -------------------------------- ### virt.instance.start Source: https://api.truenas.com/v26.04/_sources/api_methods_virt.instance.start.rst Starts a virtual machine instance. This operation is asynchronous and returns a job ID. ```APIDOC ## POST /virt/instance/start ### Description Starts a virtual machine instance using its ID. This method initiates a job that will perform the start operation. ### Method POST ### Endpoint /virt/instance/start ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **id** (string) - Required - The unique identifier of the virtual instance to start. ### Request Example ```json { "id": "instance-123-abc" } ``` ### Response #### Success Response (200) - **result** (boolean) - True if the instance was successfully started, false otherwise. #### Response Example ```json { "result": true } ``` ### Required Roles VIRT_INSTANCE_WRITE ``` -------------------------------- ### Share Options Examples Source: https://api.truenas.com/v26.04/_sources/api_methods_sharing.smb.query.rst Examples of share options. ```APIDOC ## Share Options Examples ### Example 1 ```json { "auto_snapshot": true } ``` ### Example 2 ```json { "auto_quota": 100 } ``` ``` -------------------------------- ### Query Options - Get First Result Source: https://api.truenas.com/v26.04/api_methods_fcport.query This example demonstrates how to retrieve only the first JSON object that matches the specified filters. The 'get' option set to 'true' will return a single object. The query will fail if no results are found. ```python options = { "get": true } ``` -------------------------------- ### Get Boot Environment Disks Example Source: https://api.truenas.com/v26.04/api_methods_app.image.pull Example of retrieving a list of disks associated with boot environments using the `boot.get_disks` method. This information is useful for understanding system storage and boot configurations. ```json { "jsonrpc": "2.0", "method": "boot.get_disks", "params": [], "id": 1 } ```