Page 1 of 1

Get all inventorys via API

PostPosted: Mon Apr 23, 2018 7:56 pm
by minhhieu106
Hi Mike,

I use API http://localhost/JiwaAPI/Queries/IN_Main to get inventory data. How can i get all inventory?

E.g. I have 350 records in Jiwa. By settings, API only returns 100 records, how can i get next records until last record?

Thanks,
Hieu

Re: Get all inventorys via API  Topic is solved

PostPosted: Tue Apr 24, 2018 4:42 pm
by Mike.Sheen
minhhieu106 wrote:E.g. I have 350 records in Jiwa. By settings, API only returns 100 records, how can i get next records until last record?


Hi minhhieu106,

You have 2 options - either change the default limit from 100 to a desired value via the REST APIP Tab of the System Configuration form in Jiwa (not recommended):
RESTAPI_Configuration.PNG


Or (recommended) you can use Skip to read in the "next" n records - like a paging technique. Add Skip = 100 to the query DTO and you'll get records 100 to 200. Make sure you also provide an OrderBy field to get consistent results. If you also add Include = Total the response will provide how many record there are available.

Code: Select all
https://api.jiwa.com.au/Queries/IN_Main?OrderBy=PartNo&Take=100&Include=Total&format=json


This will return something like:
Code: Select all
{"Total":272,"Results":[{"InventoryID":"69accccb872e42419ad0","...


Note the Total field at the beginning - that tells me I have 272 total records available. I can count how many that first call returned (the Count of Results) - and using that you can then loop through until you get to the end, setting the Take and Skip DTO fields:

Code: Select all
// Get records 101 to 200
https://api.jiwa.com.au/Queries/IN_Main?OrderBy=PartNo&Skip=100&Take=100&format=json



Code: Select all
// Get records 201 to 300
https://api.jiwa.com.au/Queries/IN_Main?OrderBy=PartNo&Skip=200&Take=100&format=json


Mike