[comment]: # ({8c618db1-8c618db1})
# template.massadd

[comment]: # ({/8c618db1-8c618db1})

[comment]: # ({644f677f-399b9834})
### 説明

`object template.massadd(object parameters)`

このメソッドを使用すると、指定したテンプレートに複数の関連オブジェクトを同時に追加できます。

::: noteclassic
このメソッドは、*Admin* および *Super admin* ユーザータイプでのみ使用できます。  
このメソッドを呼び出す権限は、ユーザーロール設定で取り消すことができます。詳細については、[ユーザーロール](/manual/web_interface/frontend_sections/users/user_roles) を参照してください。
:::

[comment]: # ({/644f677f-399b9834})

[comment]: # ({db47a0fd-4167b841})
### パラメータ

`(object)` 更新するテンプレートのIDと、テンプレートに追加するオブジェクトを含むパラメータです。

このメソッドは以下のパラメータを受け付けます。

|パラメータ|[Type](/manual/api/reference_commentary#data-types)|説明|
|--|--|------|
|templates|object/array|更新する[テンプレート](/manual/api/reference/template/object)。<br><br>テンプレートでは、`templateid`プロパティのみを定義する必要があります。<br><br>[パラメータの動作](/manual/api/reference_commentary#parameter-behavior):<br>- *必須*|
|groups|object/array|指定したテンプレートに追加する[テンプレートグループ](/manual/api/reference/templategroup/object)。<br><br>テンプレートグループでは、`groupid`プロパティのみを定義する必要があります。|
|macros|object/array|指定したテンプレート用に作成する[ユーザーマクロ](/manual/api/reference/usermacro/object)。|
|templates\_link|object/array|指定したテンプレートにリンクする[テンプレート](/manual/api/reference/template/object)。<br><br>テンプレートでは、`templateid`プロパティのみを定義する必要があります。|

[comment]: # ({/db47a0fd-4167b841})

[comment]: # ({dcba01c8-dcba01c8})
### 戻り値

`(object)` `templateids` プロパティの下で更新されたテンプレートの ID を含むオブジェクトを返します。

[comment]: # ({/dcba01c8-dcba01c8})

[comment]: # ({b41637d2-b41637d2})
### 例

[comment]: # ({/b41637d2-b41637d2})

[comment]: # ({9ee15989-f8fe44e4})
#### グループをテンプレートにリンクする

テンプレートグループ「2」を2つのテンプレートに追加します。

[リクエスト](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "template.massadd",
    "params": {
        "templates": [
            {
                "templateid": "10085"
            },
            {
                "templateid": "10086"
            }
        ],
        "groups": [
            {
                "groupid": "2"
            }
        ]
    },
    "id": 1
}
```

レスポンス:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "templateids": [
            "10085",
            "10086"
        ]
    },
    "id": 1
}
```

[comment]: # ({/9ee15989-f8fe44e4})

[comment]: # ({87e8784f-7dbed7e5})
#### 2つのテンプレートを1つのテンプレートにリンクする

テンプレート"10106"と"10104"をテンプレート"10073"にリンクします。

[リクエスト](/manual/api#performing-requests):

```json
{
    "jsonrpc": "2.0",
    "method": "template.massadd",
    "params": {
        "templates": [
            {
                "templateid": "10073"
            }
        ],
        "templates_link": [
            {
                "templateid": "10106"
            },
            {
                "templateid": "10104"
            }
        ]
    },
    "id": 1
}
```

Response:

```json
{
    "jsonrpc": "2.0",
    "result": {
        "templateids": [
            "10073"
        ]
    },
    "id": 1
}
```

[comment]: # ({/87e8784f-7dbed7e5})

[comment]: # ({73d79282-bd8dd370})
### 関連項目

-   [template.update](update)
-   [ホスト](/manual/api/reference/host/object#host)
-   [テンプレートグループ](/manual/api/reference/templategroup/object#template-group)
-   [ユーザーマクロ](/manual/api/reference/usermacro/object#hosttemplate-level-macro)

[comment]: # ({/73d79282-bd8dd370})

[comment]: # ({2f7abcb1-2f7abcb1})
### ソース

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

[comment]: # ({/2f7abcb1-2f7abcb1})
