Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using gitlab api, how do I get a list of active users?

Gitlab-CE v8.14.3

I'm reading the GitLAB API docs, and am trying to get the list of active users. I'm an admin and created a personal token. I do this

$ curl -XGET "Private-Token: kfjakjfkjkd" https://company.domain.com/api/v3/users?active=true

and keep getting 401 (Unauthorized) error. Like I said, I'm an admin. What gives?

like image 506
Chris F Avatar asked Jan 23 '18 22:01

Chris F


2 Answers

You must specify the header using the -H option as noted in Bertrand Martel's answer. That will retrieve up to 20 users.

Above 20 users, you must get fancier. The JSON output is paginated, and each query is limited to 100 users per page. So to get 300 users, you must get three pages, 100 users at a time:

curl -H "Private-Token: kfjakjfkjkd" "https://company.domain.com/api/v4/users?active=true&per_page=100&page=1" > gitlabusers1.json
curl -H "Private-Token: kfjakjfkjkd" "https://company.domain.com/api/v4/users?active=true&per_page=100&page=2" > gitlabusers2.json 
curl -H "Private-Token: kfjakjfkjkd" "https://company.domain.com/api/v4/users?active=true&per_page=100&page=3" > gitlabusers3.json 
like image 79
John McGehee Avatar answered Nov 08 '22 10:11

John McGehee


You need to specify that Private-Token: kfjakjfkjkd is an HTTP header with -H :

curl -H "Private-Token: kfjakjfkjkd" https://company.domain.com/api/v4/users?active=true
like image 43
Bertrand Martel Avatar answered Nov 08 '22 10:11

Bertrand Martel