I have a dashboard to do for my organization about the use of smartsheet licenses by employees. Normally, the request to obtain such information is as follows (according to the documentation):
https://api.smartsheet.com/2.0/users?include=lastLogin
However, this request displays exactly 100 results per page. All I want is to have all the results.
The documentation indicates that another parameter must be added to the request to obtain the full list of results. The request becomes:
https://api.smartsheet.com/2.0/users?include=lastLogin&includeAll=true
It works, however I only get the entire list of users without their last login, which brings me back to my question: How to get the list of all users including their last login ?
So, according to the docs for the List Users operation, specifying the
include=lastLoginquery string parameter will only include thelastLoginattribute for eachUserobject in the response when the number of results returned in the response is 100 or fewer. (FWIW, I'd suspect that Smartsheet implemented this behavior because it'd be detrimental to API performance if a single API request tried to fetch thelastLoginvalue for hundreds or thousands of users.)Good news though -- you can still get the info you want -- it's just going to take a little extra effort (and code) on your part. You'll need to submit a separate API request for each page of results (i.e., include both the
include=lastLoginquery string paramater and also thepagequery string parameter to specify the page number of results you want to retrieve with each request), and then join the results from all responses into a single list that you write to your dashboard. The value of thetotalPagesattribute in the initialList Usersresponse will tell you how many total pages (of 100 users each by default, which is the maximum number of users you can request at a time if you want thelastLoginattribute included for eachUserobject) are available -- i.e., how many requests you will need to issue in order to get all users and thelastLoginattribute for each.For example, your first request would be:
GET https://api.smartsheet.com/2.0/users?include=lastLogin...and let's assume that the response looks like this:
This response will contain the first 100 users -- but the response tells you it's only the first page of three available pages of results (i.e., the value of the
totalPagesattribute in the response is3) -- so you'll need to issue two more requests in order to have retrieved the full set of users.So, next you issue a second request, this time including the
pageparameter to specify that you want page 2:GET https://api.smartsheet.com/2.0/users?include=lastLogin&page=2...and the response returns the second page of results that looks like this:
This response will contain the next 100 users -- i.e., the second page of three available pages -- you'll need to issue one more request in order to have retrieved the full set of users.
So finally, you issue a third request, this time including the
pageparameter to specify that you want page 3:GET https://api.smartsheet.com/2.0/users?include=lastLogin&page=3...and the response contains the third (and in this example, final) page of results that looks something like this (where the value of the
totalCountproperty is a numeric value >= 1 and <= 100 that indicates the number of users in the response):Now, because the value of the
pageNumberproperty in the response is equal to the value of thetotalPagesproperty in the response, you know this is the final set of users and you don't need to issue any more requests.Between the 3 requests, you've now retrieved the full set of users (and the
lastLoginattribute value for each).