integer/array template.get(object parameters)
The method allows to retrieve templates according to the given parameters.
This method is available to users of any type. Permissions to call the method can be revoked in user role settings. See User roles for more information.
(object) Parameters defining the desired output.
The method supports the following parameters.
| Parameter | Type | Description | 
|---|---|---|
| templateids | ID/array | Return only templates with the given template IDs. | 
| groupids | ID/array | Return only templates that belong to the given template groups. | 
| parentTemplateids | ID/array | Return only templates that the given template is linked to. | 
| hostids | ID/array | Return only templates that are linked to the given hosts/templates. | 
| graphids | ID/array | Return only templates that contain the given graphs. | 
| itemids | ID/array | Return only templates that contain the given items. | 
| triggerids | ID/array | Return only templates that contain the given triggers. | 
| with_items | flag | Return only templates that have items. | 
| with_triggers | flag | Return only templates that have triggers. | 
| with_graphs | flag | Return only templates that have graphs. | 
| with_httptests | flag | Return only templates that have web scenarios. | 
| evaltype | integer | Rules for tag searching. Possible values: 0 - (default) And/Or; 2 - Or. | 
| tags | object/array | Return only templates with given tags. Exact match by tag and case-sensitive or case-insensitive search by tag value depending on operator value. Format: [{"tag": "<tag>", "value": "<value>", "operator": "<operator>"}, ...].An empty array returns all templates. Possible operator values: 0 - (default) Contains (substring match, case-insensitive); 1 - Equals (case-sensitive); 2 - Does not contain (substring match, case-insensitive); 3 - Does not equal (case-sensitive); 4 - Exists; 5 - Does not exist. | 
| selectTags | query | Return template tags in the tagsproperty. | 
| selectHosts | query | Return the hosts that are linked to the template in the hostsproperty.Supports count. | 
| selectTemplateGroups | query | Return the template groups that the template belongs to in the templategroupsproperty. | 
| selectTemplates | query | Return templates to which the given template is linked in the templatesproperty.Supports count. | 
| selectParentTemplates | query | Return templates that are linked to the given template in the parentTemplatesproperty.Supports count. | 
| selectHttpTests | query | Return the web scenarios from the template in the httpTestsproperty.Supports count. | 
| selectItems | query | Return items from the template in the itemsproperty.Supports count. | 
| selectDiscoveries | query | Return low-level discoveries from the template in the discoveriesproperty.Supports count. | 
| selectTriggers | query | Return triggers from the template in the triggersproperty.Supports count. | 
| selectGraphs | query | Return graphs from the template in the graphsproperty.Supports count. | 
| selectMacros | query | Return the macros from the template in the macrosproperty. | 
| selectDashboards | query | Return dashboards from the template in the dashboardsproperty.Supports count. | 
| selectValueMaps | query | Return a valuemapsproperty with template value maps. | 
| limitSelects | integer | Limits the number of records returned by subselects. Applies to the following subselects: selectTemplates- results will be sorted byname;selectHosts- sorted byhost;selectParentTemplates- sorted byhost;selectItems- sorted byname;selectDiscoveries- sorted byname;selectTriggers- sorted bydescription;selectGraphs- sorted byname;selectDashboards- sorted byname. | 
| sortfield | string/array | Sort the result by the given properties. Possible values: hostid,host,name,status. | 
| countOutput | boolean | These parameters are described in the reference commentary. | 
| editable | boolean | |
| excludeSearch | boolean | |
| filter | object | |
| limit | integer | |
| output | query | |
| preservekeys | boolean | |
| search | object | |
| searchByAny | boolean | |
| searchWildcardsEnabled | boolean | |
| sortorder | string/array | |
| startSearch | boolean | |
| selectGroups (deprecated) | query | This parameter is deprecated, please use selectTemplateGroupsinstead.Return the template groups that the template belongs to in the groupsproperty. | 
(integer/array) Returns either:
countOutput parameter has been used.Retrieve all data about two templates named "Linux" and "Windows".
{
           "jsonrpc": "2.0",
           "method": "template.get",
           "params": {
               "output": "extend",
               "filter": {
                   "host": [
                       "Linux",
                       "Windows"
                   ]
               }
           },
           "id": 1
       }Response:
{
           "jsonrpc": "2.0",
           "result": [
               {
                   "proxyid": "0",
                   "host": "Linux",
                   "status": "3",
                   "disable_until": "0",
                   "error": "",
                   "available": "0",
                   "errors_from": "0",
                   "lastaccess": "0",
                   "ipmi_authtype": "0",
                   "ipmi_privilege": "2",
                   "ipmi_username": "",
                   "ipmi_password": "",
                   "ipmi_disable_until": "0",
                   "ipmi_available": "0",
                   "snmp_disable_until": "0",
                   "snmp_available": "0",
                   "maintenanceid": "0",
                   "maintenance_status": "0",
                   "maintenance_type": "0",
                   "maintenance_from": "0",
                   "ipmi_errors_from": "0",
                   "snmp_errors_from": "0",
                   "ipmi_error": "",
                   "snmp_error": "",
                   "jmx_disable_until": "0",
                   "jmx_available": "0",
                   "jmx_errors_from": "0",
                   "jmx_error": "",
                   "name": "Linux",
                   "flags": "0",
                   "templateid": "10001",
                   "description": "",
                   "tls_connect": "1",
                   "tls_accept": "1",
                   "tls_issuer": "",
                   "tls_subject": "",
                   "tls_psk_identity": "",
                   "tls_psk": "",
                   "uuid": "282ffe33afc74cccaf1524d9aa9dc502"
               },
               {
                   "proxyid": "0",
                   "host": "Windows",
                   "status": "3",
                   "disable_until": "0",
                   "error": "",
                   "available": "0",
                   "errors_from": "0",
                   "lastaccess": "0",
                   "ipmi_authtype": "0",
                   "ipmi_privilege": "2",
                   "ipmi_username": "",
                   "ipmi_password": "",
                   "ipmi_disable_until": "0",
                   "ipmi_available": "0",
                   "snmp_disable_until": "0",
                   "snmp_available": "0",
                   "maintenanceid": "0",
                   "maintenance_status": "0",
                   "maintenance_type": "0",
                   "maintenance_from": "0",
                   "ipmi_errors_from": "0",
                   "snmp_errors_from": "0",
                   "ipmi_error": "",
                   "snmp_error": "",
                   "jmx_disable_until": "0",
                   "jmx_available": "0",
                   "jmx_errors_from": "0",
                   "jmx_error": "",
                   "name": "Windows",
                   "flags": "0",
                   "templateid": "10081",
                   "description": "",
                   "tls_connect": "1",
                   "tls_accept": "1",
                   "tls_issuer": "",
                   "tls_subject": "",
                   "tls_psk_identity": "",
                   "tls_psk": "",
                   "uuid": "522d17e1834049be879287b7c0518e5d"
               }
           ],
           "id": 1
       }Retrieve template groups that the template "Linux by Zabbix agent" is a member of.
{
           "jsonrpc": "2.0",
           "method": "template.get",
           "params": {
               "output": ["hostid"],
               "selectTemplateGroups": "extend",
               "filter": {
                   "host": [
                       "Linux by Zabbix agent"
                   ]
               }
           },
           "id": 1
       }Response:
{
           "jsonrpc": "2.0",
           "result": [
               {
                   "templateid": "10001",
                   "templategroups": [
                       {
                           "groupid": "10",
                           "name": "Templates/Operating systems",
                           "uuid": "846977d1dfed4968bc5f8bdb363285bc"
                       }
                   ]
               }
           ],
           "id": 1
       }Retrieve hosts that have the "10001" (Linux by Zabbix agent) template linked to them.
{
           "jsonrpc": "2.0",
           "method": "template.get",
           "params": {
               "output": "templateid",
               "templateids": "10001",
               "selectHosts": ["hostid", "name"]
           },
           "id": 1
       }Response:
{
           "jsonrpc": "2.0",
           "result": [
               {
                   "templateid": "10001",
                   "hosts": [
                       {
                           "hostid": "10084",
                           "name": "Zabbix server"
                       },
                       {
                           "hostid": "10603",
                           "name": "Host 1"
                       },
                       {
                           "hostid": "10604",
                           "name": "Host 2"
                       }
                   ]
               }
           ],
           "id": 1
       }Retrieve templates that have tag "host-name" equal to "{HOST.NAME}".
{
           "jsonrpc": "2.0",
           "method": "template.get",
           "params": {
               "output": ["hostid"],
               "selectTags": "extend",
               "evaltype": 0,
               "tags": [
                   {
                       "tag": "host-name",
                       "value": "{HOST.NAME}",
                       "operator": 1
                   }
               ]
           },
           "id": 1
       }Response:
{
           "jsonrpc": "2.0",
           "result": [
               {
                   "hostid": "10402",
                   "tags": [
                       {
                           "tag": "host-name",
                           "value": "{HOST.NAME}"
                       }
                   ]
               }
           ],
           "id": 1
       }CTemplate::get() in ui/include/classes/api/services/CTemplate.php.