[comment]: # translation:outdated

[comment]: # ({cd4a930c-cd4a930c})

# service.update

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

[comment]: # ({53331219-79afe9b7})
### 描述

`object service.update(object/array services)`

此方法允许更新已有的服务。

::: noteclassic
此方法允许任何用户使用。可以在用户角色设置中撤销调用此方法的权限。更多信息请查看 [用户角色](/manual/web_interface/frontend_sections/administration/user_roles)。
:::

[comment]: # ({/53331219-79afe9b7})

[comment]: # ({new-5fb5ebb3})
### Parameters 参数

`(object/array)` service properties to be updated.
`(object/array)`需要更新的服务属性。 The `serviceid` property must be
defined for each service, all other properties are optional. Only the
passed properties will be updated, all others will remain unchanged.
必须为每个服务定义`serviceid`属性，所有其他属性为可选项。只有通过的属性会被更新，所有其他属性将保持不变。
Additionally to the [standard service properties](object#service), the
method accepts the following parameters. 除[standard service
properties](object#service)之外，该方法接受以下参数。

|Parameter 参数   T|pe 类型       Des|ription 说明|
|--------------------|-------------------|--------------|
|dependencies|array 数组      S|rvice dependencies to replace the current service dependencies. 用来替换当前内容的服务依赖关系。<br><br>Each service dependency has the following parameters: 每个服务依赖项具有以下参数：<br>- `dependsOnServiceid` - *(string 字符串)* ID of an service the service depends on, that is, the child service. 依赖服务的服务，即子服务的ID。<br>- `soft` - *(integer 整数型)* type of service dependency; 服务依赖类型；refer to the [service dependency object page](object#service_dependency) for more information on dependency types. 有关依赖关系类型的更多信息，请参阅[service dependency object page](object#service_dependency)。|
|parentid|string 字符串   ID|of a hard-linked parent service. 硬链接的父服务ID。|
|times|array 数组      S|rvice times to replace the current service times. 用来替换当前内容的服务时间。|

[comment]: # ({/new-5fb5ebb3})

[comment]: # ({9465ee4d-9465ee4d})

### 返回值

`(对象)` 返回一个`serviceids`属性包含了被更新服务ID的对象。

[comment]: # ({/9465ee4d-9465ee4d})

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

### 示例

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

[comment]: # ({a0145a3c-b9918036})
#### 设置服务的父服务

使ID为“3”的服务成为ID为“5”的服务的父服务。 

请求：

```json
{
    "jsonrpc": "2.0",
    "method": "service.update",
    "params": {
        "serviceid": "5",
        "parents": [
            {
                "serviceid": "3"
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

响应：

```json
{
    "jsonrpc": "2.0",
    "result": {
        "serviceids": [
            "5"
        ]
    },
    "id": 1
}
```

[comment]: # ({/a0145a3c-b9918036})

[comment]: # ({3b848788-263b1baa})
#### 增加关机计划

给ID为“4”的服务增加每周一22:00到周二10:00的关机计划。

请求：

```json
{
    "jsonrpc": "2.0",
    "method": "service.update",
    "params": {
        "serviceid": "4",
        "times": [
            {
                "type": "1",
                "ts_from": "165600",
                "ts_to": "201600"
            }
        ]
    },
    "auth": "038e1d7b1735c6a5436ee9eae095879e",
    "id": 1
}
```

响应：

```json
{
    "jsonrpc": "2.0",
    "result": {
        "serviceids": [
            "4"
        ]
    },
    "id": 1
}
```

[comment]: # ({/3b848788-263b1baa})

[comment]: # ({fd1b6894-fd1b6894})

### 来源

CService::update() 在*ui/include/classes/api/services/CService.php*。

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