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" />
Answer from codependent on Stack OverflowWhere do I find the project ID for the GitLab API? - Stack Overflow
How to get the project details using Gitlab API
How to get a list of all your Gitlab personal projects via API?
How to get GitLab project name by using Project id in GitLab API - Stack Overflow
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" />
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:

Hi all,
I want to add a list of the titles and dates of all my Gitlab personal projects to my website via API.
There is some documentation on how to get the first few of the the projects on Gitlab but I could not figure out a way to get all of only mine.
Is there any way to do that?
Thanks.
According to the Projects API, no. It will return all projects that contain your search string, but you should be able to filter the results once you retrieve it.
The available options are sort and order_by. You can order by the fields id, name, created_at, and last_activity_at
One may use jq to filter the returned results from a fuzzy search:
project_name="test"
curl --silent --show-error --location \
"https://gitlab.com/api/v4/search?scope=projects&search=${project_name}" \
--header "PRIVATE-TOKEN: ${GITLAB_COM_API_PRIVATE_TOKEN}" | jq \
--raw-output --arg project_name "${project_name}" '.[] | \
select(.name == $project_name)'
Of course, this returns 12 projects. Which one is mine?
It is far better if you can include a namespace.
project_path_with_namespace="$username/test"
curl --silent --show-error --location \
"https://gitlab.com/api/v4/search?scope=projects&search=${project_path_with_namespace}" \
--header "PRIVATE-TOKEN: ${GITLAB_COM_API_PRIVATE_TOKEN}" | jq \
--arg path_with_namespace "${project_path_with_namespace}" '.[] | \
select(.path_with_namespace == $path_with_namespace)'
Now the search is not fuzzy and will always return a precise result so long as such a project exists at that path.
There is an attribute called "attributes". Try the following:
for project in gl.projects.list():
# print everything
print(project.attributes)
# or a single attribute
print(project.attributes['name'])
The same for groups:
for group in gl.groups.list():
# print everything
print(group.attributes)
# or a single attribute
print(group.attributes['name'])
Use pagination if you have more than 20 projects in the group
gl = gitlab.Gitlab('https://gitlab.com', private_token='Token')
group = gl.groups.get(group_id, lazy=True)
project_lst=group.projects.list(as_list=False) #pagination
for item in project_lst:
project_id = gl.projects.get(item.attributes['id'])
......................................
......................................
If only your private token is available, you can only use the API:
PROJECTS
Use the following command to request projects:
curl "https://<host>/api/v4/projects?private_token=<your private token>"
This will return you the first 20 entries. To get more you can add the paramater per_page
curl "https://<host>/api/v4/projects?private_token=<your private token>&per_page=100"
with this parameter you can request between 20and 100 entries (see REST API Pagination documentation).
If you now want all projects, you have to loop through the pages. To get to another page add the parameter page.
curl "https://<host>/api/v4/projects?private_token=<your private token>&per_page=100&page=<page_number>"
Now you may want to know how many pages there are. For that, add the curl parameter --head. This will not return the payload, but the header.
The result should look like this:
HTTP/1.1 200 OK
Server: nginx
Date: Thu, 13 Jul 2017 17:43:24 GMT
Content-Type: application/json
Content-Length: 29428
Cache-Control: no-cache
Link: <request link>
Vary: Origin
X-Frame-Options: SAMEORIGIN
X-Next-Page: 2
X-Page: 1
X-Per-Page: 20
X-Prev-Page:
X-Request-Id: 80ecc167-4f3f-4c99-b09d-261e240e7fe9
X-Runtime: 4.117558
X-Total: 312257
X-Total-Pages: 15613
Strict-Transport-Security: max-age=31536000
The two interesting parts here are X-Totaland X-Total-Pages. The first is the count of available entries and the second the count of total pages.
I suggest to use python or some other kind of script to handle the requests and concat the results at the end.
If you want to refine the search, consult this wiki page: https://docs.gitlab.com/api/projects.html#projects-api
GROUPS
For groups simply replace projects with groups in the curls.
https://docs.gitlab.com/api/groups.html#list-groups
UPDATE:
Here is the official list of Gitlab API clients/wrappers: https://docs.gitlab.com/api/rest/third_party_clients/
I highly recommend using one of these.
In bash for Gitlab API V4:
#!/bin/bash
GL_DOMAIN=""
GL_TOKEN=""
echo "" > gitlab_projects_urls.txt
for ((i=1; ; i+=1)); do
contents=$(curl "$GL_DOMAIN/api/v4/projects?private_token=$GL_TOKEN&per_page=100&page=$i")
if jq -e '. | length == 0' >/dev/null; then
break
fi <<< "$contents"
echo "$contents" | jq -r '.[].ssh_url_to_repo' >> gitlab_projects_urls.txt
done