IsraelOrtuno / pipedrive

Complete Pipedrive API client for PHP
MIT License
166 stars 58 forks source link

Issue with creation of Filters #27

Closed willjosefi closed 5 years ago

willjosefi commented 7 years ago

There's a issue when creating a new "Filter". I think the problem is with the use of a "json" field in request.

My request is like that:

$newFilter = array(
    'glue' => 'and',
    'conditions' => array(
        array(
            'glue' => 'and',
            'conditions' => array(
                array(
                    'object' => 'person',
                    'field_id' => '9039', // phone
                    'operator' => '=',
                    'value' => 'xxxxxxxxxxx',
                    'extra_value' => null,
                )
            ),
        ),
        array(
            'glue' => 'or',
            'conditions' => array(),
        ),
    ),
);

$pipedrive = new \Devio\Pipedrive\Pipedrive('xxxxxx');
$addFilter = $pipedrive->filters->add(array(
    'name' => 'Filter Name 0123',
    'conditions' => $newFilter,
    'type' => 'people',
));

I receive the follow exception

Fatal error: Uncaught exception 'Devio\Pipedrive\Exceptions\PipedriveException' with message 'This field is missing.' in /var/wxu/test/pipedrive-test/vendor/devio/pipedrive/src/Http/Request.php:85 Stack trace: #0...

I "solved" the issue with a small change in PipedriveClient.php

public function post($url, $parameters = [])
    {
        $request = new GuzzleRequest('POST', $url);
        $form = 'form_params';

        // If any file key is found, we will assume we have to convert the data
        // into the multipart array structure. Otherwise, we will perform the
        // request as usual using the form_params with the given parameters.
        if (isset($parameters['file'])) {
            $form = 'multipart';
            $parameters = $this->multipart($parameters);
        }

        // This was generated with error: return $this->execute($request, [$form => $parameters]);
        // Replace with that:
        return $this->execute($request, ['json' => $parameters]);
    }

But for obvious reasons this will break the file upload.

Maybe someone can work in a fix? ... or i missing something?

IsraelOrtuno commented 7 years ago

We will have to add a kind of mapper for JSON requests. Will dig into this in the upcoming days.