IsraelOrtuno/pipedrive

API break on addProduct to deals

mikebastarache opened this issue · 1 comments

I had originally contacted Pipedrive directly, but their response was;

We were unable to reproduce the error using our official PHP library. It seems to be an issue on the Devio\Pipedrive\Pipedrive library side. We see from our logs that the library is converting all of the values, for some reason, to string types and since the id, product_id, item_price and quantity parameters are either integer or number types (documentation link), the request fails.

The Devio\Pipedrive\Pipedrive library is a community-built library and not officially supported from our side, therefore it would be a good idea to raise the issue there.

We have been using this code for over 1 year and in March it stopped working for us.

try {
$pipedrive = new Pipedrive($this->token);
$itemResponse = $pipedrive->deals()->addProduct($id, $product_id, $item_price, $quantity, $options);
} catch (Exception $e) {
return false;
}

We confirmed with the PHP debugger that all values are integers. But as mentioned by Pipedrive, the integers are getting converted to a string when they are passed through the library and the API fails.

I believe it's related to the fact that this library use form_params by default for requests.

from Guzzle RequestOption class:

form_params: (array) Associative array of form field names to values
     * where each value is a string or array of strings. Sets the Content-Type
     * header to application/x-www-form-urlencoded when no Content-Type header
     * is already present.

I noticed it also transform null values into empty strings.

Pipedrive recomends using JSON body in https://pipedrive.readme.io/docs/core-api-concepts-requests

We recommend using JSON body format when performing API requests.

I made a fork to change this default behaviour. (but didn't keep it up to date lately)

I'm happy to open a PR, but not sure if it would be a breaking change.