0

We need to load invoices whose lines are tagged with a specific tracking category.

Right now the way to do this is to load ALL invoices, which gets invoice header info, then load invoice Lines, which finally gets tracking info, then filter out the ones I need.

This seems very inefficient. Is there a better way to do this? I do not want to load all invoices, then load them one by one just to find the few which are using the specific tracking category.

Daniel Williams
  • 8,912
  • 15
  • 68
  • 107

1 Answers1

0

Use paging to get the invoices with the lines included, it should mean fewer calls will be required to the API.

Here is a snippet from one of my projects that uses paging for invoices. c# version

        var api = XeroApiHelper.CoreApi();

        api.SummarizeErrors(false);

        var invoices = new List<Invoice>();
        var invoicep = new List<Invoice>();

        int i = 1;
        do
        {
            invoicep = api.Invoices.Where("Contact.ContactID == Guid(\"" + xeroId + "\")").Page(i).Find().ToList();
            invoices.AddRange(invoicep);
            i++;
        } while (invoicep.Any());
sheavens
  • 685
  • 7
  • 14