invoiceninja / sdk-php

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

Get tasks by client #24

Closed fibis closed 6 years ago

fibis commented 7 years ago

I tried to get all tasks for a client via the API with $tasks = Task::findByClientID(12);. I get this error:


Deprecated: Non-static method InvoiceNinja\Models\AbstractModel::findByClientID() should not be called statically in cron.php on line 16

Fatal error: Uncaught Exception: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>301 Moved Permanently</title> </head><body> <h1>Moved Permanently</h1> <p>The document has moved <a href="https://ninja.test/api/v1/tasks?client_id=12&amp;">here</a>.</p> </body></html> in vendor/invoiceninja/sdk-php/src/InvoiceNinja/Models/AbstractModel.php:186 Stack trace: #0vendor/invoiceninja/sdk-php/src/InvoiceNinja/Models/AbstractModel.php(47): InvoiceNinja\Models\AbstractModel::sendRequest('https://ninja..') #1 cron.php(16): InvoiceNinja\Models\AbstractModel::findByClientID(12) #2 {main} thrown in vendor/invoiceninja/sdk-php/src/InvoiceNinja/Models/AbstractModel.php on line 186

Is there a fix for the problem?

marcoboers commented 7 years ago

find() is a static function while findByClientID() is not. You could try the following, but maybe it should be defined as a static function instead $task = new Task; $tasks = $task->findByClientID(12);

fibis commented 7 years ago

Thanks for your suggestion. I tried it but I get still this error:

Fatal error: Uncaught Exception: <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN"> <html><head> <title>301 Moved Permanently</title> </head><body> <h1>Moved Permanently</h1

It seems to be an error in the route to get the data.

hillelcoren commented 7 years ago

I've checked in a fix for this and created a new release.

It should now work using Task::findByClientId(12)

Note: it's been changed to a lower case 'd' in Id.