Suggest Changes API
- Tier: Free, Premium, Ultimate
- Offering: GitLab.com, GitLab Self-Managed, GitLab Dedicated
This page describes the API for suggesting changes.
Every API call to suggestions must be authenticated.
Create a suggestion
To create a suggestion through the API, use the Discussions API to create a new thread in the merge request diff. The format for suggestions is:
```suggestion:-3+0
example text
```
Apply a suggestion
Applies a suggested patch in a merge request. Users must have at least the Developer role to perform such action.
PUT /suggestions/:id/apply
Attribute | Type | Required | Description |
---|---|---|---|
id | integer | yes | The ID of a suggestion |
commit_message | string | no | A custom commit message to use instead of the default generated message or the project’s default message |
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" "https://gitlab.example.com/api/v4/suggestions/5/apply"
Example response:
{
"id": 5,
"from_line": 10,
"to_line": 10,
"applicable": true,
"applied": false,
"from_content": "This is an example\n",
"to_content": "This is an example\n"
}
Apply multiple suggestions
PUT /suggestions/batch_apply
Attribute | Type | Required | Description |
---|---|---|---|
ids | integer | yes | The IDs of suggestions |
commit_message | string | no | A custom commit message to use instead of the default generated message or the project’s default message |
curl --request PUT --header "PRIVATE-TOKEN: <your_access_token>" --header 'Content-Type: application/json' --data '{"ids": [5, 6]}' "https://gitlab.example.com/api/v4/suggestions/batch_apply"
Example response:
[
{
"id": 5,
"from_line": 10,
"to_line": 10,
"applicable": true,
"applied": false,
"from_content": "This is an example\n",
"to_content": "This is an example\n"
}
{
"id": 6,
"from_line": 19
"to_line": 19,
"applicable": true,
"applied": false,
"from_content": "This is another example\n",
"to_content": "This is another example\n"
}
]
Docs
Edit this page to fix an error or add an improvement in a merge request.
Create an issue to suggest an improvement to this page.
Product
Create an issue if there's something you don't like about this feature.
Propose functionality by submitting a feature request.
Feature availability and product trials
View pricing to see all GitLab tiers and features, or to upgrade.
Try GitLab for free with access to all features for 30 days.
Get help
If you didn't find what you were looking for, search the docs.
If you want help with something specific and could use community support, post on the GitLab forum.
For problems setting up or using this feature (depending on your GitLab subscription).
Request support