Adding a Webhook in a Repository
Function
This API is used to add a Webhook in a repository.
Debugging
You can debug this API through automatic authentication in API Explorer or use the SDK sample code generated by API Explorer.
Authorization Information
Each account root user has all the permissions required to call all APIs, but IAM users must be assigned the following required identity policy-based permissions. For details about the required permissions, see Permissions Policies and Supported Actions.
| Action | Access Level | Resource Type (*: required) | Condition Key | Alias | Dependencies |
|---|---|---|---|---|---|
| codeartsrepo:group:setGroup | Write | - | - | - | - |
URI
POST https://{hostURL}/v4/groups/{group_id}/hooks
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| group_id | Yes | Integer | Definition Repository group ID, which is the numeric ID next to Group ID on the repository group homepage. Default Value N/A Value range: 1~2147483647 |
Request Parameters
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| X-Auth-Token | Yes | String | Definition User token. You can obtain the token by calling the IAM API used to obtain a user token. The value of X-Subject-Token in the response header is the user token. Constraints N/A Range A string that can contain 1 to 100,000 characters. Default Value N/A |
| Parameter | Mandatory | Type | Description |
|---|---|---|---|
| url | Yes | String | Definition Webhook URL. Range A maximum of 500 characters. |
| push_events | No | Boolean | Definition Whether to enable the push event. Constraints At least one of the following parameters must be transferred as true: push_events, tag_push_events, merge_requests_events, and note_events |
| push_events_branch_regex_filter | No | String | Definition Regular expression for push event branches filtering. Range A maximum of 500 characters. Constraints push_events_branch_regex_filter is associated with push_events. When push_events is set to true, the value of push_events_branch_regex_filter must be a regular expression. |
| note_plain_text_filter | No | Array of strings | Definition Filtering rules of event comment text. Range 0 to 50 characters for each string. Max. 10 strings. Constraints note_plain_text_filter is associated with note_events. When note_events is set to true, the value of note_plain_text_filter must be a regular expression. |
| tag_push_events | No | Boolean | Definition Whether to enable the tag push event. Constraints At least one of the following parameters must be transferred as true: push_events, tag_push_events, merge_requests_events, and note_events |
| merge_requests_events | No | Boolean | Definition Whether to enable the merge request event. Constraints At least one of the following parameters must be transferred as true: push_events, tag_push_events, merge_requests_events, and note_events |
| note_events | No | Boolean | Definition Whether to enable the comment event. Constraints At least one of the following parameters must be transferred as true: push_events, tag_push_events, merge_requests_events, and note_events |
| token | No | String | Definition Token value. When it is used as the return value, the mask is used to replace the actual value. Range A maximum of 2,000 characters. |
| token_type | No | String | Definition Token type. The default value is X-Repo-Token. Range A maximum of 200 characters. |
| name | Yes | String | Definition Name. Range A maximum of 200 characters. |
| description | No | String | Definition Description. Range A maximum of 200 characters. |
Response Parameters
Status code: 201
| Parameter | Type | Description |
|---|---|---|
| url | String | Definition Webhook URL. Range Mandatory. Max. 500 characters. |
| push_events | Boolean | Definition Whether to enable the push event. |
| push_events_branch_regex_filter | String | Definition Regular expression for push event branches filtering. Range Mandatory. Max. 500 characters. |
| note_plain_text_filter | Array of strings | Definition Filtering rules of event comment text. Range 0–50 characters for each string. Max. 10 strings. |
| tag_push_events | Boolean | Definition Whether to enable the tag push event. |
| merge_requests_events | Boolean | Definition Whether to enable the MR event. |
| note_events | Boolean | Definition Whether to enable the comment event. |
| token | String | Definition Token value. When it is used as the return value, the mask is used to replace the actual value. Range Mandatory. Max. 2,000 characters. |
| token_type | String | Definition Token type. The default value is X-Repo-Token. Range Mandatory. Max. 200 characters. |
| name | String | Definition Name. Range Mandatory. Max. 200 characters. |
| description | String | Definition Description. Range Mandatory. Max. 200 characters. |
| event_cfgs | Array of WebHookEventCfgDto objects | Definition Reserved field for setting event triggering. This parameter can be left empty. |
| project_cfgs | Array of WebHookBranchCfgDto objects | Definition Reserved field for setting repository branch rules. This parameter can be left empty. |
| branch_cfgs | Array of WebHookBranchCfgDto objects | Definition Reserved field for setting repository branch rule. This parameter can be left empty. Constraints Reserved field, only valid for repository settings. |
| id | Integer | Definition Webhook ID. Value range: 1~2147483647 |
| created_at | String | Definition Creation time. Definition yyyy-MM-dd'T'HH:mm:ss.SSSXXX |
| updated_at | String | Definition Update time. Definition yyyy-MM-dd'T'HH:mm:ss.SSSXXX |
| service | String | Definition Internal service name. |
| Parameter | Type | Description |
|---|---|---|
| event_type | String | Definition Event type. Range 1 to 255 bytes. |
| cfgs | String | Definition Configuration information. Range 1 to 255 bytes. |
| Parameter | Type | Description |
|---|---|---|
| branch_type | Integer | Definition Branch type. Range Default value: 0 Enumeration values: |
| branch | String | Definition Branch name configuration. Range 1 to 255 bytes. |
| project_type | Integer | Definition Repository name type. Range Default value: 0 Enumeration values: |
| project | String | Definition Repository name configuration. Range 1 to 255 bytes. |
Status code: 401
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Definition Error code. |
| error_msg | String | Definition Error message. |
Status code: 403
| Parameter | Type | Description |
|---|---|---|
| error_code | String | Definition Error code. |
| error_msg | String | Definition Error message. |
Example Requests
POST https://{endpoint}/v4/groups/1/hooks
{
"url" : "https://demo1.com",
"push_events" : true,
"push_events_branch_regex_filter" : ".*",
"tag_push_events" : true,
"merge_requests_events" : false,
"note_events" : false,
"token" : "exampletoken",
"token_type" : "X-Repo-Token",
"name" : "Code check.",
"description" : "Code check."
} Example Responses
Status code: 201
OK
{
"id" : 2,
"event_cfgs" : [ {
"event_type" : "cr-comment-added",
"cfgs" : {
"compare_type" : null,
"pattern" : ""
}
} ],
"project_cfgs" : [ {
"project_type" : 0,
"project" : "",
"branch_type" : null,
"branch" : ""
} ],
"url" : "https://demo1.com",
"push_events" : true,
"push_events_branch_regex_filter" : ".*",
"tag_push_events" : true,
"merge_requests_events" : false,
"note_events" : false,
"token" : "************",
"token_type" : "X-Repo-Token",
"name" : "Code check.",
"description" : "Code check.",
"created_at" : "2024-10-15T22:30:24.000+08:00",
"updated_at" : "2024-10-15T22:30:24.000+08:00"
} Status code: 401
Unauthorized
{
"error_code" : "DEV.00000003",
"error_msg" : "Authentication information expired."
} Status code: 403
Bad Request
{
"error_code" : "CH.004403",
"error_msg" : "Insufficient permissions. Apply for the required permissions and try again."
} Status Codes
| Status Code | Description |
|---|---|
| 201 | OK |
| 401 | Unauthorized |
| 403 | Bad Request |
Error Codes
See Error Codes.
Feedback
Was this page helpful?
Provide feedbackThank you very much for your feedback. We will continue working to improve the documentation.See the reply and handling status in My Cloud VOC.
For any further questions, feel free to contact us through the chatbot.
Chatbot