client-php icon indicating copy to clipboard operation
client-php copied to clipboard

No custom fields support for Deal, documentation lies

Open f-laino opened this issue 2 years ago • 16 comments

https://github.com/pipedrive/client-php/blob/master/docs/Api/DealsApi.md#adddeal

Note that you can supply additional custom fields ...

but there is no way to do it, isn't it?

f-laino avatar Dec 12 '23 11:12 f-laino

You have to do the requests manually, than they support the custom fields. This client is a :hankey: -show when it comes to custom fields... Do it manually or you are :hankey: out of luck... :man_facepalming:

Husky110 avatar Jan 06 '24 17:01 Husky110

The custom fields are contained in response from PD API but they are ignored by object serialization.

Quickfix: in ObjectSerializer.php add the following line to "deserialize" function before $instance is returned.

$instance->raw = $data;

This will add full response data to the built object.

SeoFuchs avatar Feb 03 '24 14:02 SeoFuchs

@SeoFuchs - Thanks for your reply, but I'm using the client within a laravel-project, so all external dependencies (like this client) are handled by composer. Every change I do in there will be overwritten by the next update. So far I refered to send manual Requests when needed but your fix should be implemented by default.

Husky110 avatar Feb 03 '24 21:02 Husky110

@Husky110 Thats right, everything will be overwritten in vendor directory. But you could either integrate the package in your project to keep changes save or extend the ObjectSerializer class ;-) Anyway, I am with you, it should be implemented by default...

SeoFuchs avatar Feb 06 '24 12:02 SeoFuchs

@SeoFuchs - "But you could either integrate the package in your project to keep changes save or extend the ObjectSerializer class ;-)" -> nice! And whenever Pipedrives updates it's API I have to manually update aswell... GG!

Husky110 avatar Feb 06 '24 17:02 Husky110

Hey, thank you for noticing and reporting. The fix should definitely be done on our side in our SDK generator, we'll have a task for that 👍

siirimangus avatar Apr 19 '24 11:04 siirimangus

In the original post the DealsApi was specifically mentioned, however, as this is due to the ObjectSerializer class ignoring extra fields, this is for any API that allows for custom fields. We're running into this same issue with the organizations.

raalderink avatar May 10 '24 14:05 raalderink

For anyone coming across this I've just hit this issue and have started a work around. If you extend the DealsApi you get access to the client and request factories so you can just rewrite getDeal to skip the broken serializer.


namespace App\Services\Pipedrive;

class DealsApi extends \Pipedrive\Api\DealsApi
{
    public function getDeal($id) {
        $request = $this->getDealRequest($id);

        $options = $this->createHttpClientOption();
        $response = $this->client->send($request, $options);
        $stream = $response->getBody();
        $content = $stream->getContents();
        return json_decode($content);
    }
}

This method is incomplete because you need to add the different error and oauth handling but in my simple happy path test I have access to all the custom fields.

Have a look at https://github.com/pipedrive/client-php/blob/master/lib/Api/DealsApi.php#L3197 to see what error handling needs to be added.

Hopefully this is fixed soon so these workarounds aren't needed.

damienadermann avatar May 16 '24 13:05 damienadermann

Hi everyone,

Released a new version that includes a new getRawData methods in models.

It provides access to full API response, including the properties which are not available in openapi generated models. Basic usage:

$dealsApiInstance = new DealsApi(...);

$deal = $dealsApiInstance->getDeal($id);

// get deal title
$title = $deal->getData()->getTitle();
or 
$title = $deal->getRawData()->title;

// get custom field
$customField = $deal->getRawData()->{$customFieldKey};

Feel free to reach us in case of any questions.

bashmach avatar May 17 '24 05:05 bashmach

Hello @bashmach, thanks for the update. I'm trying to send custom fields with addPerson like this:

$apiInstance = new PersonsApi(...);

$newPerson = new NewPerson($data);
$newPerson->setRawData(json_decode(json_encode(['data' => $customFields]), false));

$apiInstance->addPerson($newPerson);

If I use $newPerson->getRawData() I see an array of my custom fields. But they are not pushed to Pipedrive.

Am I doing something wrong or there is no way to send custom fields via this package?

apavliukov avatar Jul 22 '24 13:07 apavliukov

Hey, @apavliukov! Sending custom fields can be done as follows.

  • If you already have a custom field created, then:
$apiInstance = new PersonsApi(...);

$personData = [
    'name' => 'John Custom',
    '4c60861d5eed1ed8959a5d6c258808d524c12345' => 'this is my existing custom field' // the key is your existing custom field key
];

$apiInstance->addPerson($personData);
  • If you want to create a new custom field along with the new person:
$personsApi = new PersonsApi(...);
$personFieldsApi = new PersonFieldsApi(...);

$newCustomField = $personFieldsApi->addPersonField([
    'name' => 'my new custom field',
    'field_type' => 'varchar',
]);
$customFieldKey = $newCustomField->getData()->getKey();

$personData = [
    'name' => 'John Custom',
    $customFieldKey => 'new custom field value'
];

$personsApi->addPerson($personData);

I will close the issue for now. Please reach out and feel free to reopen the issue in case this example doesn't work for you.

siirimangus avatar Sep 06 '24 12:09 siirimangus