Get all inventorys via API  Topic is solved

Discussions relating to plugin development, and the Jiwa API.

Get all inventorys via API

Postby minhhieu106 » Mon Apr 23, 2018 7:56 pm

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
minhhieu106
Occasional Contributor
Occasional Contributor
 
Posts: 49
Joined: Thu Mar 29, 2018 3:29 pm
Topics Solved: 0

Re: Get all inventorys via API  Topic is solved

Postby Mike.Sheen » Tue Apr 24, 2018 4:42 pm

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
Mike Sheen
Chief Software Engineer
Jiwa Financials

If I do answer your question to your satisfaction, please mark it as the post solving the topic so others with the same issue can readily identify the solution
User avatar
Mike.Sheen
Overflow Error
Overflow Error
 
Posts: 2444
Joined: Tue Feb 12, 2008 11:12 am
Location: Perth, Republic of Western Australia
Topics Solved: 756


Return to Technical and or Programming

Who is online

Users browsing this forum: No registered users and 21 guests