Where do I find the project ID for the GitLab API?

Solution 1:

I just found out an even easier way to get the project id: just see the HTML content of the gitlab page hosting your project. There is an input with a field called project_id, e.g:

<input type="hidden" name="project_id" id="project_id" value="335" />

Solution 2:

On the Edit Project page there is a Project ID field in the top right corner.

(You can also see the ID on the CI/CD pipelines page, in the exameple code of the Triggers section.)

In older versions, you can see it on the Triggers page, in the URLs of the example code.

Solution 3:

The latest version of GitLab 11.4 at the time of this writing now puts the Project ID at the top of the frontpage of your repository.

Screenshot:

GitLab Project Front Page

Solution 4:

You can query for your owned projects:

curl -XGET --header "PRIVATE-TOKEN: XXXX" "https://gitlab.com/api/v3/projects/owned"

You will receive JSON with each owned project:

[
  {
    "id":48,
    "description":"",
    "default_branch":"master",
    "tag_list":[
...

You are also able to get the project ID from the triggers configuration in your project which already has some sample code with your ID.

From the Triggers page:

curl -X POST \
     -F token=TOKEN \
     -F ref=REF_NAME \
     https://<GitLab Installation>/api/v3/projects/<ProjectID>/trigger/builds