This was actually an interesting problem to solve. Atlassian don’t seem to want anyone returning all of the users in an Jira instance through the API. There’s supposedly a method for doing this, but it doesn’t work if you’re running the script through a Connect app like ScriptRunner. This is another method that only works with an external script, as was the case with managing Cloud Confluence Space permissions.
Instead what we do is run an empty query through the user search. However, this presents its own set of challenges, as the body is only returned in a raw format. That is, instead of returning JSON, the HTTP request is returned as a byte stream.
So after running the query, we turn it into text and then use the JSON Slurper to turn it into a JSON object with which we can work.
Despite the strangeness of the raw response, pagination, startAt, and maxResults still work, and are necessary to get all of the results. Additionally, there is no flag in the HTTP response that pertains to the last page of results, such as “lastPage”. Therefor we must determine the final page of results ourselves.
The script starts by asserting