Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List project variables API doesn't show all GitLab project (repository) variables

I'm trying to list all the variables defined in my GitLab repository (project) using the following API: https://gitlab.com/api/v4/projects/[PROJECT-ID]/variables

But, I don't get all the variables. I can see more variables defined here: https://gitlab.com/[GROUP-NAME]/[PROJECT-NAME]/-/settings/ci_cd

I also checked the following API documentation but didn't find anything to figure out the reason: GitLab > Project-level CI/CD variables API > List project variables

Why is this happening? Is there any bug in GitLab?

Note: [PROJECT-ID], [GROUP-NAME] and [PROJECT-NAME] are placeholders and will be replaced with the actual values.

like image 734
Abdullah Khawer Avatar asked Sep 06 '25 00:09

Abdullah Khawer


2 Answers

I have figured it out. It seems like the list project variables API doesn't show more than 20 variables by default. I just made a wild guess to try out passing a page variable with the API call and it worked. See this: https://gitlab.com/api/v4/projects/[PROJECT-ID]/variables?page=2

On the second page, the remaining (missing) variables appeared which means that they do exist and are accessible.

You can also pass per_page variable with the API call to set how many variables to show per page. See this: https://gitlab.com/api/v4/projects/[PROJECT-ID]/variables? page=1&per_page=100

The details regarding these pagination variables page and per_page are available in the GitLab's official documentation about REST API here.

Note: [PROJECT-ID] is a placeholder and will be replaced with the actual value.

like image 98
Abdullah Khawer Avatar answered Sep 08 '25 04:09

Abdullah Khawer


Or you can set how many variables you want to be listed on the page with: https://gitlab.com/api/v4/projects/[PROJECT-ID]/variables?page=1&per_page=1000

like image 44
Cristian Corbu Avatar answered Sep 08 '25 05:09

Cristian Corbu