Giter Club home page Giter Club logo

client-php's People

Contributors

alex-bukach avatar bashmach avatar divineomega avatar estevanjantsk avatar jr-k avatar mghtinlynn avatar mykhailo-riabokon avatar ph-7 avatar poethrenoff avatar s-pogoda avatar siimkirjanen avatar siirimangus avatar spaceoven avatar uopals avatar youssef-saber-3 avatar ziimk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

client-php's Issues

Test issue

Test issue to check if appropriate slack channel is notified

Leads API

Hi guys,

Any plans to implement methods for Leads management via API?

Thanks,
Ros

"getDetailsOfADeal" doesn't contain Deal Custom Fields in response

Hello!
I am trying to connect my project to PipeDrive and decided to use this php client, but I have some issues.
"getDetailsOfADeal" doesn't return custom fields, direct API call response has them in "data", but when I use this client, $response ->data contains only default set of fields.

Checked all the documentation I could, but still cannot find the answer, is there any way to get deal custom field value via this client?

updateAPerson without email address or phone fails

$client->getPersons()->updateAPerson([
    'id' => 123,
    'name' => 'John Doe',
]);

results in

Warning: array_values() expects parameter 1 to be array, null given  
                                                                       
Exception trace:
  at vendor/pipedrive/pipedrive/src/Controllers/PersonsController.php:445

(or line 446 for phone)
coming from this code:

        $_parameters = array (
            'name'       => $this->val($options, 'name'),
            'owner_id'   => $this->val($options, 'ownerId'),
            'org_id'     => $this->val($options, 'orgId'),
            'email'    => array_values($this->val($options, 'email')),
            'phone'    => array_values($this->val($options, 'phone')),
            'visible_to' => APIHelper::prepareFormFields($this->val($options, 'visibleTo'))
        );

array_values() is called with null if no email or phone is provided (which are optional)

missing 1 parameter lead_id on ActivitiesController

current version missing 'lead_id' => $this->val($options, 'leadId')

$_parameters = array (
            'subject'      => $this->val($options, 'subject'),
            'type'         => $this->val($options, 'type'),
            'done'         => APIHelper::prepareFormFields($this->val($options, 'done')),
            'due_date'     => DateTimeHelper::toSimpleDate($this->val($options, 'dueDate')),
            'due_time'     => $this->val($options, 'dueTime'),
            'duration'     => $this->val($options, 'duration'),
            'user_id'      => $this->val($options, 'userId'),
            'deal_id'      => $this->val($options, 'dealId'),
            'person_id'    => $this->val($options, 'personId'),
            'participants' => $this->val($options, 'participants'),
            'org_id'       => $this->val($options, 'orgId'),
            'note'         => $this->val($options, 'note'),
            'busy_flag'    => $this->val($options, 'busyFlag')
        );

i expected same with API documentation on pipedrive addActivity documentation

$_parameters = array (
            'subject'      => $this->val($options, 'subject'),
            'type'         => $this->val($options, 'type'),
            'done'         => APIHelper::prepareFormFields($this->val($options, 'done')),
            'due_date'     => DateTimeHelper::toSimpleDate($this->val($options, 'dueDate')),
            'due_time'     => $this->val($options, 'dueTime'),
            'duration'     => $this->val($options, 'duration'),
            'user_id'      => $this->val($options, 'userId'),
            'deal_id'      => $this->val($options, 'dealId'),
            'lead_id'.     => $this->val($options, 'leadId'), // ====> ADD LEAD ID HERE
            'person_id'    => $this->val($options, 'personId'),
            'participants' => $this->val($options, 'participants'),
            'org_id'       => $this->val($options, 'orgId'),
            'note'         => $this->val($options, 'note'),
            'busy_flag'    => $this->val($options, 'busyFlag')
        );

Cannot update person custom fields

Hi,

I am just trying to update a person. It is working, except the custom fields of a person. Those are not handled by the PersonController. This seem to be a great bug in the code. When I add the following lines in the method PersonController::updateAPerson in line 455 it seems to work:

foreach ($options as $key => $value) {
    if (!in_array($key, ['id', 'name', 'owner_id', 'org_id', 'email', 'phone', 'visible_to'])) {
        $_parameters[$key] = $value;
    }
}

This is clearly a bug in this lib for me and makes the whole lib pointless/useless.

updateAPerson and other updates don't consider custom fields

only this fields will be changed:

        $_parameters = array (
            'name'       => $this->val($options, 'name'),
            'owner_id'   => $this->val($options, 'ownerId'),
            'org_id'     => $this->val($options, 'orgId'),
            'email'    => array_values($this->val($options, 'email')),
            'phone'    => array_values($this->val($options, 'phone')),
            'visible_to' => APIHelper::prepareFormFields($this->val($options, 'visibleTo'))
        );

busyFlag is not supported for adding/updating activity

ActivitiesController.php

addAnActivity():

$_parameters = array (
            'subject'      => $this->val($options, 'subject'),
            'type'         => $this->val($options, 'type'),
            'done'       => APIHelper::prepareFormFields($this->val($options, 'done')),
            'due_date'   => DateTimeHelper::toSimpleDate($this->val($options, 'dueDate')),
            'due_time'     => $this->val($options, 'dueTime'),
            'duration'     => $this->val($options, 'duration'),
            'user_id'      => $this->val($options, 'userId'),
            'deal_id'      => $this->val($options, 'dealId'),
            'person_id'    => $this->val($options, 'personId'),
            'participants' => $this->val($options, 'participants'),
            'org_id'       => $this->val($options, 'orgId'),
            'note'         => $this->val($options, 'note')
        );

busy_flag parameter is missing - it's in documentation: https://developers.pipedrive.com/docs/api/v1/Activities#addActivity

Fatal error in OrganizationFieldsApi->getOrganizationFields()

Fatal error: Uncaught InvalidArgumentException: Invalid value for enum '\Pipedrive\Model\FieldTypeAsString', must be one of: 'address', 'date', 'daterange', 'double', 'enum', 'monetary', 'org', 'people', 'phone', 'set', 'text', 'time', 'timerange', 'user', 'varchar', 'varchar_auto', 'visible_to' in /vendor/pipedrive/pipedrive/lib/ObjectSerializer.php:375

Retrieving indivudual fields via OrganizationFieldsApi->getOrganizationField($id) works fine

AddFile return error

Hi
I'm trying to add a document to pipdrive but I have the following error: operation aborted by callback and i don't undestrand the error

My code

  $pipeDrive = $this->client;
 $files = $pipDrive->getFiles();
$collect['file'] = $pathfile ;  // public/uploads/filename.pdf =>
$collect['personalId'] = 1;
$files->addFile($collect);

Thank's for help

Inconsistent use of camelCase breaks things

Some controller functions use CamelCaseHelper::keysToCamelCase() on the function return value, and some don't. For example, in DealsController.php getDetailsOfADeal() ends like this:

return $mapper->mapClass($response->body, 'Pipedrive\\Models\\GetDeal');

but, in OrganizationsController.php, listDealsAssociatedWithAnOrganization() ends like this:

return CamelCaseHelper::keysToCamelCase($response->body);

This can play havoc in some situations.

ItemSearch missing

This library looks out of date as it's using deprecated search functions like findPersonsByName. Will it be updated with the ItemSearch controller or should we move too interacting with the API directly?

Uncaught Error: Call to undefined method Pipedrive\Configuration::setApiKey()

I'm using the following code from the example. I'm running PHP 7.4.3 and get this error "Uncaught Error: Call to undefined method Pipedrive\Configuration::setApiKey()"

$ssdpath = get_stylesheet_directory();

use Pipedrive\Configuration;

require_once($ssdpath . '/vendor/autoload.php');


// Create a Configuration object and set the API key as an array

// Configure API key authorization: api_key
$config = (new Pipedrive\Configuration())->setApiKey('api_token', 'YOUR_API_KEY');

$apiInstance = new Pipedrive\Api\ActivitiesApi(
// If you want use custom http client, pass your client which implements `GuzzleHttp\ClientInterface`.
// This is optional, `GuzzleHttp\Client` will be used as default.
    new GuzzleHttp\Client(),
    $config
);

try {
    $result = $apiInstance->getActivities();
    echo '<pre>';
    print_r($result);
    echo '</pre>';
} catch (Exception $e) {
    echo 'Exception when calling ActivitiesApi->getActivities: ', $e->getMessage(), PHP_EOL;
}

If I use just this code, i do not get any error:

$ssdpath = get_stylesheet_directory();

use Pipedrive\Configuration;

require_once($ssdpath . '/vendor/autoload.php');


// Create a Configuration object and set the API key as an array
$config = new \Pipedrive\Configuration();

So it seems like for whatever reason the setApiKey method is not available?

I have tried uninstalling pipedrive with composer and then reinstalling, and get the same result.

If it's of any consequence, I am using composer via SSH on a wpengine server. Thanks

[BUG] getAllWebhooks() last_delivery_time incorrect format

Exception:
production.ERROR: Incorrect format. {"userId":1,"email":"[email protected]","exception":"[object] (Exception(code: 0): Incorrect format. at /vendor/pipedrive/pipedrive/src/Utils/DateTimeHelper.php:73)
[stacktrace]
#0 [internal function]: Pipedrive\Utils\DateTimeHelper::fromSimpleDate('2020-03-30T13:3...')
#1 /vendor/apimatic/jsonmapper/src/JsonMapper.php(183): call_user_func('\\Pipedrive\\Util...', '2020-03-30T13:3...')
#2 /vendor/apimatic/jsonmapper/src/JsonMapper.php(523): apimatic\jsonmapper\JsonMapper->map(Object(stdClass), Object(Pipedrive\Models\Data29))
#3 /vendor/apimatic/jsonmapper/src/JsonMapper.php(247): apimatic\jsonmapper\JsonMapper->mapArray(Array, Array, '\\Pipedrive\\Mode...')
#4 /vendor/apimatic/jsonmapper/src/JsonMapper.php(319): apimatic\jsonmapper\JsonMapper->map(Object(stdClass), Object(Pipedrive\Models\WebhooksResponse))
#5 /vendor/pipedrive/pipedrive/src/Controllers/WebhooksController.php(97): apimatic\jsonmapper\JsonMapper->mapClass(Object(stdClass), 'Pipedrive\\Model...')
#6 /pipedriveplugin/Controllers/PluginController.php(45): Pipedrive\Controllers\WebhooksController->getAllWebhooks()

I think at /pipedrive/pipedrive/src/Models/Data29.php need to change:

$json['last_delivery_time'] = isset($this->lastDeliveryTime) ? DateTimeHelper::toSimpleDate($this->lastDeliveryTime) : null;

to

$json['last_delivery_time'] = isset($this->lastDeliveryTime) ? DateTimeHelper::toRfc3339DateTime($this->lastDeliveryTime) : null;

and

/**
* The last delivery time of the Webhook
* @maps last_delivery_time
* @factory \Pipedrive\Utils\DateTimeHelper::fromSimpleDate
* @var \DateTime|null $lastDeliveryTime public property
*/
public $lastDeliveryTime;

to

/**
* The last delivery time of the Webhook
* @maps last_delivery_time
* @factory \Pipedrive\Utils\DateTimeHelper::fromRfc3339DateTime
* @var \DateTime|null $lastDeliveryTime public property
*/
public $lastDeliveryTime;

getProductfields fails

Unnecessary use json mapper. It fails.

$mapper->mapClass($response->body, 'Pipedrive\\Models\\GetAllProductFieldsResponse')

Use this:

CamelCaseHelper::keysToCamelCase($response->body);

getAllPersonFields - does not have pagination param support

 /**
     * Returns data about all person fields
     *
     * @return void response from the API call
     * @throws APIException Thrown if API call fails
     */
    public function getAllPersonFields()
    {
        //check or get oauth token
        OAuthManager::getInstance()->checkAuthorization();

        //prepare query string for API call
        $_queryBuilder = '/personFields';

        //validate and preprocess url
        $_queryUrl = APIHelper::cleanUrl(Configuration::getBaseUri() . $_queryBuilder);

So, there is no way to add any query params and this only return first 100 results.

FieldTypeAsString not accepted during deserialization

Stack trace:

PHP Fatal error:  Uncaught InvalidArgumentException: Invalid value for enum '\Pipedrive\Model\FieldTypeAsString', must be one of: 'address', 'date', 'daterange', 'double', 'enum', 'monetary', 'org', '
people', 'phone', 'set', 'text', 'time', 'timerange', 'user', 'varchar', 'varchar_auto', 'visible_to' in ...\vendor\pipedrive\pipedrive\lib\ObjectSerializer.php:375
Stack trace:
#0 ...\vendor\pipedrive\pipedrive\lib\ObjectSerializer.php(400): Pipedrive\ObjectSerializer::deserialize('int', '\\Pipedrive\\Mode...', NULL)
#1 ...\vendor\pipedrive\pipedrive\lib\ObjectSerializer.php(287): Pipedrive\ObjectSerializer::deserialize(Object(stdClass), '\\Pipedrive\\Mode...', NULL)
#2 ...\vendor\pipedrive\pipedrive\lib\ObjectSerializer.php(400): Pipedrive\ObjectSerializer::deserialize(Array, '\\Pipedrive\\Mode...', NULL)
#3 ...\vendor\pipedrive\pipedrive\lib\Api\DealFieldsApi.php(1373): Pipedrive\ObjectSerializer::deserialize(Object(stdClass), '\\Pipedrive\\Mode...', Array)
#4 ...\vendor\pipedrive\pipedrive\lib\Api\DealFieldsApi.php(1314): Pipedrive\Api\DealFieldsApi->getDealFieldsWithHttpInfo(0, NULL)

PHP8.1 deprecation notices

Using this package with PHP8.1 thows a lot of deprecation notices:

PHP Deprecated:  Return type of Pipedrive\Models\PostNote::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/vendor/pipedrive/pipedrive/src/Models/PostNote.php on line 46
PHP Deprecated:  Return type of Pipedrive\Models\BaseNote::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/vendor/pipedrive/pipedrive/src/Models/BaseNote.php on line 195
PHP Deprecated:  Return type of Pipedrive\Models\Person::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/vendor/pipedrive/pipedrive/src/Models/Person.php on line 38
PHP Deprecated:  Return type of Pipedrive\Models\NoteCreatorUser::jsonSerialize() should either be compatible with JsonSerializable::jsonSerialize(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice in /var/www/vendor/pipedrive/pipedrive/src/Models/NoteCreatorUser.php on line 64

Invalid Request Body Parameter Type

I try run a example: updateTheProductAttachedToADeal

Request

`
$id = 27;
$collect['id'] = $id;

$productAttachmentId = 27;
$collect['productAttachmentId'] = $productAttachmentId;

$productId = 2;
$collect['productId'] = $productId;

$itemPrice = 27.9633801840075;
$collect['itemPrice'] = $itemPrice;

$quantity = 27;
$collect['quantity'] = $quantity;

$discountPercentage = 27.9633801840075;
$collect['discountPercentage'] = $discountPercentage;

$duration = 27.9633801840075;
$collect['duration'] = $duration;

$productVariationId = 27;
$collect['productVariationId'] = $productVariationId;

$comments = 'comments';
$collect['comments'] = $comments;

$enabledFlag = int::ENUM_0;
$collect['enabledFlag'] = $enabledFlag;

$result = $deals->updateTheProductAttachedToADeal($collect);
`

Response

`

+body: {#1694
+"success": false
+"error": "body/product_id must be integer, body/item_price must be number, body/quantity must be number, body/discount_percentage must be number, body/product_variation_id must be integer, body/product_variation_id must be null, body/product_variation_id must match a schema in anyOf, body/duration must be number
`

Not returning custom fields in version 6

Сustom fields are not returned when I use the getDeals()/getDeal()/getPersons()/getPerson() methods.
During debugging, I see custom fields in the response, but after deserialization, they don't get into the object.
In version 4, the fields are present.

CamelCaseHelper - empty response body causes `invalid argument supplied for foreach()`

Sometimes Pipedrive Api returns an empty body causing CamelCaseHelper to fail because response is not iterable.

Sadly, we do not know how to reproduce this at the moment.

/var/www/vendor/pipedrive/pipedrive/src/Utils/CamelCaseHelper.php:27 Invalid argument supplied for foreach()
/var/www/vendor/pipedrive/pipedrive/src/Utils/CamelCaseHelper.php in _exception_handler() at line 27
/var/www/vendor/pipedrive/pipedrive/src/Controllers/PersonsController.php in Pipedrive\Utils\CamelCaseHelper::keysToCamelCase() at line 233
/var/www/application/logic/pipedrive.php in Pipedrive\Controllers\PersonsController->searchPersons() at line 433

Wrong void return type

Currently all the method of all controllers have the return type hinting set to void.

This is wrong, as the real return type is \Pipedrive\Utils\JsonSerializer.

Using void breaks autocompletion in PHPStorm and breaks static code analyses.

EXPECTED BEHAVIOR

Return type hintings in Docblock comments should be \Pipedrive\Utils\JsonSerializer.

Example

    /**
     * Returns all organizations
     *
     * @param  array  $options    Array with all options for search
     * @param integer $options['userId']     (optional) If supplied, only organizations owned by the given user will be
     *                                       returned.
     * @param integer $options['filterId']   (optional) ID of the filter to use
     * @param string  $options['firstChar']  (optional) If supplied, only organizations whose name starts with the
     *                                       specified letter will be returned (case insensitive).
     * @param integer $options['start']      (optional) Pagination start
     * @param integer $options['limit']      (optional) Items shown per page
     * @param string  $options['sort']       (optional) Field names and sorting mode separated by a comma (field_name_1
     *                                       ASC, field_name_2 DESC). Only first-level field keys are supported (no
     *                                       nested keys).
-     * @return void response from the API call
+     * @return \Pipedrive\Utils\JsonSerializer response from the API call
     * @throws APIException Thrown if API call fails
     */
    public function getAllOrganizations(

Configuration.php loading incompletely

i use this "composer require pipedrive/pipedrive"
command and my Configuration.php loading incompletely
for example i didnt acces setApiKey() function.
Am I making a mistake while uploading?
(my Configuration.php row count 78 But there needs to be more rows)

Scope and URL mismatch

Hey guys,

Please help me!

I give this error:

Unirest\Response {#1172 +code: 403 +raw_body: "{"success":false,"error":"Scope and URL mismatch","errorCode":403}" +body: {#1181 +"success": false +"error": "Scope and URL mismatch" +"errorCode": 403 } +headers: array:21 [ 0 => "HTTP/1.1 403 Forbidden" "Date" => "Thu, 02 Jul 2020 18:00:31 GMT" "Content-Type" => "application/json" "Transfer-Encoding" => "chunked" "Connection" => "keep-alive" "Set-Cookie" => "__cfduid=d76208080a8f8cda75657cdf957e5528c1593712830; expires=Sat, 01-Aug-20 18:00:30 GMT; path=/; domain=.pipedrive.com; HttpOnly; SameSite=Lax" "x-correlation-id" => "4fcd6f7f-3b89-4568-891f-6f45382685fa" "badi" => "Routing: us-east-1=>us-east-1; Version: c2a6; Host: bari;" "Cache-Control" => "no-cache" "Access-Control-Expose-Headers" => "X-RateLimit-Remaining, X-RateLimit-Limit, X-RateLimit-Reset" "pdtrusted-wgw-real-user-ip" => "18.230.84.218" "X-XSS-Protection" => "1; mode=block" "X-Content-Type-Options" => "nosniff" "Strict-Transport-Security" => "max-age=31536000; includeSubDomains" "Content-Encoding" => "gzip" "CF-Cache-Status" => "DYNAMIC" "cf-request-id" => "03b24901c90000d01cda0ac200000001" "Expect-CT" => "max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct"" "Server" => "cloudflare" "CF-RAY" => "5aca44494bf9d01c-GRU" "alt-svc" => "h3-27=":443"; ma=86400, h3-28=":443"; ma=86400, h3-29=":443"; ma=86400" ]}

But in my account, i have permission on Call Logs, when i create new App.
Why this error ?

The method of the authentication is: OAuth

Request:

Method: POST
URL: https://api.pipedrive.com/v1/callLogs/7441/recordings
Parameters: ^ array:11 [
"user_id" => "11419111"
"activity_id" => null
"subject" => "asdfasdfasdfasdfadsf"
"from_phone_number" => null
"to_phone_number" => "41992512151"
"outcome" => "connected"
"start_time" => "2020-07-02 19:33:40"
"end_time" => "2020-07-02 19:33:40"
"deal_id" => null
"person_id" => "9865"
"org_id" => null
]

getAllDeals is not returning the custom fields

json mapper in getAllDeals is not returning the custom fields
return CamelCaseHelper::keysToCamelCase($mapper->mapClass($response->body, 'Pipedrive\\Models\\GetDeals'));

Better use this
return CamelCaseHelper::keysToCamelCase($response->body);

Return types of API responses are void

A lot of times the return type of API calls are void when they are returning an array of data. Could you please update them to a correct value?

E.g.:
@return void response from the API call
To:
@return mixed response from the API call
Or:
@return array response from the API call

Thanks in advance.

Using deprecated methods

I've just started a project using this library, and in general, it's done a good job, however, it seems a little out of date
https://developers.pipedrive.com/docs/api/v1

 Published: 8 April 2020

On 31 March 2021 we will remove the following endpoints:
    GET /deals/find
    GET /organizations/find
    GET /persons/find
    GET /products/find
    GET /searchResults
    GET /searchResults/field

All of these endpoints are in the library, and more importantly perhaps, their replacements are not. Is there a plan to update this to support the new methods?

unable to ad activity

it is not possible to use "addAnActivity" on "activity" controller. Ther is undefined variable in use "$due_date" on line 229

WebhooksController -> createANewWebhook

I get in response
{
"statusCode":415,
"code":"FST_ERR_CTP_INVALID_MEDIA_TYPE",
"error":"Unsupported Media Type",
"message":"Internal Server Error (2bac3f41-d80a-4377-b4f9-e55aecc19ba2)"
}

How to create a lead?

I don't see any controller related to leads. Could you let me know which is the controller for create/delete leads?

DealFieldsApi->getDealFields() fails with error 'Class 'FieldTypeAsString' not found'

Hi everyone,

I'm running pipedrive/pipedrive:5@beta and when using the getDealFields function on DealFieldsApi, it fails with 'Class 'FieldTypeAsString' not found'. My code is added below.

Other endpoints like POST deals is working perfectly.

Who has an idea what goes wrong?

        $apiKey = Environment::getEnv('PIPEDRIVE_API_KEY');
        $companyDomain = Environment::getEnv('PIPEDRIVE_COMPANY_DOMAIN');

        $host = str_replace('{{companyDomain}}', $companyDomain, 'https://{{companyDomain}}.pipedrive.com/v1');

        $this->configuration = (new Pipedrive\Configuration())
            ->setApiKey('api_token', $apiKey)
            ->setHost($host);

       $apiInstance = new Pipedrive\Api\DealFieldsApi(
            new GuzzleHttp\Client(),
            $this->configuration
        );

        try {
            $result = $apiInstance->getDealFields(0, 10);
            print_r($result);
        } catch (\Exception $e) {
            print_r('Exception when calling DealFieldsApi->getDealFields: ' . $e->getMessage());
        } 

phpunit does not run by README

Hi. I've tried running tests by README but it gives an error about missing api key. I guess it should work out of the box for tests run? 🤔

terminal: php71 vendor/bin/phpunit --verbose
PHPUnit 4.8.36 by Sebastian Bergmann and contributors.

Runtime:	PHP 7.1.31 with Xdebug 2.7.2
Configuration:	~/pipedrive/pipedrive/phpunit.xml

EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE

Time: 354 ms, Memory: 8.00MB

There were 42 errors:

1) Pipedrive\Tests\ActivitiesControllerTest::testTestGetAllActivitiesAssignedToAParticularUser
Exception: Client is not authorized. An OAuth token or an API token is needed to make API calls.

~/pipedrive/pipedrive/src/OAuthManager.php:150
~/pipedrive/pipedrive/src/Controllers/ActivitiesController.php:128
~/pipedrive/pipedrive/tests/Controllers/ActivitiesControllerTest.php:64

2) Pipedrive\Tests\ActivityFieldsControllerTest::testTestGetAllFieldsForAnActivity
Exception: Client is not authorized. An OAuth token or an API token is needed to make API calls.

~/pipedrive/pipedrive/src/OAuthManager.php:150
~/pipedrive/pipedrive/src/Controllers/ActivityFieldsController.php:56
~/pipedrive/pipedrive/tests/Controllers/ActivityFieldsControllerTest.php:53

...

DealsTimeline mapping error: JsonMapper::map requires first argument to be an object, array given.

InvalidArgumentException
JsonMapper::map() requires first argument to be an object, array given.
in vendor/apimatic/jsonmapper/src/JsonMapper.php:103

image

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.