Use this API to retrieve the merge trains of a project. These endpoints require the Developer, Maintainer, or Owner role, and support offset-based pagination.
Each object in a response represents one merge request in a train, not an entire train. Requesting merge trains without a target branch can return entries from more than one train in the project.
Responses do not include an explicit queue position, and return merge requests as a flat list rather than grouped by train:
- For an exact queue position, sort by
idin ascending order, or use the GraphQL APIMergeTrainCar.indexfield. - To group merge requests by train, use the
target_branchattribute, or query the GraphQL APIProject.mergeTrainsandMergeTrain.carsfields.
Read every merge train of a project
GET /api/v4/projects/{id}/merge_trains
Returns the cars of all the trains of the project at once. Cars of different target branches are mixed together, so read one train instead when the queue of a single branch is what matters.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- Example: 11 |
scopeQuery | String | Limit the response to cars still queued (active) or to cars that have left the queue (complete)Allowed values: active,completeExample: active |
sortQuery | String | Order the cars by their position, Allowed values: asc,descDefault: desc |
pageQuery | Integer | Current page number Default: 1Example: 1 |
per_Query | Integer | Number of items per page Default: 20Example: 20 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
401 | Unauthorized | — |
403 | Forbidden | — |
404 | Not found | — |
Read the place of a merge request in its merge train
GET /api/v4/projects/{id}/merge_trains/merge_requests/{merge_request_iid}
Returns the car that represents the merge request in the train of its target branch.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- Example: 11 |
merge_Path, | Integer | IID of the merge request Example: 1 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
401 | Unauthorized | — |
403 | Forbidden | — |
404 | Not found | — |
Queue a merge request on a merge train
POST /api/v4/projects/{id}/merge_trains/merge_requests/{merge_request_iid}
Puts the merge request at the back of the train of its target branch, or has it join the queue once its merge checks pass.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- Example: 11 |
merge_Path, | Integer | IID of the merge request Example: 1 |
Request body (application/json)
| Property | Type | Description |
|---|---|---|
auto_ | Boolean | Queue the merge request instead of merging it right away |
sha | String | Head of the source branch as the caller last saw it. |
squash | Boolean | Squash the commits of the source branch into one when the merge request merges |
Responses
| Code | Description | Schema |
|---|---|---|
201 | Created | APIEntities |
202 | Accepted | APIEntities |
400 | Cannot be queued | — |
401 | Unauthorized | — |
403 | Forbidden | — |
404 | Not found | — |
409 | Conflict | — |
Read the merge train of a target branch
GET /api/v4/projects/{id}/merge_trains/{target_branch}
Returns the cars queued for one target branch, in queue order.
Parameters
| Name | Type | Description |
|---|---|---|
idPath, | String or integer | The ID or URL- Example: 11 |
target_Path, | String | Target branch whose train to read Example: main |
scopeQuery | String | Limit the response to cars still queued (active) or to cars that have left the queue (complete)Allowed values: active,completeExample: active |
sortQuery | String | Order the cars by their position, Allowed values: asc,descDefault: desc |
pageQuery | Integer | Current page number Default: 1Example: 1 |
per_Query | Integer | Number of items per page Default: 20Example: 20 |
Responses
| Code | Description | Schema |
|---|---|---|
200 | OK | APIEntities |
400 | Bad Request | — |
401 | Unauthorized | — |
403 | Forbidden | — |
404 | Not found | — |
Schemas
Objects returned by the operations above and objects nested in their request bodies.
APIEntitiesCiPipelineBasic
| Property | Type | Description |
|---|---|---|
created_ | String (date- | Example:2022- |
id | Integer (int64) | Example:1 |
iid | Integer | Example:2 |
project_ | Integer (int64) | Example:3 |
ref | String | Example:feature- |
sha | String | Example:0ec9e58fdfca6cdd6652 |
source | String | Example:push |
status | String | Example:success |
updated_ | String (date- | Example:2022- |
web_ | String | Example:https: |
APIEntitiesCustomAttribute
| Property | Type | Description |
|---|---|---|
key | String | Example:foo |
value | String | Example:bar |
APIEntitiesMergeRequestSimple
| Property | Type | Description |
|---|---|---|
created_ | String (date- | Example:2022- |
description | String | Example:Repellendus impedit et vel velit dignissimos. |
id | Integer (int64) | Example:84 |
iid | Integer | Example:14 |
project_ | Integer (int64) | Example:4 |
state | String | Example:closed |
title | String | Example:Test MR 1580978354 |
updated_ | String (date- | Example:2022- |
web_ | String | Example:http: |
APIEntitiesMergeTrainsCar
| Property | Type | Description |
|---|---|---|
created_ | String (date- | Example:2026- |
duration | Integer | Seconds between queueing and merging Example: 480 |
id | Integer | Example:7 |
merge_ | APIEntities | — |
merged_ | String (date- | Example:2026- |
pipeline | APIEntities | — |
status | String | Where the car stands in its queue Allowed values: idle,merged,stale,fresh,merging,skip_Example: merged |
target_ | String | Example:main |
updated_ | String (date- | Example:2026- |
user | APIEntities | — |
APIEntitiesUserBasic
| Property | Type | Description |
|---|---|---|
avatar_ | String | Example:/ |
avatar_ | String | Example:https: |
custom_ | Array of APIEntities | — |
id | Integer (int64) | Example:1 |
locked | Boolean | — |
name | String | Example:Administrator |
public_ | String | Example:john@example. |
state | String | Example:active |
username | String | Example:admin |
web_ | String | Example:https: |