invoiceninja / sdk-php

PHP wrapper for Invoice Ninja's REST API
https://www.invoiceninja.com
83 stars 41 forks source link

When trying to fetch all expenses, I only get 15? #21

Closed alexbogias closed 3 years ago

alexbogias commented 7 years ago

Why when trying to grab all expenses the array that returns always gives 15 values? $expenses = Expense::all();

alexbogias commented 7 years ago

OK just found it! I used: NinjaConfig::setPerPage(9999);

marcoboers commented 7 years ago

The sendRequest function uses pagination even when using function all. You could use NinjaConfig::setPerPage(100);

stevro commented 7 years ago

Hi, I think something is wrong about the ::all() method. You cannot simply use setPerPage option as in the API code there is a MAX_API_PAGE_SIZE constant which is 500. Here's the line of code So using NinjaConfig::setPerPage(9999); will not bring you more than 500 records.

I guess this was added as a precaution, but how are we supposed to paginate the results trough the API, as the sdk does not provide us back the meta data like current page, total pages?

If I look directly at the response the application returns this meta data is included, but they get lost in the sendRequest method.

This method needs some refactoring as currently I don't see how we could get all of the results from an endpoint.

hillelcoren commented 7 years ago

It looks like we'd need to expose the pagination through the SDK

marcoboers commented 7 years ago

At the API docs page under optional settings, it lists the page parameter. So I guess it only needs a minor adjustment in the sdk sendRequest function: https://github.com/invoiceninja/sdk-php/blob/master/src/InvoiceNinja/Models/AbstractModel.php#L153

http://docs.invoiceninja.com/en/latest/api.html

marcoboers commented 7 years ago

Maybe there should be an options parameter (array) for the sendRequest function, that is merged with the other options?

hillelcoren commented 7 years ago

That sounds about right..