GitLab API returns status code 400 instead of 409 when creating project with same name

Summary

When attempting to create a new project using the API, if the name exists, a status code of 400 (Bad Request) is returned where I was expecting a 409. According to the Status Code section in the API documentation, it states that it should return a 409 when:

A conflicting resource already exists. For example, creating a project with a name that already exists.

Steps to reproduce

  • Run the following command twice. Replace <PERSONAL ACCESS TOKEN> with your access token.

    curl -i --request POST --header "Content-Type: application/json" --header "PRIVATE-TOKEN: <PERSONAL ACCESS TOKEN>" --data '{"name":"StatusTest"}' "https://gitlab.com/api/v4/projects"
  • The first time running the command will return the expected HTTP/2 201 at the top with the response body being the JSON for the created project.

  • The second command will return HTTP/2 400 at the top with the response body being:

    {"message":{"name":["has already been taken"],"path":["has already been taken"]}}

What is the current bug behavior?

Status code 400 is returned if there is a project name conflict when attempting to create a project through the API.

What is the expected correct behavior?

I expected a status code of 409 to be returned based on the documentation.

Edited by 🤖 GitLab Bot 🤖