Nascom / TeamleaderApiClient

PHP Client to connect to the Teamleader API
MIT License
9 stars 9 forks source link

POST method in requests seems unused? #12

Closed svendecabooter closed 5 years ago

svendecabooter commented 5 years ago

I'm using the v2-refactor branch, to integrate Teamleader with a Drupal 8 site.

When adding a new draft invoice, I'm getting the following error:

Client error: `GET https://api.teamleader.eu/invoices.draft` resulted in a `405 Method Not Allowed` response: @"errors":[{"code":405000,"title":"Method GET not allowed. Allowed method(s): POST","status":405]} 

When debugging, it seems the $method property of the \Nascom\TeamleaderApiClient\Request\Invoicing\Invoices\InvoicesDraftRequest class is set to NULL. It should use POST from its PostRequest class inheritance, but it seems the usage of MultipleMethodsTrait overrides this.

Since the method is NULL, it gets set to GET by default.

See the screenshot of my debugger, in \League\OAuth2\Client\Provider\AbstractProvider::createRequest(): Selection_007

Interestingly, when trying to add new contact, I also did debugging to see the difference. There the same problem occurs, and the method used is also GET.

But it seems in the latter case the Teamleader API does not reject the call, but in the former it does.

Do we need to call setMethod() explicitly in Request classes where a POST is desired? Or what would be the appropriate way to handle this?

mark-gerarts commented 5 years ago

Hi @svendecabooter, thanks for the detailed writeup. The idea behind the MultipleMethodsTrait is to provide the ability to perform the request in multiple ways (since the Teamleader API supports this for some endpoints).

This is definitely a bug. A request extending the PostRequest should default to POST as method. @yoerioptr might be able to look into this. We could fix the bug, or maybe think of some alternative way to change the method of the request classes.

yoerioptr commented 5 years ago

Hi @svendecabooter, Thanks for reporting the issue. It should be fixed by now.

svendecabooter commented 5 years ago

Thanks for the quick followup @yoerioptr & @mark-gerarts !