# \[SOLVED\] How to fetch all the users through curl on apiv4 with Mattermost version 4.1.0

**URL:** <https://forum.mattermost.com/t/solved-how-to-fetch-all-the-users-through-curl-on-apiv4-with-mattermost-version-4-1-0/3728>\
**Category:** Troubleshooting\
**Created:** [August 22, 2017, 2:00pm UTC](https://forum.mattermost.com/t/solved-how-to-fetch-all-the-users-through-curl-on-apiv4-with-mattermost-version-4-1-0/3728 "2017-08-22T14:00:20Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![ankushgrover](https://avatars.discourse-cdn.com/v4/letter/a/d26b3c/32.png) [@ankushgrover](https://forum.mattermost.com/u/ankushgrover)\
**Post date:** [August 22, 2017, 2:00pm UTC](https://forum.mattermost.com/t/solved-how-to-fetch-all-the-users-through-curl-on-apiv4-with-mattermost-version-4-1-0/3728/1 "2017-08-22T14:00:20Z")

</div>

Hi,

Presently I am running MatterMost version 4.1.0 on Ubuntu 16.04. There is a script which automatically runs for disabling the users who leaves my organization. The script is working fine for the apiv3 but not for apiv4. When I try to fetch all the users through the curl command it just fetches only 60 users (by default) whereas in apiv3 I was able to fetch all the users by mentioning the same in the url [https://mattermost.example.com/api/v3/users/0/100](https://mattermost.example.com/api/v3/users/0/100). How can I achieve the same with the apiv4.

/usr/bin/curl -H “Content-Type: application/json” -H “Authorization: Bearer xxxxxx” -X GET -d ‘{“page”:“0”,“per\_page”:“100”}’ [https://mattermost.example.com/api/v4/users](https://mattermost.example.com/api/v4/users)

Thanks & Regards

Ankush Grover

---

<div class="post-metadata">

**Author:** ![prixone](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/prixone/32/1184_2.png) [@prixone](https://forum.mattermost.com/u/prixone)\
**Post date:** [August 22, 2017, 4:11pm UTC](https://forum.mattermost.com/t/solved-how-to-fetch-all-the-users-through-curl-on-apiv4-with-mattermost-version-4-1-0/3728/2 "2017-08-22T16:11:34Z")

</div>

Those are query parameters not JSON data, so it goes with the URL:

```auto
https://mattermost.example.com/api/v4/users?per_page=100

```

As a curl request it would look something like this:

```auto
/usr/bin/curl -H 'Authorization: Bearer xxxxxx' -X GET -d 'per_page=100' -G https://mattermost.example.com/api/v4/users

```

To use the `-d` you need to use `-G` alternatively you could run:

```auto
/usr/bin/curl -H 'Authorization: Bearer xxxxxx' -X GET 'https://mattermost.example.com/api/v4/users?per_page=100'

```

You can skip setting the page since the default is 0 and you want to list all users, so you want page 0 which is the default when not defined.

---

<div class="post-metadata">

**Author:** ![ankushgrover](https://avatars.discourse-cdn.com/v4/letter/a/d26b3c/32.png) [@ankushgrover](https://forum.mattermost.com/u/ankushgrover)\
**Post date:** [August 23, 2017, 7:14am UTC](https://forum.mattermost.com/t/solved-how-to-fetch-all-the-users-through-curl-on-apiv4-with-mattermost-version-4-1-0/3728/3 "2017-08-23T07:14:19Z")

</div>

Thanks Prixone for sharing an example. The below one worked for me but with certain limitation as only 200 users are returned per page.

> /usr/bin/curl -H ‘Authorization: Bearer xxxxxx’ -X GET ‘[https://mattermost.example.com/api/v4/users?per\_page=100](https://mattermost.example.com/api/v4/users?per_page=100)’

I need another help for deactivating a user, I am trying the below curl command but somehow it is not doing the job and saying “active” parameter is missing in the request body whereas I have supplied the “active” parameter.

> /usr/bin/curl -H “Content-Type: application/json” -H “Authorization: Bearer $tokenid” -X PUT -d ‘{“active”: “false”}’ ‘[https://mattermost.example.com/api/v4/users/wrjff9bcdid1jd8whm7xs8bgao/active](https://mattermost.example.com/api/v4/users/wrjff9bcdid1jd8whm7xs8bgao/active)’

where wrjff9bcdid1jd8whm7xs8bgao is a user\_id of an user.

> {id":“api.context.invalid\_body\_param.app\_error”,“message”:“Invalid or missing active in request body”,“detailed\_error”:“”,“request\_id”:“ms15nct1gf8p8bt1kdnfrzweae”,“status\_code”:400}

Thanks & Regards

Ankush Grover

---

<div class="post-metadata">

**Author:** ![prixone](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/prixone/32/1184_2.png) [@prixone](https://forum.mattermost.com/u/prixone)\
**Post date:** [August 23, 2017, 10:41am UTC](https://forum.mattermost.com/t/solved-how-to-fetch-all-the-users-through-curl-on-apiv4-with-mattermost-version-4-1-0/3728/4 "2017-08-23T10:41:28Z")

</div>

Sorry, you’re saying you tried per\_page=200 or above and the maximum it ever gave you was 200 no matter how big u changed it to?

Your quotes look odd, at least on my console environment those fail me, maybe that is breaking it?

```auto
‘{“active”: “false”}’

```

versus:

```auto
'{"active": false}'

```

---

<div class="post-metadata">

**Author:** ![ankushgrover](https://avatars.discourse-cdn.com/v4/letter/a/d26b3c/32.png) [@ankushgrover](https://forum.mattermost.com/u/ankushgrover)\
**Post date:** [August 23, 2017, 11:13am UTC](https://forum.mattermost.com/t/solved-how-to-fetch-all-the-users-through-curl-on-apiv4-with-mattermost-version-4-1-0/3728/5 "2017-08-23T11:13:07Z")

</div>

Thanks a lot prixone. Yes its working with -d ‘{“active”: false}’

Related to per\_page=200 it always return 200 even I used per\_page=1000. So I have use page=$i,per\_page=200 with a loop replacing $i with number starting from 0 till 5(I have around 1000 users) to retrieve all my users.

---

<div class="post-metadata">

**Author:** ![prixone](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/prixone/32/1184_2.png) [@prixone](https://forum.mattermost.com/u/prixone)\
**Post date:** [August 23, 2017, 3:48pm UTC](https://forum.mattermost.com/t/solved-how-to-fetch-all-the-users-through-curl-on-apiv4-with-mattermost-version-4-1-0/3728/6 "2017-08-23T15:48:08Z")

</div>

Well I don’t see any limitations on the code for the use of page and per\_page, they are translated directly as limit and offset to the database, so it should give you the 1000 if u do per\_page=1000

Maybe curl is not reading the whole response or its splitting? Have you checked if the resulting json is valid? from per\_page=1000?

~~Or perhaps its just a bug.~~

---

<div class="post-metadata">

**Author:** ![ankushgrover](https://avatars.discourse-cdn.com/v4/letter/a/d26b3c/32.png) [@ankushgrover](https://forum.mattermost.com/u/ankushgrover)\
**Post date:** [August 23, 2017, 4:23pm UTC](https://forum.mattermost.com/t/solved-how-to-fetch-all-the-users-through-curl-on-apiv4-with-mattermost-version-4-1-0/3728/7 "2017-08-23T16:23:50Z")

</div>

Well I tried on 2 different Ubuntu Systems 14.04 and 16.04 64-bits and the result was same that the curl returned 200 users even though I mentioned ?per\_page=1000. Curl is 7.35 version on Ubuntu 14.04 and 7.47 version on Ubuntu 16.04. Do let me know you need any further information.

Curl returned when I used ?per\_page=1000

> grep -o ‘“id”:’ details.txt | wc -l  
> 200

Curl returned all the users when I mention ?page=1,per\_page=200 till page=4,per\_page=200

> grep -o ‘“id”:’ details.txt | wc -l  
> 859

Thanks & Regards  
Ankush Grover

---

<div class="post-metadata">

**Author:** ![prixone](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/prixone/32/1184_2.png) [@prixone](https://forum.mattermost.com/u/prixone)\
**Post date:** [August 24, 2017, 1:54am UTC](https://forum.mattermost.com/t/solved-how-to-fetch-all-the-users-through-curl-on-apiv4-with-mattermost-version-4-1-0/3728/8 "2017-08-24T01:54:38Z")

</div>

Sorry about that, apparently I missed a small piece of code which is what limits it, thanks @saturnino for pointing that out.

> <https://github.com/mattermost/mattermost-server/blob/master/api4/params.go>

So yes, its not a bug and you would have to page(like you are already doing), if you have more than 200 users as the maximum per\_page is 200.

---

<div class="post-metadata">

**Author:** ![ankushgrover](https://avatars.discourse-cdn.com/v4/letter/a/d26b3c/32.png) [@ankushgrover](https://forum.mattermost.com/u/ankushgrover)\
**Post date:** [August 24, 2017, 2:02am UTC](https://forum.mattermost.com/t/solved-how-to-fetch-all-the-users-through-curl-on-apiv4-with-mattermost-version-4-1-0/3728/9 "2017-08-24T02:02:53Z")

</div>

Thanks prixone for the update. Thats fine with me if there are limits in fetching the users.

Thanks once again for your help.

Thanks & Regards

Ankush Grover

---

<div class="post-metadata">

**Author:** ![prixone](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/prixone/32/1184_2.png) [@prixone](https://forum.mattermost.com/u/prixone)\
**Post date:** [August 24, 2017, 2:04am UTC](https://forum.mattermost.com/t/solved-how-to-fetch-all-the-users-through-curl-on-apiv4-with-mattermost-version-4-1-0/3728/10 "2017-08-24T02:04:21Z")

</div>

No problem, glad it solved you issue 😉

---

<div class="post-metadata">

**Author:** ![aholt](https://avatars.discourse-cdn.com/v4/letter/a/58f4c7/32.png) [@aholt](https://forum.mattermost.com/u/aholt)\
**Post date:** [October 23, 2018, 8:06pm UTC](https://forum.mattermost.com/t/solved-how-to-fetch-all-the-users-through-curl-on-apiv4-with-mattermost-version-4-1-0/3728/11 "2018-10-23T20:06:22Z")

</div>

Is it possible to increase the PER\_PAGE\_MAXIMUM?

---

<div class="post-metadata">

**Author:** ![amy.blais](https://sea2.discourse-cdn.com/flex020/user_avatar/forum.mattermost.com/amy.blais/32/7481_2.png) [@amy.blais](https://forum.mattermost.com/u/amy.blais)\
**Post date:** [October 23, 2018, 11:36pm UTC](https://forum.mattermost.com/t/solved-how-to-fetch-all-the-users-through-curl-on-apiv4-with-mattermost-version-4-1-0/3728/12 "2018-10-23T23:36:33Z")

</div>

Hi @aholt, you can make multiple requests until you get all the channel members you need

e.g. `/api/v4/channels/{channel_id}/members?page=0&per_page=200` , `/api/v4/channels/{channel_id}/members?page=1&per_page=200` , and so on until you receive less than 200 results, meaning you’ve hit the end.
