9

We use Gitlab 7.8, i'm trying to get full list of groups on our prod server via gitlab api, unfortunately gitlab api is returning only 20 groups out of 80 available group. Any help in this would be appreciated.

command used is curl -k --header "PRIVATE-TOKEN: token of admin users"  https://server_name/api/v3/groups

Running this as admin and adding admin account to all the groups didn't help either.

maestromani
  • 841
  • 1
  • 9
  • 31

2 Answers2

12

20 is the default number of results returned by GitLab API

You could pass the per_page=80 parameter, to get your 80 expected groups.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • 1
    Thank you very much, but i still run into the same. Now i use command used is curl -k --header "PRIVATE-TOKEN: token of admin users" --header "per_page=100" https://server_name/api/v3/groups – maestromani Apr 24 '15 at 11:18
  • 2
    @maestromani maybe because of a bug similar to https://github.com/gitlabhq/gitlabhq/issues/7492 and https://github.com/gitlabhq/gitlabhq/pull/9048/files? – VonC Apr 24 '15 at 11:35
  • Okay I think this means I have to update my gitlab installation first. Running 7.8.2 and passing 80 instead of 100 doesn´t work for me – Marian Klühspies Jun 05 '15 at 12:43
  • 2
    the thing is, `per_page` IS NOT A HEADER. It is just a query param – Nebulosar Jan 20 '22 at 13:29
  • @Nebulosar Good point. It is not a header indeed. – VonC Jan 20 '22 at 13:46
6

As well as the 'per_page=100' I would also recommend using 'page=' also, if you have more repositories than the maximum value of per_page. You can specify a maximum per_page value of 100.

Something like curl -k --header "PRIVATE-TOKEN: token of admin users" https://server_name/api/v3/groups?page=1&per_page=100

Dante
  • 548
  • 1
  • 7
  • 19
  • Hi Dante, Thanks a lot for this clarification, however I have a follow up question, how to get 2nd page users if you have more than 1 pages? because on first page only 100 results are displayed – Sunny Jul 29 '22 at 07:11
  • Hi Sunny. Sure. It's page=2&per_page=100 – Dante Jul 30 '22 at 09:05
  • Question still remains, how do u get all ur output w/out knowing the item/page count in advance. – galaxis Sep 24 '22 at 18:10
  • You have to use pagination with the GitLab API to get complete results beyond the max page size. https://docs.gitlab.com/ee/api/#pagination Also note that if you have projects organised into subgroups, the Group List Projects API has an include_subgroups option (default false) that will need to be provided if you also want to list projects contained in subgroups. https://docs.gitlab.com/ee/api/groups.html#list-a-groups-projects – Dante Oct 18 '22 at 09:42
  • You can also follow nandeesh's answer here. https://stackoverflow.com/a/59197424/4220286 – Dante Oct 18 '22 at 09:45