Updated on 2026-01-27 GMT+08:00

Adding a Deploy Key

Function

This API is used to add a deployment key.

URI

POST /v2/repositories/{repository_id}/deploy-keys

Table 1 Path parameter

Parameter

Mandatory

Type

Description

repository_id

Yes

Integer

Explanation:

Repository ID.

Constraints:

N/A

Range:

1–2147483647

Default value:

N/A

Request Parameters

Table 2 Request header parameter

Parameter

Mandatory

Type

Description

X-Auth-Token

Yes

String

Explanation:

User token. It can be obtained by calling the corresponding Obtaining a User Token. The value of X-Subject-Token in the response header is the user token.

Constraints:

N/A

Range:

1–100,000 characters.

Default value

N/A

Table 3 Request body parameters

Parameter

Mandatory

Type

Description

application

Yes

String

Explanation:

Source of the SSH key for deployment.

Constraints:

N/A

Range:

N/A

Default value

N/A

can_push

Yes

Boolean

Explanation:

Whether the SSH key for deployment can push code.

Constraints:

N/A

Range:

false: Code cannot be pushed.

Default value

N/A

key

Yes

String

Explanation:

SSH key for deployment.

Constraints:

N/A

Range:

N/A

Default value

N/A

key_title

Yes

String

Explanation:

Name of the SSH key for deployment.

Constraints:

N/A

Range:

1–255

Default value

N/A

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

error

Error object

Explanation:

Response error code.

Range:

N/A

result

Key object

Explanation:

Response result.

Range:

N/A

status

String

Explanation:

Response status.

Range:

  • success: The API call is successful.
  • failed: The API call failed.
Table 5 Error

Parameter

Type

Description

code

String

Explanation:

Error code.

Range:

Max. 100 characters in the error code format.

message

String

Explanation:

Error message.

Range:

N/A

Table 6 Key

Parameter

Type

Description

can_push

Boolean

Explanation:

Whether to allow push.

Range:

  • true: Push is allowed.
  • false: Push is not allowed.

created_at

String

Explanation:

Creation time of the deploy key.

Range:

None

key

String

Explanation:

Deploy key.

Range:

None

key_id

String

Explanation:

Deploy key ID.

Range:

1-40

key_title

String

Explanation:

Deploy key name.

Range:

None

Example Requests

POST https://{endpoint}/v2/repositories/{repository_id}/deploy-keys

{
  "key_title" : "repo@example.com",
  "key" : "ssh-rsa AAAAB3NzaC1yc2EA*********************************************************U7xcma6HU8nj1E0i46VObWyOONl3gh142BV repo@example.com",
  "can_push" : true,
  "application" : ""
}

Example Responses

Status code: 200

OK

{
  "result" : {
    "key_id" : "1034546",
    "key_title" : "repo@example.com",
    "key" : "ssh-rsa AAAAB3NzaC1yc2EA*********************************************************U7xcma6HU8nj1E0i46VObWyOONl3gh142BV repo@example.com"
  },
  "status" : "success"
}

Status Code

Status Code

Description

200

OK

Error Codes

See Error Codes.