Get list of all users in Zammad using Rest API

Infos:

  • Used Zammad version:
  • Used Zammad installation type: (source, package, docker-compose, …)
  • Operating system:
  • Browser + version:

Expected behavior:

When I run curl --insecure -u “username”:“password” https://zammad.mydomain.net/api/v1/users in the command prompt, I expect to get the data for every user in the Zammad system.

Actual behavior:

I am only getting the first 500 users in the Zammad system when I know I have more than that in there.

Steps to reproduce the behavior:

Install curl on windows command prompt.
run curl --insecure -u “username”:“password” https://zammad.mydomain.net/api/v1/users
parse the output into a csv file.

I am sure this is a bug and no feature request or general question.

Hi @rtebbnc

The response is paginated. See

https://docs.zammad.org/en/latest/api/intro.html#pagination

Regards
Gijs

1 Like

Is there a way to get all of them to appear in the same response?

I tried https://zammad.mydomain.net/api/v1/users?expand=true&page=1&per_page=5000, and I still only got 500 in the response. I am expecting roughly 1000.

Hio @rtebbnc

The limit per call can be defined but there will always be a max. number. I am not sure what the max number at this specific route is, but I guess 500.

The rest api is usually not used for manual use. You normally build some kind of application that calls this route untill the last call gets a response.

So you will have to call
https://zammad.mydomain.net/api/v1/users?expand=true&page=1&per_page=500
https://zammad.mydomain.net/api/v1/users?expand=true&page=2&per_page=500
https://zammad.mydomain.net/api/v1/users?expand=true&page=3&per_page=500
etc.

Since Zammad doesn’t provided any information of the total number of results nor the number of pages or if the requested page is the last page, you will have to request the next page untill you receive an empty response.

Basically, you keep asking for a next page and when you get an empty response, you know you’re done. The pagination should stop after an empty response or empty data in the body.

Greetings,
Gijs

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.