M
M
Michael2018-03-22 15:22:29
CRM
Michael, 2018-03-22 15:22:29

What to do if there is pagination in the JSON response??

Hello! I am using retail crm api https://github.com/retailcrm/api-client-dotnet library for .Net, there is a method

Retailcrm.Versions.V4.Client api = new Retailcrm.Versions.V4.Client(product.SiteName, product.AccessToken);
                Dictionary<string, object> filteredOrders = new Dictionary<string, object>
               {
                { "extendedStatus", "complete" },
                { "statusUpdatedAtFrom", DateTime.Now.AddDays(-3).ToString("yyyy-MM-dd HH:mm:ss")},
                { "statusUpdatedAtTo", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}
               };

                Response responseFiltered = api.OrdersList(filteredOrders, 1, 100);

api.OrdersList
has 3 parameters, this is a filter, the second parameter is the current page with the received users and 3 parameter, the displayed number of users per 1 page. Now I have a hardcode - since the second parameter is 1, I get users from only 1 page. How to make it so that you get users from all pages? I deserialize the users into a model and it has this:
public class Pagination
    {
        public int limit { get; set; }
        public int totalCount { get; set; }
        public int currentPage { get; set; }
        public int totalPageCount { get; set; }
    }

When I deserialize json , users are written to my db. How can I implement pagination in this case? Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Dmitry Kovalsky, 2018-03-22
@M-Misha-M

And what's the problem? well, call the API method with a loop or asynchronous tasks until you get all the pages. Remove hardcode. Or do you want to write the code directly to you? Then it's a complaint for a job

F
freeExec, 2018-03-22
@freeExec

do {
    responseFiltered = api.OrdersList(filteredOrders, page++, 100);
} while (responseFiltered.Count > 0);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question