Chris F
Chris F

Reputation: 16673

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?

Upvotes: 9

Views: 16067

Answers (2)

Bertrand Martel
Bertrand Martel

Reputation: 45352

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

Upvotes: 7

John McGehee
John McGehee

Reputation: 10299

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 

Upvotes: 14

Related Questions