AlexaCRM / php-crm-toolkit

Dynamics CRM Toolkit for PHP
GNU Lesser General Public License v3.0
107 stars 42 forks source link

Does this library work with CRM Dynamics 2015? #79

Closed Artemy-Matvienko closed 5 years ago

Artemy-Matvienko commented 5 years ago

I found this issue that seems to mention the 2015 version, yet I can't seem to get it to work. Here's the code:

require_once __DIR__.'/../../includes/config.php';
require_once VENDOR_DIR.'/autoload.php';

use AlexaCRM\CRMToolkit\Client as OrganizationService;
use AlexaCRM\CRMToolkit\Settings;

$contactid = 'B07B01DA-059E-E711-8112-005056A76201';

$options = [
    'serverUrl' => 'https://dev.<org>:<port>/XrmServices/2011/Discovery.svc',
    'username' => '<username>@<org>.com',
    'password' => '<password>',
    'authMode' => 'Federation',
];

$serviceSettings = new Settings( $options );
$service = new OrganizationService( $serviceSettings );

$contact = $service->entity( 'contact', $contactid );
echo "{$contact->fullname}" . PHP_EOL;

The code prints nothing and there are warning in the php error log.

[18-Mar-2019 10:20:00 Canada/Eastern] PHP Warning:  Invalid argument supplied for foreach() in /var/www/html/Sources/vendor/alexacrm/php-crm-toolkit/src/Entity.php on line 103
[18-Mar-2019 10:20:00 Canada/Eastern] PHP Stack trace:
[18-Mar-2019 10:20:00 Canada/Eastern] PHP   1. {main}() /var/www/html/Sources/src/scripts/test/update_test_alexa.php:0
[18-Mar-2019 10:20:00 Canada/Eastern] PHP   2. AlexaCRM\CRMToolkit\Client->entity() /var/www/html/Sources/src/scripts/test/update_test_alexa.php:27
[18-Mar-2019 10:20:00 Canada/Eastern] PHP   3. AlexaCRM\CRMToolkit\Entity->__construct() /var/www/html/Sources/vendor/alexacrm/php-crm-toolkit/src/Client.php:957
[18-Mar-2019 10:20:00 Canada/Eastern] PHP Warning:  array_key_exists() expects parameter 2 to be array, null given in /var/www/html/Sources/vendor/alexacrm/php-crm-toolkit/src/Entity.php on line 209
[18-Mar-2019 10:20:00 Canada/Eastern] PHP Stack trace:
[18-Mar-2019 10:20:00 Canada/Eastern] PHP   1. {main}() /var/www/html/Sources/src/scripts/test/update_test_alexa.php:0
[18-Mar-2019 10:20:00 Canada/Eastern] PHP   2. AlexaCRM\CRMToolkit\Entity->__get() /var/www/html/Sources/src/scripts/test/update_test_alexa.php:28
[18-Mar-2019 10:20:00 Canada/Eastern] PHP   3. array_key_exists() /var/www/html/Sources/vendor/alexacrm/php-crm-toolkit/src/Entity.php:209
[18-Mar-2019 10:20:00 Canada/Eastern] PHP Warning:  array_key_exists() expects parameter 2 to be array, null given in /var/www/html/Sources/vendor/alexacrm/php-crm-toolkit/src/Entity.php on line 217
[18-Mar-2019 10:20:00 Canada/Eastern] PHP Stack trace:
[18-Mar-2019 10:20:00 Canada/Eastern] PHP   1. {main}() /var/www/html/Sources/src/scripts/test/update_test_alexa.php:0
[18-Mar-2019 10:20:00 Canada/Eastern] PHP   2. AlexaCRM\CRMToolkit\Entity->__get() /var/www/html/Sources/src/scripts/test/update_test_alexa.php:28
[18-Mar-2019 10:20:00 Canada/Eastern] PHP   3. array_key_exists() /var/www/html/Sources/vendor/alexacrm/php-crm-toolkit/src/Entity.php:217
[18-Mar-2019 10:20:00 Canada/Eastern] PHP Warning:  array_key_exists() expects parameter 2 to be array, null given in /var/www/html/Sources/vendor/alexacrm/php-crm-toolkit/src/Entity.php on line 209
[18-Mar-2019 10:20:00 Canada/Eastern] PHP Stack trace:
[18-Mar-2019 10:20:00 Canada/Eastern] PHP   1. {main}() /var/www/html/Sources/src/scripts/test/update_test_alexa.php:0
[18-Mar-2019 10:20:00 Canada/Eastern] PHP   2. AlexaCRM\CRMToolkit\Entity->__get() /var/www/html/Sources/src/scripts/test/update_test_alexa.php:28
[18-Mar-2019 10:20:00 Canada/Eastern] PHP   3. array_key_exists() /var/www/html/Sources/vendor/alexacrm/php-crm-toolkit/src/Entity.php:209
[18-Mar-2019 10:20:00 Canada/Eastern] PHP Warning:  array_key_exists() expects parameter 2 to be array, null given in /var/www/html/Sources/vendor/alexacrm/php-crm-toolkit/src/Entity.php on line 217
[18-Mar-2019 10:20:00 Canada/Eastern] PHP Stack trace:
[18-Mar-2019 10:20:00 Canada/Eastern] PHP   1. {main}() /var/www/html/Sources/src/scripts/test/update_test_alexa.php:0
[18-Mar-2019 10:20:00 Canada/Eastern] PHP   2. AlexaCRM\CRMToolkit\Entity->__get() /var/www/html/Sources/src/scripts/test/update_test_alexa.php:28
[18-Mar-2019 10:20:00 Canada/Eastern] PHP   3. array_key_exists() /var/www/html/Sources/vendor/alexacrm/php-crm-toolkit/src/Entity.php:217
georged commented 5 years ago

@Artemy-Matvienko

serverUrl in settings does not need to be a discovery service url - we figure that out. As per the example in readme, just try

$options = [
    'serverUrl' => 'https://dev.<org>:<port>',
    'username' => '<username>@<org>.com',
    'password' => '<password>',
    'authMode' => 'Federation',
];
Artemy-Matvienko commented 5 years ago

https://<org>.<domain>:<port> format did indeed work. Thanks!