picqer / moneybird-php-client

PHP Client for Moneybird V2
MIT License
82 stars 77 forks source link

How to combine filter with paging when fetching SalesInvoices #254

Closed malle-pietje closed 2 years ago

malle-pietje commented 2 years ago

Working with this client I'm running into an issue where I need to fetch invoices for a certain time period using filters. The maximum number of SalesInvoices returned for a single request is 100, how do we use paging in these cases?

For now I've created this method in one of my classes:

    public function listInvoices($page, $per_page = 100, $filter = [])
    {
        if (!empty($filter)) {
            return $this->moneybird_client->salesInvoice()->filter($filter);
        }

        return $this->moneybird_client->salesInvoice()->get([
            'per_page' => $per_page,
            'page'     => $page,
        ]);
    }

I have tried to combine the two but that doesn't work.

malle-pietje commented 2 years ago

This combination of filtering and paging does seem to work with a test/sandbox administration but need to test it against a live environment:

    public function listInvoices($page, $per_page = 100, $filter = '')
    {
        $params = [
            'per_page' => $per_page,
            'page'     => $page
        ];

        if (!empty($filter)) {
            $params['filter'] = $filter;
        }

        return $this->moneybird_client->salesInvoice()->get($params);
    }