This topic describes how to update credentials by using an API. When you update credentials, the system performs SSH verification and stores the password in an encrypted format.
API call description
If you set a password, you must pass the authentication. For more information, see API hybrid encryption.
Request path
PATCH /api/v1/security/credential/:id
Request parameters
Parameter |
Type |
Required |
Example value |
Description |
|---|---|---|---|---|
| id | int | Yes | 1 | The ID of the credential. This parameter is specified in the path. |
| name | string | Yes | updated-credential | The name of the credential. |
| description | string | No | Updated description | The description of the credential. |
| ssh_credential_property | SshCredentialProperty | Yes | - | The properties of the SSH credential. For more information, see the Data structure of SshCredentialProperty section below. |
Data structure of SshCredentialProperty:
Parameter |
Type |
Required |
Example value |
Description |
|---|---|---|---|---|
| targets | []Target | Yes | [{"ip": "10.10.10.1", "port": 22}] | The list of target hosts. Each Target contains the ip and port. If the port is not specified, the default port is 22. The list cannot be empty and must contain at least one target. |
| username | string | Yes | root | The username for the SSH connection. |
| type | string | Yes | PASSWORD | The authentication type. Only "PASSWORD" is supported. |
| passphrase | string | Yes | *********** | The password for the SSH connection in plaintext (which is encrypted before being stored). This parameter can be empty. |
Response
Parameter |
Type |
Description |
|---|---|---|
| successful | bool | Indicates whether the request was successful. |
| timestamp | time.Time | The timestamp when the server completed the request. |
| duration | int | The time taken by the server to process the request, in milliseconds. |
| status | int | The HTTP status code. |
| traceId | string | The trace ID of the request. |
| data | Credential | The returned credential information. For more information, see the Data structure of Credential section below. |
| error | ApiError | The error returned by the request, which contains the following information:
|
Data structure of Credential:
Parameter |
Type |
Description |
|---|---|---|
| credential_id | int64 | The ID of the credential. |
| name | string | The name of the credential. |
| target_type | string | The type of the target. |
| description | string | The description of the credential. |
| ssh_secret | SshSecret | The SSH key information (excluding the password). For more information, see the Data structure of SshSecret section below. |
| create_time | time.Time | The time when the credential was created. |
| update_time | time.Time | The time when the credential was last updated. |
Data structure of SshSecret:
Parameter |
Type |
Description |
|---|---|---|
| targets | []Target | The list of target hosts. |
| username | string | The username. |
| type | string | The authentication type. |
Examples
Request example
PATCH 10.10.10.1:2886/api/v1/security/credential/1
{
"name": "updated-credential",
"description": "Updated description",
"ssh_credential_property": {
"targets": [
{
"ip": "10.10.10.1",
"port": 22
}
],
"username": "root",
"type": "PASSWORD",
"passphrase": "**************"
}
}
Response example
{
"successful": true,
"timestamp": "2025-10-14T15:15:01.277047628+08:00",
"duration": 28,
"status": 200,
"traceId": "e6f64ba7f54e7a49",
"data": {
"credential_id": 1,
"name": "updated-credential",
"target_type": "HOST",
"description": "Updated description",
"ssh_secret": {
"targets": [
{
"ip": "10.10.10.1",
"port": 22
}
],
"username": "root",
"type": "PASSWORD"
},
"create_time": "2025-10-14T15:14:01.277047628+08:00",
"update_time": "2025-10-14T15:15:01.277047628+08:00"
}
}
