debian-mirror-gitlab/doc/api/system_hooks.md

128 lines
2.8 KiB
Markdown
Raw Normal View History

2017-09-10 17:25:29 +05:30
# System hooks API
2014-09-02 18:07:02 +05:30
2016-04-02 18:10:28 +05:30
All methods require administrator authorization.
2014-09-02 18:07:02 +05:30
2016-04-02 18:10:28 +05:30
The URL endpoint of the system hooks can also be configured using the UI in
2020-03-13 15:44:24 +05:30
the **Admin Area > System Hooks** (`/admin/hooks`).
2016-04-02 18:10:28 +05:30
Read more about [system hooks](../system_hooks/system_hooks.md).
2014-09-02 18:07:02 +05:30
## List system hooks
2016-04-02 18:10:28 +05:30
Get a list of all system hooks.
2020-04-08 14:13:33 +05:30
```plaintext
2014-09-02 18:07:02 +05:30
GET /hooks
```
2016-04-02 18:10:28 +05:30
Example request:
2020-03-13 15:44:24 +05:30
```shell
2020-06-23 00:09:42 +05:30
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/hooks"
2016-04-02 18:10:28 +05:30
```
2014-09-02 18:07:02 +05:30
2016-04-02 18:10:28 +05:30
Example response:
2014-09-02 18:07:02 +05:30
```json
[
2017-08-17 22:00:37 +05:30
{
"id":1,
"url":"https://gitlab.example.com/hook",
"created_at":"2016-10-31T12:32:15.192Z",
"push_events":true,
"tag_push_events":false,
2018-03-17 18:26:18 +05:30
"merge_requests_events": true,
2018-11-20 20:47:30 +05:30
"repository_update_events": true,
2017-08-17 22:00:37 +05:30
"enable_ssl_verification":true
}
2014-09-02 18:07:02 +05:30
]
```
2016-04-02 18:10:28 +05:30
## Add new system hook
Add a new system hook.
2020-04-08 14:13:33 +05:30
```plaintext
2014-09-02 18:07:02 +05:30
POST /hooks
```
2016-04-02 18:10:28 +05:30
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `url` | string | yes | The hook URL |
2017-08-17 22:00:37 +05:30
| `token` | string | no | Secret token to validate received payloads; this will not be returned in the response |
| `push_events` | boolean | no | When true, the hook will fire on push events |
| `tag_push_events` | boolean | no | When true, the hook will fire on new tags being pushed |
2018-03-17 18:26:18 +05:30
| `merge_requests_events` | boolean | no | Trigger hook on merge requests events |
2018-11-20 20:47:30 +05:30
| `repository_update_events` | boolean | no | Trigger hook on repository update events |
2017-08-17 22:00:37 +05:30
| `enable_ssl_verification` | boolean | no | Do SSL verification when triggering the hook |
2016-04-02 18:10:28 +05:30
Example request:
2020-03-13 15:44:24 +05:30
```shell
2019-02-15 15:39:39 +05:30
curl --request POST --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/hooks?url=https://gitlab.example.com/hook"
2016-04-02 18:10:28 +05:30
```
Example response:
2014-09-02 18:07:02 +05:30
2016-04-02 18:10:28 +05:30
```json
[
2017-08-17 22:00:37 +05:30
{
"id":1,
"url":"https://gitlab.example.com/hook",
"created_at":"2016-10-31T12:32:15.192Z",
"push_events":true,
"tag_push_events":false,
2018-03-17 18:26:18 +05:30
"merge_requests_events": true,
2018-11-20 20:47:30 +05:30
"repository_update_events": true,
2017-08-17 22:00:37 +05:30
"enable_ssl_verification":true
}
2016-04-02 18:10:28 +05:30
]
```
2014-09-02 18:07:02 +05:30
## Test system hook
2020-04-08 14:13:33 +05:30
```plaintext
2014-09-02 18:07:02 +05:30
GET /hooks/:id
```
2016-04-02 18:10:28 +05:30
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer | yes | The ID of the hook |
2014-09-02 18:07:02 +05:30
2016-04-02 18:10:28 +05:30
Example request:
2020-03-13 15:44:24 +05:30
```shell
2020-06-23 00:09:42 +05:30
curl --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/hooks/2"
2016-04-02 18:10:28 +05:30
```
Example response:
2014-09-02 18:07:02 +05:30
```json
{
2016-04-02 18:10:28 +05:30
"project_id" : 1,
"owner_email" : "example@gitlabhq.com",
"owner_name" : "Someone",
"name" : "Ruby",
"path" : "ruby",
"event_name" : "project_create"
2014-09-02 18:07:02 +05:30
}
```
## Delete system hook
2017-08-17 22:00:37 +05:30
Deletes a system hook.
2016-04-02 18:10:28 +05:30
2020-04-08 14:13:33 +05:30
```plaintext
2014-09-02 18:07:02 +05:30
DELETE /hooks/:id
```
2016-04-02 18:10:28 +05:30
| Attribute | Type | Required | Description |
| --------- | ---- | -------- | ----------- |
| `id` | integer | yes | The ID of the hook |
Example request:
2014-09-02 18:07:02 +05:30
2020-03-13 15:44:24 +05:30
```shell
2020-06-23 00:09:42 +05:30
curl --request DELETE --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/hooks/2"
2019-09-30 21:07:59 +05:30
```