Skip to main content

An API request using pagination for returning ~74,000 assets results in duplicate values although the total items returned is correct.

After doing some research, the issue could be related to non-deterministic ordering on the endpoint. How does iiQ order items in the query on their API endpoint?

@NS_92501 Hello, I hope you are doing well! 

Typically when making an API call with paging and size parameters being passed through, you should be able to add the paging and sizing parameters by adding the following to the end of the API url for the API call you are trying to make. Please note that the S parameter indicates the number of items while the p value should determine what page is returned:

(URL)?$s=50&$p=0

With that said though, if you may be encountering any issues with the paging or number of item parameters, please let us know! 

Best regards,
Drew


Hi Drew,

Thank you for your response - my URL is set up as follows and it returns the correct total amount of items, however, there are usually one to two thousand duplicate assets that are returned.

  let url = 'https://SITE.incidentiq.com/api/v1.0/assets?$p=' + intPage + '&$s=5000';
intPage increases at the end of a while loop and will exit around 15 pages when there are no more assets to query.
The duplicate assets that are returned could be because of non-deterministic ordering. How is the endpoint setup - what does the API use for deterministic ordering that ensures unique results per page? Does it use one or perhaps two different database fields?
 

@NS_92501 Thank you for reaching back out with this additional information! 

Typically, if you are seeing repeat items in the results, it is typically due to missing header parameters expected in the call or a misconfigured body of the call. To help address these concerns, I went ahead and included below an example URL with additional parameters for $o. This will add sort order to the results returned by the call which will ensure a deterministic ordering is used based on Criteria. For this call, I selected AssetTag, but you could use SerialNumber instead if you wanted! ASC has also been added to the end to designate ascending order. 

(SITE).incidentiq.com/api/v1.0/assets/?$s=50&$p=1&$o=AssetTag%20ASC

In addition to the API URL changes though, you will also want to ensure that the body of the POST call is similar to the one included below. This particular Body should return all enabled assets for your district:

{"OnlyShowDeleted":false,"Filters":[{"Facet":"ParentAsset","Id":null}],"FilterByViewPermission":true}

Best Regards,

Drew


Thank you for getting back to me and for specifying that the AssetTag and SerialNumber could be used for deterministic ordering. I used a combination for the orderBy and it looks like all the results are unique. I appreciate your help!