Skip to main content

I know that it is possible to set the number of rows returned when querying Assyst data with the REST API, but I don’t know nor can I find an example in documentation on how to limit number of rows returned to “x” number of rows.

asking for ALL open service request events, is more than 500 rows.  I would like to limit the number of rows so my query does not error out and will run.

any help is greatly appreciated and “Thanks” in advance

Hello, ​@VT_VKOLB 

 

I’m sorry if I’ve misunderstood your question, but to me it sounds like what you are looking for is pagination, this allows you to return a given number of records that meet the rest of your REST query.

There is a short section introducing this concept on the Wiki, with the following example:

GET http://<server>:<port>/assystREST/v2/events?$top=10

I haven’t found an example of further refined use of pagination on the wiki, so the following is based on my own understanding, testing, and experience using the rest api, and if there are any inaccuracies I’m more than happy to receive any corrections.

 

You can combine $top this with other query parameters to shape the initial pool of resources you are selecting from.

GET http://<server>:<port>/assystREST/v2/items/?acquiredDate=2023-01-01T00:00:00Z,2024-06-T00:00:00Z&$top=20

Without $top=20 the example above would return all non discontinued items with an acquiredDate inside the range of dates specified which would return more than 2000 results in my case, however adding the top limit this to 20 records. The “base” of this top is item id, in ascending order, as this is the default ordering in the API. 

This ordering might be useful in some scenarios, but if a different “base” or ordering is desired then the available $orderby options for any given resource can be found using the RAML: 

GET http://<server>:<port>/assystREST/v2/items/raml/1.0/?showDetail=true

At he bottom of the RAML at the start of the query parameters all the valid options for $orderby is listed under is:dorderable: …. ].

  • In Assyst 24R2 for instance /items/raml will inform that id, shortCode, name, product.id, product.shortCode, product.name, keyA, keyB, and serialNumber can be used in an $orderby

The list of what can be used in an orderby is different for each Assyst resource, for example Events has a much larger list of orderable properties available. 

Building on the example from above the list of items returned could be changed to use the product name as a baseline for what is included in the $top:

GET http://<server>:<port>/assystREST/v2/items/?acquiredDate=2023-01-01T00:00:00Z,2024-06-T00:00:00Z&$top=20&$orderby=product.name:desc
  • As an example this query returns 20 items under a Zbook product in our CMDB.

Changing this desc to an asc would likely return a whole different set of items in the response:

GET http://<server>:<port>/assystREST/v2/items/?acquiredDate=2023-01-01T00:00:00Z,2024-06-T00:00:00Z&$top=20&$orderby=product.name:asc
  • As an example this query returns 20 items inder an access controll product in our CMDB. 

When a page size is set using $top=x the following “pages” can be retrieved using $skip=x. Whenever you use a $top the response from the API contains the link to the next page is of the result in a  X-assyst-nextLink header, The nextLink header does not contain the entire url, just the endpoint, the initial query parameters, and an additional $skip=x parameter mirroring the $top=x value to indicate how much to skip ahead to get a new page.

Following the previous example the following next link would be included as a header in the response:

X-assyst-nextLink: items/?acquiredDate=2023-01-01T00:00:00Z,2024-06-T00:00:00Z&$top=20&$orderby=product.name:asc&$skip=20

 

$skip can also be used manually to retrieve a specific “page,” so you can, of course, set your own skip value. However, to avoid unintended gaps in the pages or inadvertently retrieving the same resource in consecutive responses, the $skip value should be a multiple of the $top value.

($skip can also be used outside of pagination. For example, when querying for Assyst users and you want to retrieve all assystUsers except the SA user with ID 1, you can do so with /assystREST/v2/assystUsers/?skip=1.)

 

Does this help with what you were looking for?


If not, can you elaborate further on what you are trying to achieve and what errors you get in your attempts?

 


Thanks so much!  I knew there was something documented that I had seen before on it, but for the life of me I couldn’t find it again.


Reply