In Version 3.2 of the PHP package, I get the following exception when calling getDealsTimeline:
InvalidArgumentException
JsonMapper::map() requires first argument to be an object, array given.
apimatic/jsonmapper/src/JsonMapper.php:103
apimatic/jsonmapper/src/JsonMapper.php:270
apimatic/jsonmapper/src/JsonMapper.php:322
vendor/pipedrive/pipedrive/src/Controllers/DealsController.php:396
I submitted this with more detail as a Github issue and also submitted a Pull Request with my proposed fix.
opened 05:26PM - 06 Oct 21 UTC
InvalidArgumentException
JsonMapper::map() requires first argument to be an obj… ect, array given.
in vendor/apimatic/jsonmapper/src/JsonMapper.php:103
![image](https://user-images.githubusercontent.com/380727/136251661-da075162-36eb-4de0-805b-2d9a2cc97add.png)
It looks like the getDealsTimeline API response returns an object with the data member as an array for like this:
```
object(stdClass)#2247 (2) {
["success"]=>
bool(true)
["data"]=>
array(12) {
[0]=>
object(stdClass)#2244 (4) {
["period_start"]=>
string(19) "2021-08-01 00:00:00"
["period_end"]=>
string(19) "2021-08-31 23:59:59"
["deals"]=>
array(9) {
[0]=>
object(stdClass)#2246 (69) {
["id"]=>
int(1193)
["creator_user_id"]=>
int(149104)
["user_id"]=>
...
```
When jsonmapper tries to map this response in `pipedrive/pipedrive/src/Controllers/DealsController.php:459` the data ends up being recognized as an object of type `\Pipedrive\Models\Data25` rather than as an array. But in `apimapper/jsonmapper/src/JsonMapper.php:103` an InvalidArgumentException is thrown because `$json` that is passed in is an array rather than an object.
Ultimately, I think JsonMapper should be calling `mapArray` or `mapClassArray` around `JsonMapper.php:247` but it is instead trying to call `map` which only works with an object.
I wish I could have determined the root cause here to provide a merge request to fix this, but the best I could come up with is to skip using JsonMapper and to instead just return the object that comes back from the API. This looks like:
```
--- vendor/pipedrive/pipedrive/src/Controllers/DealsController.php.old
+++ vendor/pipedrive/pipedrive/src/Controllers/DealsController.php
@@ -454,7 +454,7 @@ class DealsController extends BaseContro
$mapper = $this->getJsonMapper();
- return $mapper->mapClass($response->body, 'Pipedrive\\Models\\GetDealsTimeline');
+ return $response->body;
}
```
That solution neglects whatever value JsonMapper has.
Thanks for your help troubleshooting and fixing this issue!
pipedrive:master
← buckii:get-deals-timeline-data-array-fix
opened 06:54PM - 06 Oct 21 UTC
This fixes a JsonMapper exception thrown by DealsController::getDealsTimeline() … on DealsController.php:396 .
Fixes #52
r2d2
December 30, 2021, 8:55pm
2
Hi,
Thanks for the contribution This means a lot to the community. Were you able to solve the challenge? If it is still open, feel free to create a new topic.