Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No custom fields support for Deal, documentation lies #105

Open
f-laino opened this issue Dec 12, 2023 · 16 comments
Open

No custom fields support for Deal, documentation lies #105

f-laino opened this issue Dec 12, 2023 · 16 comments
Assignees

Comments

@f-laino
Copy link

f-laino commented Dec 12, 2023

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?

@Husky110
Copy link

Husky110 commented Jan 6, 2024

You have to do the requests manually, than they support the custom fields. This client is a 💩 -show when it comes to custom fields... Do it manually or you are 💩 out of luck... 🤦‍♂️

@SeoFuchs
Copy link

SeoFuchs commented Feb 3, 2024

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.

@Husky110
Copy link

Husky110 commented Feb 3, 2024

@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.

@SeoFuchs
Copy link

SeoFuchs commented Feb 6, 2024

@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...

@Husky110
Copy link

Husky110 commented Feb 6, 2024

@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!

@siirimangus
Copy link
Contributor

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 👍

@bashmach bashmach self-assigned this May 8, 2024
@raalderink
Copy link

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.

@damienadermann
Copy link

damienadermann commented May 16, 2024

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.

@bashmach
Copy link
Member

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.

@apavliukov
Copy link

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?

@siirimangus
Copy link
Contributor

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.

@chromadesign
Copy link

chromadesign commented Sep 23, 2024

Hi,

I have been tearing my hair out trying to get this to work but every custom field I am trying to add data to is being ignored.

This is the array:

$new_person_data = array(
    "name" => $firstname . " " . $lastname,
    "email" => array(
        "value" => $email,
        "primary"=> "true",
        "label"=> "Büro"
    ),
    "phone" => array(
        "value" => $phone,
        "primary"=> "true",
        "label"=> "Büro"
    ),
    "owner_id" => $owner_id,
    "visible_to" => $visible_to,
    "job_title" => $function,
    "org_id" => $org_id,
    "43089c755de56ecdd1cf926da152dfa0ff813ff1" => "141"
);

I can't see what I'm doing wrong? And strangely enough, "job_title" won't update either, even though it's not a custom field.

@siirimangus
Copy link
Contributor

Hey, @chromadesign!

That's an interesting case as I'm currently having the "works-on-my-machine" moment. Let's try to figure this out.

  • What version of the SDK are you using? The custom fields support was added in v6.7.0.
  • After adding a person, have you also refreshed the page in the Pipedrive app (in case it was a PUT request instead of POST)?
  • What's the flow exactly, you try to add a new person, the name, email etc gets saved, but only the custom field and job title do not?

Based on your example I'm trying something like this and I'm able to add a new person:

$apiInstance = new PersonsApi(...);

$firstname = 'John';
$lastname = 'Doe Updated';
$email = 'test@example.com';
$phone = '123456789';
$owner_id = 1;
$visible_to = 3;
$function = 'CTO';
$org_id = 3;

$new_person_data = array(
  "name" => $firstname . " " . $lastname,
  "email" => array(
      "value" => $email,
      "primary"=> "true",
      "label"=> "Büro"
  ),
  "phone" => array(
      "value" => $phone,
      "primary"=> "true",
      "label"=> "Büro"
  ),
  "owner_id" => $owner_id,
  "visible_to" => $visible_to,
  "job_title" => $function,
  "org_id" => $org_id,
  "c1183f8e1bd7897ce51b4a0ba90549a2c27bf520" => "73"
);

$apiInstance->addPerson($new_person_data);

@chromadesign
Copy link

chromadesign commented Sep 25, 2024

Thanks for the quick feedback! I use version 7.1. The only difference in my code is that I used the example code provided in the docs to add the person to Pipedrive (https://github.com/pipedrive/client-php/blob/master/docs/Api/PersonsApi.md#addperson), e.g.

$apiInstancePerson = new Pipedrive\Api\PersonsApi(
        new GuzzleHttp\Client(),
        $config
);
$new_person = new \Pipedrive\Model\NewPerson($new_person_data);
$add_person = $apiInstancePerson->addPerson($new_person);

Yes, I refreshed the page and tried several times with different test persons.

I am trying to add a person (which means adding all data including job title and custom field) or update an existing person with just the custom field. Every field except job_title and the custom field get added without an issue. When I add the data via Curl or in Postman, it works fine. I even tried a workaround of adding only the data that I know gets added and then updating the two missing fields via Curl. This also works.

@siirimangus
Copy link
Contributor

Aha, ok, with your example, I'm able to reproduce the issue.

It looks like the problem is with the NewPerson model. It lists only the fields that are documented in our API reference and the generator generates only those fields for the model. And while creating a new person as the docs suggest, every other field gets missed.

Currently, I think the best solution here is to skip the step of creating a NewPerson and send the data straight to the addPerson function as done in my example above.

I will reopen this issue and investigate more from our side whether we can somehow make this NewPerson model work properly with every field, or another option - update the code examples so that they would reflect the working solution.

@siirimangus siirimangus reopened this Sep 25, 2024
@chromadesign
Copy link

Yes, that was it! Thanks so much, I got it working with out the model.

@bashmach bashmach assigned siirimangus and unassigned bashmach Oct 30, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

9 participants