gitlabgitlab-api

Gitlab API adding members to a project


I'm experiencing errors when trying to add users to a Gitlab project using the Gitlab API. I'm using Gitlab version 8.11.0 on CentOS 6.8 and I'm not sure if it is a bug or something I am doing wrong. The following works fine and gives me a list of project members:

curl --header "PRIVATE-TOKEN: top_secret" "https://example.com/api/v3/projects/1/members"

but when trying to add a members with the following, I get an error message:

curl --request POST --header "PRIVATE-TOKEN: top_secret" "https://example.com/api/v3/projects/1/members/myusername?access_level=30"

{"error":"405 Not Allowed"}

Using the web interface I am able to add the user to the project.


Solution

  • It looks like the Gitlab API documentation was incorrect.

    As it's a create action, you should send both the user ID and access levels as named parameters (like you would for creating any other resource).

    So something like:

    https://example.com/api/v3/projects/1/members/?user_id=299&access_level=40