Multiline comments API does not work as expected despite following documentation

Hello GitLab team,

I am trying to use the GitLab API to add multiline comments on a Merge Request. However, despite strictly following the documentation, I keep getting a 400 Bad Request error with the message:

{
    "message": "400 Bad request - Note {:line_code=>[\"can't be blank\", \"must be a valid line code\"], :position=>[\"is incomplete\"]}"
}

Here is the request payload I am sending:

{
    "body": "My Body Response",
    "position": {
        "base_sha": "0e64199ce6772820040b39d224a2d1b4c9b276c7",
        "start_sha": "0e64199ce6772820040b39d224a2d1b4c9b276c7",
        "head_sha": "97b74fb799ea5fe63c7c5b58d70328c28f7c0d06",
        "new_path": "index.html",
        "old_path": "index.html",
        "line_range": {
            "start": {
                "line_code": "f6013a00b362253c64368d6eebc50ea2131754e2_21_21",
                "type": "new"
            },
            "end": {
                "line_code": "f6013a00b362253c64368d6eebc50ea2131754e2_24_24",
                "type": "new"
            }
        },
        "position_type": "text"
    }
}

Steps to reproduce:

  • Get base_sha, start_sha, and head_sha from the Merge Request.
  • Generate line_code using the format .
  • Ensure both start and end refer to valid modified lines within the same file.
  • Make a POST request to /api/v4/projects/{PROJECT_ID}/merge_requests/{MR_ID}/discussions.
  • Observe the error response.

Could you please confirm if this is a bug or if there is something wrong with my request? Any guidance or clarification would be greatly appreciated! 🙏

Thanks in advance for your help! 🚀

Edited by 🤖 GitLab Bot 🤖