-2

we are looking to pull those Contacts in Xero which have paid their first ever Invoice within a defined timeframe.

Is there any simple solution to achieving this with the Xero API?

Thanks

1 Answers1

0

Making some assumptions about what you're after - this is achieveable with a couple of requests:

Retrieve all contacts for the organisation:

GET https://api.xero.com/api.xro/2.0/Contacts

For each contact, retrieve all invoices:

GET https://api.xero.com/api.xro/2.0/Invoices?ContactIDs={ContactID}&where=Type%3d%3d%22ACCREC%22

Get the first invoice for each contact:

var firstInvoicesForContacts = invoices.GroupBy(i => i.Contact.ContactID, (key, g) => g.OrderBy(i => i.Date).First());

Out of those, get the ones that have been paid within 5 days of their original date.

var result = firstInvoicesForContacts.Where(i => i.FullyPaidOnDate.HasValue && i.FullyPaidOnDate.Value < i.Date.Value.AddDays(5));

rustyskates
  • 856
  • 4
  • 10