批量更新模板

描述

object template.massupdate(object parameters)

此方法允许同时替换或删除相关对象,并更新多个模板上的属性。

此方法仅适用于管理员和超级管理员用户类型。可以在用户角色设置中撤销调用该方法的权限。详情请阅 User roles

参数

(object) 参数包含要更新的模板ID和要替换的模板对象。

该方法接受以下参数.

参数类型描述
templates
(必须)
object/array要更新的模版。

模版必须有已定义的templateid属性。
groupsobject/array用于替换模板所属的当前主机群组的主机群组。

主机群组必须有已定义的groupid属性。
macrosobject/array用户宏替换给定模板上的当前用户宏。
templates_clearobject/array取消链接并清除给定模板的模板。

模版必须有已定义的templateid属性。
templates_linkobject/array替换当前链接的模板的模板。

模版必须有已定义的templateid属性。

返回值

(object) 返回一个对象,该对象包含templateids属性下已更新模板的ID。

示例

Unlinking a template

Unlink and clear template “10091” from the given templates.

Request:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "template.massupdate",
  4. "params": {
  5. "templates": [
  6. {
  7. "templateid": "10085"
  8. },
  9. {
  10. "templateid": "10086"
  11. }
  12. ],
  13. "templates_clear": [
  14. {
  15. "templateid": "10091"
  16. }
  17. ]
  18. },
  19. "id": 1
  20. }

Response:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "templateids": [
  5. "10085",
  6. "10086"
  7. ]
  8. },
  9. "id": 1
  10. }

替换主机群组

从给定模板中取消链接并清除模板“10091”。

请求:

  1. {
  2. "jsonrpc": "2.0",
  3. "method": "template.massupdate",
  4. "params": {
  5. "templates": [
  6. {
  7. "templateid": "10085"
  8. },
  9. {
  10. "templateid": "10086"
  11. }
  12. ],
  13. "templates_clear": [
  14. {
  15. "templateid": "10091"
  16. }
  17. ]
  18. },
  19. "auth": "038e1d7b1735c6a5436ee9eae095879e",
  20. "id": 1
  21. }

响应:

  1. {
  2. "jsonrpc": "2.0",
  3. "result": {
  4. "templateids": [
  5. "10085",
  6. "10086"
  7. ]
  8. },
  9. "id": 1
  10. }

参阅

源码

CTemplate::massUpdate() in ui/include/classes/api/services/CTemplate.php.