AlexaCRM / dynamics-webapi-toolkit

Dynamics 365 Web API Toolkit for PHP
MIT License
75 stars 58 forks source link

QueryByAttribute not working. #72

Closed tnakazawa closed 2 years ago

tnakazawa commented 2 years ago

Im using PHP Version 7.3.25 dynamics-webapi-toolkit Installed by composer.

This code return cURL error No.3.

Code

$settings = new \AlexaCRM\WebAPI\OData\OnlineSettings();
$settings->instanceURI = $this->instanceURI;
$settings->applicationID = $this->applicationID;
$settings->tenantID = $this->tenantID;
$settings->applicationSecret = $this->applicationSecret;
$settings->apiVersion = $this->apiVersion;
$settings->tlsVerifyPeers = false;
$middleware = new \AlexaCRM\WebAPI\OData\OnlineAuthMiddleware( $settings );
$odataClient = new \AlexaCRM\WebAPI\OData\Client( $settings, $middleware);
$client = new \AlexaCRM\WebAPI\Client( $odataClient );

$query = new \AlexaCRM\Xrm\Query\QueryByAttribute( 'contact' );
$query->ColumnSet = new \AlexaCRM\Xrm\ColumnSet( true );
$collection = $client->RetrieveMultiple( $query );

return $collection;

Error

Error: [AlexaCRM\WebAPI\ToolkitException] cURL error 3: <url> malformed (see https://curl.haxx.se/libcurl/c/libcurl-errors.html)

Please tell me how to fix this problem.

georged commented 2 years ago

@tnakazawa as per https://github.com/AlexaCRM/dynamics-webapi-toolkit/#prerequisites: minimum supported PHP version is 7.4

tnakazawa commented 2 years ago

@georged thank you for your massage. I upgrade PHP Version 7.4.13, but this problem is not fix. same error reporting.

georged commented 2 years ago

@tnakazawa please provide full sample code including composer.json file the following code works in our tests.

<?php
require_once 'vendor/autoload.php';

$settings = new \AlexaCRM\WebAPI\OData\OnlineSettings();
$settings->instanceURI = 'https://yourinstance.crmX.dynamics.com';
$settings->applicationID = '<guid>';
$settings->applicationSecret = '<secret>';
$settings->tlsVerifyPeers = false;
$middleware = new \AlexaCRM\WebAPI\OData\OnlineAuthMiddleware( $settings );
$odataClient = new \AlexaCRM\WebAPI\OData\Client( $settings, $middleware);
$client = new \AlexaCRM\WebAPI\Client( $odataClient );
$query = new \AlexaCRM\Xrm\Query\QueryByAttribute( 'contact' );
$query->ColumnSet = new \AlexaCRM\Xrm\ColumnSet( [ 'fullname', 'emailaddress1' ] );
$collection = $client->RetrieveMultiple( $query );
foreach($collection as $c) {
  echo "{$c['fullname']}, {$c['emailaddress1']}\r\n";
}

composer.json

{
    "require": {
        "php": "^7.4",
        "alexacrm/dynamics-webapi-toolkit": "^2.6"
    }
}
tnakazawa commented 2 years ago

@georged Thank you & Im sorry.

I rewrite composer.json. "alexacrm/dynamics-webapi-toolkit": "^2.6"

Exec this command.

rm -rf vendor
composer update

This problem is fixed.