1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340
|
---
stage: Security Risk Management
group: Security Policies
info: "To determine the technical writer assigned to the Stage/Group associated with this page, see https://handbook.gitlab.com/handbook/product/ux/technical-writing/#assignments"
---
# External Status Checks API
DETAILS:
**Tier:** Ultimate
**Offering:** GitLab.com, Self-managed, GitLab Dedicated
## Get project external status check services
You can request information about a project's external status check services using the following endpoint:
```plaintext
GET /projects/:id/external_status_checks
```
**Parameters:**
| Attribute | Type | Required | Description |
|---------------------|---------|----------|---------------------|
| `id` | integer | yes | ID of a project |
```json
[
{
"id": 1,
"name": "Compliance Tool",
"project_id": 6,
"external_url": "https://gitlab.com/example/compliance-tool",
"hmac": true,
"protected_branches": [
{
"id": 14,
"project_id": 6,
"name": "main",
"created_at": "2020-10-12T14:04:50.787Z",
"updated_at": "2020-10-12T14:04:50.787Z",
"code_owner_approval_required": false
}
]
}
]
```
## Create external status check service
You can create a new external status check service for a project using the following endpoint:
```plaintext
POST /projects/:id/external_status_checks
```
WARNING:
External status checks send information about all applicable merge requests to the
defined external service. This includes confidential merge requests.
| Attribute | Type | Required | Description |
|------------------------|------------------|----------|------------------------------------------------|
| `id` | integer | yes | ID of a project |
| `name` | string | yes | Display name of external status check service |
| `external_url` | string | yes | URL of external status check service |
| `shared_secret` | string | no | HMAC secret for external status check |
| `protected_branch_ids` | `array<Integer>` | no | IDs of protected branches to scope the rule by |
## Update external status check service
You can update an existing external status check for a project using the following endpoint:
```plaintext
PUT /projects/:id/external_status_checks/:check_id
```
| Attribute | Type | Required | Description |
|------------------------|------------------|----------|------------------------------------------------|
| `id` | integer | yes | ID of a project |
| `check_id` | integer | yes | ID of an external status check service |
| `name` | string | no | Display name of external status check service |
| `external_url` | string | no | URL of external status check service |
| `shared_secret` | string | no | HMAC secret for external status check |
| `protected_branch_ids` | `array<Integer>` | no | IDs of protected branches to scope the rule by |
## Delete external status check service
You can delete an external status check service for a project using the following endpoint:
```plaintext
DELETE /projects/:id/external_status_checks/:check_id
```
| Attribute | Type | Required | Description |
|------------------------|----------------|----------|----------------------------------------|
| `check_id` | integer | yes | ID of an external status check service |
| `id` | integer | yes | ID of a project |
## List status checks for a merge request
For a single merge request, list the external status check services that apply to it and their status.
```plaintext
GET /projects/:id/merge_requests/:merge_request_iid/status_checks
```
**Parameters:**
| Attribute | Type | Required | Description |
| ------------------------ | ------- | -------- | -------------------------- |
| `id` | integer | yes | ID of a project |
| `merge_request_iid` | integer | yes | IID of a merge request |
```json
[
{
"id": 2,
"name": "Service 1",
"external_url": "https://gitlab.com/test-endpoint",
"status": "passed"
},
{
"id": 1,
"name": "Service 2",
"external_url": "https://gitlab.com/test-endpoint-2",
"status": "pending"
}
]
```
## Set status of an external status check
> - Support for `failed` and `passed` [enabled by default](https://gitlab.com/gitlab-org/gitlab/-/issues/353836) in GitLab 15.0
> - Support for `pending` in GitLab 16.5 [enabled by default](https://gitlab.com/gitlab-org/gitlab/-/issues/413723) in GitLab 16.5
For a single merge request, use the API to inform GitLab that a merge request has passed a check by an external service.
To set the status of an external check, the personal access token used must belong to a user with at least the Developer role on the target project of the merge request.
Execute this API call as any user with rights to approve the merge request itself.
```plaintext
POST /projects/:id/merge_requests/:merge_request_iid/status_check_responses
```
**Parameters:**
| Attribute | Type | Required | Description |
| -------------------------- | ------- | -------- |---------------------------------------------------------------------------------------------------|
| `id` | integer | yes | ID of a project |
| `merge_request_iid` | integer | yes | IID of a merge request |
| `sha` | string | yes | SHA at `HEAD` of the source branch |
| `external_status_check_id` | integer | yes | ID of an external status check |
| `status` | string | no | Set to `pending` to mark the check as pending, `passed` to pass the check, or `failed` to fail it |
NOTE:
`sha` must be the SHA at the `HEAD` of the merge request's source branch.
## Retry failed status check for a merge request
> - [Introduced](https://gitlab.com/gitlab-org/gitlab/-/issues/383200) in GitLab 15.7.
For a single merge request, retry the specified failed external status check. Even
though the merge request hasn't changed, this endpoint resends the current state of
merge request to the defined external service.
```plaintext
POST /projects/:id/merge_requests/:merge_request_iid/status_checks/:external_status_check_id/retry
```
**Parameters:**
| Attribute | Type | Required | Description |
| -------------------------- | ------- | -------- | ------------------------------------- |
| `id` | integer | yes | ID of a project |
| `merge_request_iid` | integer | yes | IID of a merge request |
| `external_status_check_id` | integer | yes | ID of a failed external status check |
## Response
In case of success status code is 202.
```json
{
"message": "202 Accepted"
}
```
In case status check is already passed status code is 422
```json
{
"message": "External status check must be failed"
}
```
## Example payload sent to external service
```json
{
"object_kind": "merge_request",
"event_type": "merge_request",
"user": {
"id": 1,
"name": "Administrator",
"username": "root",
"avatar_url": "https://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80&d=identicon",
"email": "[REDACTED]"
},
"project": {
"id": 6,
"name": "Flight",
"description": "Ipsa minima est consequuntur quisquam.",
"web_url": "http://example.com/flightjs/Flight",
"avatar_url": null,
"git_ssh_url": "ssh://example.com/flightjs/Flight.git",
"git_http_url": "http://example.com/flightjs/Flight.git",
"namespace": "Flightjs",
"visibility_level": 20,
"path_with_namespace": "flightjs/Flight",
"default_branch": "main",
"ci_config_path": null,
"homepage": "http://example.com/flightjs/Flight",
"url": "ssh://example.com/flightjs/Flight.git",
"ssh_url": "ssh://example.com/flightjs/Flight.git",
"http_url": "http://example.com/flightjs/Flight.git"
},
"object_attributes": {
"assignee_id": null,
"author_id": 1,
"created_at": "2022-12-07 07:53:43 UTC",
"description": "",
"head_pipeline_id": 558,
"id": 144,
"iid": 4,
"last_edited_at": null,
"last_edited_by_id": null,
"merge_commit_sha": null,
"merge_error": null,
"merge_params": {
"force_remove_source_branch": "1"
},
"merge_status": "can_be_merged",
"merge_user_id": null,
"merge_when_pipeline_succeeds": false,
"milestone_id": null,
"source_branch": "root-main-patch-30152",
"source_project_id": 6,
"state_id": 1,
"target_branch": "main",
"target_project_id": 6,
"time_estimate": 0,
"title": "Update README.md",
"updated_at": "2022-12-07 07:53:43 UTC",
"updated_by_id": null,
"url": "http://example.com/flightjs/Flight/-/merge_requests/4",
"source": {
"id": 6,
"name": "Flight",
"description": "Ipsa minima est consequuntur quisquam.",
"web_url": "http://example.com/flightjs/Flight",
"avatar_url": null,
"git_ssh_url": "ssh://example.com/flightjs/Flight.git",
"git_http_url": "http://example.com/flightjs/Flight.git",
"namespace": "Flightjs",
"visibility_level": 20,
"path_with_namespace": "flightjs/Flight",
"default_branch": "main",
"ci_config_path": null,
"homepage": "http://example.com/flightjs/Flight",
"url": "ssh://example.com/flightjs/Flight.git",
"ssh_url": "ssh://example.com/flightjs/Flight.git",
"http_url": "http://example.com/flightjs/Flight.git"
},
"target": {
"id": 6,
"name": "Flight",
"description": "Ipsa minima est consequuntur quisquam.",
"web_url": "http://example.com/flightjs/Flight",
"avatar_url": null,
"git_ssh_url": "ssh://example.com/flightjs/Flight.git",
"git_http_url": "http://example.com/flightjs/Flight.git",
"namespace": "Flightjs",
"visibility_level": 20,
"path_with_namespace": "flightjs/Flight",
"default_branch": "main",
"ci_config_path": null,
"homepage": "http://example.com/flightjs/Flight",
"url": "ssh://example.com/flightjs/Flight.git",
"ssh_url": "ssh://example.com/flightjs/Flight.git",
"http_url": "http://example.com/flightjs/Flight.git"
},
"last_commit": {
"id": "141be9714669a4c1ccaa013c6a7f3e462ff2a40f",
"message": "Update README.md",
"title": "Update README.md",
"timestamp": "2022-12-07T07:52:11+00:00",
"url": "http://example.com/flightjs/Flight/-/commit/141be9714669a4c1ccaa013c6a7f3e462ff2a40f",
"author": {
"name": "Administrator",
"email": "admin@example.com"
}
},
"work_in_progress": false,
"total_time_spent": 0,
"time_change": 0,
"human_total_time_spent": null,
"human_time_change": null,
"human_time_estimate": null,
"assignee_ids": [
],
"reviewer_ids": [
],
"labels": [
],
"state": "opened",
"blocking_discussions_resolved": true,
"first_contribution": false,
"detailed_merge_status": "mergeable"
},
"labels": [
],
"changes": {
},
"repository": {
"name": "Flight",
"url": "ssh://example.com/flightjs/Flight.git",
"description": "Ipsa minima est consequuntur quisquam.",
"homepage": "http://example.com/flightjs/Flight"
},
"external_approval_rule": {
"id": 1,
"name": "QA",
"external_url": "https://example.com/"
}
}
```
## Related topics
- [External status checks](../user/project/merge_requests/status_checks.md)
|