skip to Main Content

I need to request all invoices within a quarter, and return and sum the amount of each line item grouped by the line items account. However, no matter how I build the request the line items array is empty.

I am using the calcinai/xero-php library and have a working mockup that returns the data I expect it to:

  private static function getBillsPaid($xeroClient) {
    // ... some setup

    $bills = $xero->load(XeroPHPModelsAccountingInvoice::class)
      ->where('Type', XeroPHPModelsAccountingInvoice::INVOICE_TYPE_ACCPAY)
      ->where('Status', XeroPHPModelsAccountingInvoice::INVOICE_STATUS_PAID)
      ->where("Date >= DateTime($start)")
      ->where("Date <= DateTime($end)")
      ->execute();

    $billsByAccount = new Map();
    foreach ($bills as $bill) {
      $invoice = $xero->loadByGUID(XeroPHPModelsAccountingInvoice::class, $bill->getInvoiceID());
      foreach ($invoice->getLineItems() as $lineItem) {
        $billsByAccount->addListItemSum(
          $lineItem->getAccountCode(),
          $invoice->getCurrencyCode(),
          $lineItem->getUnitAmount()
        );
      }
    }

    return $billsByAccount->getAll();
  }

This works, however, it has to make a new request to load the line items for each invoice. What I need is for all the information to be loaded in a single request ($bills) so that it doesn’t throw a "too many requests" error.

I have looked at the documentation and in theory adding a summaryOnly=True query to the request should resolve the issue I am facing.

However, adding ->setParameter('summaryOnly', 'true') to the request causes it throw a "bad request" error unless I remove both date queries from the request. But, even if I do remove the date queries it still doesn’t include the line items.

For reference, when not fetching the $invoice, I am trying to get the line items from $bills->getLineItems().

What am I missing?

2

Answers


  1. Can you try adding the page param e.g. ?page=1

    Login or Signup to reply.
  2. SummaryOnly=true will ensure that no line items are returned rather than the opposite. As Doel has mentioned, using paging will give you the detailed response you need.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search