Values of deal custom fields missing when using getAllDeals from client-php

I’m using official PHP API client and it’s getAllDeals() method. It works as expected, but I don’t get any of my deal custom fields.

When I test it on official API reference docs, I get custom fields, e.g.:

"f00a99b096ee8dca2656856814bcdf543540a0f1": "Value of my custom field",

However, those fields are simply not there when using PHP client, I’m getting only basic deal fields…

Does anyone have a clue what is wrong here?

Regards,
Petar

It seems the problem is in a way how does getAllDeals() method transforms the API response. If I change the highlighted line to
return CamelCaseHelper::keysToCamelCase($response->body);
(borrowed that from getAllOrganizations() :wink:) I’m getting unfiltered response…

However, very strange to have such inconsistencies in similar controllers :thinking:

1 Like

Hi @petar

Thanks for bringing this to our attention. I’ll give this info to our team and see if we can get this inconsistency cleared up.

1 Like

@David Is this fix on the roadmap?

I’m running into the same issue with DealsController::getDealsTimeline where $mapper->map removes custom fields. The proposed solution from petar above would work great for getDealsTimeline and other endpoints.

For now, I’ve had to write my own Guzzle HTTP requests to return the raw response. If you could fix this in the PHP package, it would be ver helpful!

Hi @David (or whoever else),

unbelieveble, but this problem with PHP client is not solved after 3 years and many new versions of PHP client :frowning:

But the difference with the actual client version is that I cannot borrow the solution from OrganizationsApi::getOrganization because it’s messed up there as well.

Please, give us the way to get values of deal custom fields using PHP client!

Still the same problem with PHP client…
This problem is not only relevant with deals but also with other models such as organizations.
We can’t get custom field values or can’t update custom field values on existing models.

Are there any plans on fixing this issue?

Not sure if this will be ever fixed so I wrote a quick patch that allows me to get the custom field values from organizations and update them. Not the best solution but it works for my use case.

 .../pipedrive/lib/Model/OrganizationItem.php     | 10 ++++++++++
 .../pipedrive/lib/Model/UpdateOrganization.php   | 16 ++++++++++++++++
 .../pipedrive/pipedrive/lib/ObjectSerializer.php | 14 ++++++++++++++
 3 files changed, 40 insertions(+)

diff --git a/lib/Model/OrganizationItem.php b/lib/Model/OrganizationItem.php
index a48c3c1e7..9c574d7b6 100644
--- a/lib/Model/OrganizationItem.php
+++ b/lib/Model/OrganizationItem.php
@@ -48,6 +48,8 @@ class OrganizationItem implements ModelInterface, ArrayAccess, JsonSerializable
 {
     public const DISCRIMINATOR = null;

+    protected array $leftOvers = [];
+
     /**
       * The original name of the model.
       *
@@ -487,6 +489,14 @@ public function __construct(array $data = null)
         $this->container['next_activity'] = $data['next_activity'] ?? null;
     }

+    public function setLeftOvers(array $leftOvers): void {
+      $this->leftOvers = $leftOvers;
+    }
+
+    public function getLeftOvers(): array {
+      return $this->leftOvers;
+    }
+
     /**
      * Show all the invalid properties with reasons.
      *
diff --git a/lib/Model/UpdateOrganization.php b/lib/Model/UpdateOrganization.php
index 5be5d090e..5fd8af150 100644
--- a/lib/Model/UpdateOrganization.php
+++ b/lib/Model/UpdateOrganization.php
@@ -48,6 +48,8 @@ class UpdateOrganization implements ModelInterface, ArrayAccess, JsonSerializabl
 {
     public const DISCRIMINATOR = null;

+    protected array $custom = [];
+
     /**
       * The original name of the model.
       *
@@ -242,6 +244,20 @@ public function valid(): bool
         return count($this->listInvalidProperties()) === 0;
     }

+    public function setCustom(array $custom): self
+    {
+        $this->custom = $custom;
+
+        return $this;
+    }
+
+    public function appendCustom(array $values): array {
+      foreach ($this->custom as $key => $value) {
+        $values[$key] = $value;
+      }
+
+      return $values;
+    }

     /**
      * Gets name
diff --git a/lib/ObjectSerializer.php b/lib/ObjectSerializer.php
index 05a11d9d2..b32f1a007 100644
--- a/lib/ObjectSerializer.php
+++ b/lib/ObjectSerializer.php
@@ -110,6 +110,11 @@ public static function sanitizeForSerialization($data, $type = null, string $for
                     }
                 }
             }
+
+          if (method_exists($data, 'appendCustom')) {
+            $values = $data->appendCustom($values);
+          }
+
             return (object)$values;
         } else {
             return (string)$data;
@@ -388,9 +393,13 @@ public static function deserialize($data, string $class, array $httpHeaders = nu

             /** @var ModelInterface $instance */
             $instance = new $class();
+            $leftovers = (array) $data;
+
             foreach ($instance::openAPITypes() as $property => $type) {
                 $propertySetter = $instance::setters()[$property];

+                unset($leftovers[$property]);
+
                 if (!isset($propertySetter) || !isset($data->{$instance::attributeMap()[$property]})) {
                     continue;
                 }
@@ -400,6 +409,11 @@ public static function deserialize($data, string $class, array $httpHeaders = nu
                     $instance->$propertySetter(self::deserialize($propertyValue, $type, null));
                 }
             }
+
+            if (method_exists($instance, 'setLeftOvers')) {
+                $instance->setLeftOvers($leftovers);
+            }
+
             return $instance;
         }
     }
--
2.34.1