barrycarey / SnipeSharp

A c# wrapper for the Snipe IT API
25 stars 30 forks source link

Actually GetAll when there are fewer than 1000 entries and FindAll when a limit is not provided #9

Open cofl opened 5 years ago

cofl commented 5 years ago

Discovered while testing against the asset list on a local SnipeIT install.

In EndPointManager.GetAll, when there are fewer than 1000 assets in the system, only 50 assets (the default limit) would be included in the ResponseCollection, though the Total would still show the correct number.

In EndPointManager.FindAll, when a limit is not provided, again at most only 50 assets would be included in the ResponseCollection, even when the results should have more, such as when retrieving all assets of a certain manufacturer.

Replication steps

I did my testing in PowerShell.

  1. Have a SnipeIT instance with more than 50 but fewer than 1000 assets, where approximately 160 of those assets have a manufacturer.
  2. PowerShell log attached (paths removed):
PS C:\> $api = [SnipeSharp.SnipeItApi]::new(); $api.ApiSettings.ApiToken = $token; $api.ApiSettings.BaseUrl = $url
PS C:\> $api.AssetManager.GetAll() | select Total, @{Name='Actual';Expression={$_.Rows.Count}}

Total Actual
----- ------
  602     50

PS C:\> $filter = [SnipeSharp.Endpoints.SearchFilters.AssetSearchFilter]::new()
PS C:\> $filter.Manufacturer = $api.ManufacturerManager.Get("Lenovo")
PS C:\> $api.ManufacturerManager.Get("Lenovo").AssetsCount
167
PS C:\> $api.AssetManager.FindAll($filter) | select Total, @{Name='Actual';Expression={$_.Rows.Count}}

Total Actual
----- ------
  167     50
cofl commented 5 years ago

This addresses #5.