CoolRunner-dk / business-central-php

SDK for Microsoft Business Central
MIT License
11 stars 13 forks source link

Call to a member function getEntityType() on null in vendor\coolrunner\business-central-sdk\src\EntityCollection.php:59 #17

Open thomasa00 opened 1 year ago

thomasa00 commented 1 year ago

Hi, I'm getting the error Call to a member function getEntityType() on null when I try to do any query. It seems the problem starts in `EntityCollection.ph , line 77:

$this->type        = $this->query->getEntitySet($response['@odata.context']);

$response['@odata.context'] has a valid content: https://api.businesscentral.dynamics.com/v2.0/myTenant/sandbox/ODataV4/$metadata#Company

$response looks good as well (array of value is there; 1 element in it, with Name, Display_Name, Id, ...

But $this->query->getEntitySet returns null

Complete usage of SDK:

$sdk = \BusinessCentral\SDK::instance($myTenant, [
    // OAuth2 [Required]
    'client_id' => $myClientId,

    // Basic auth token [Required]
    'client_secret'    => $mySecret,

    // Default collection size [Optional]
    // Amount of entities to load initially and per page per collection
    // Can be changed on the fly on any collection instance
    'default_collection_size' => 20,

    // Default environment [Optional - 'production' by default]
    'environment' => 'sandbox',
]);

$company = $sdk->company('company');

At creating the instance some warnings will come - maybe this is the reason?

Warning: Undefined array key "@attributes" in \vendor\coolrunner\business-central-sdk\src\Schema.php on line 40

Warning: Trying to access array offset on value of type null in \vendor\coolrunner\business-central-sdk\src\Schema.php on line 40

Warning: Undefined array key "@attributes" in \vendor\coolrunner\business-central-sdk\src\Schema.php on line 40

Warning: Trying to access array offset on value of type null in \vendor\coolrunner\business-central-sdk\src\Schema.php on line 40

Warning: Undefined array key "Namespace" in \vendor\coolrunner\business-central-sdk\src\Schema.php on line 40

Warning: Undefined array key "@attributes" in \vendor\coolrunner\business-central-sdk\src\Schema.php on line 40

Warning: Trying to access array offset on value of type null in \vendor\coolrunner\business-central-sdk\src\Schema.php on line 40

Warning: Undefined array key "Namespace" in \vendor\coolrunner\business-central-sdk\src\Schema.php on line 40

Warning: Undefined array key "@attributes" in \vendor\coolrunner\business-central-sdk\src\Schema.php on line 40

Warning: Trying to access array offset on value of type null in \vendor\coolrunner\business-central-sdk\src\Schema.php on line 40

Warning: Undefined array key "NAV.ComplexTypes" in \vendor\coolrunner\business-central-sdk\src\Schema.php on line 55

Warning: Trying to access array offset on value of type null in \vendor\coolrunner\business-central-sdk\src\Schema.php on line 55

Warning: foreach() argument must be of type array|object, null given in \vendor\coolrunner\business-central-sdk\src\Schema.php on line 55

Warning: Undefined array key "NAV" in \vendor\coolrunner\business-central-sdk\src\Schema.php on line 59

Warning: Trying to access array offset on value of type null in \vendor\coolrunner\business-central-sdk\src\Schema.php on line 59

Warning: foreach() argument must be of type array|object, null given in \vendor\coolrunner\business-central-sdk\src\Schema.php on line 59

Warning: Undefined array key "NAV" in \vendor\coolrunner\business-central-sdk\src\Schema.php on line 63

Warning: Trying to access array offset on value of type null in \vendor\coolrunner\business-central-sdk\src\Schema.php on line 63

Warning: Trying to access array offset on value of type null in \vendor\coolrunner\business-central-sdk\src\Schema.php on line 63

Warning: foreach() argument must be of type array|object, null given in \vendor\coolrunner\business-central-sdk\src\Schema.php on line 63

Warning: Undefined array key "NAV" in \vendor\coolrunner\business-central-sdk\src\Schema.php on line 67

Warning: Trying to access array offset on value of type null in \vendor\coolrunner\business-central-sdk\src\Schema.php on line 67

Warning: foreach() argument must be of type array|object, null given in \vendor\coolrunner\business-central-sdk\src\Schema.php on line 67

PHP Version: 8.1.6

thomasa00 commented 1 year ago

The problem seems to be, that the metadata can't be parsed correctly in Schema.php.

bcmetadata.zip

Any idea?

ArneAmeye commented 1 year ago

@thomasa00 Have you been able to solve this? we used this package recently for another project where it seems to work however for a new project it also gives me errors on the "@attributes" key in Schema.php Edit: we are on PHP 8.0 in both projects, so isn't necessarily the PHP version.

nicoladj77 commented 1 year ago

@ArneAmeye did you manage to get it working?I have the same issue.

ArneAmeye commented 1 year ago

@ArneAmeye did you manage to get it working?I have the same issue.

Nope, I ended up using the Http client by Laravel and a custom class to write my get and post calls depending on API routes provided by the external partner. The SDK is left unused for now...

nicoladj77 commented 1 year ago

@ArneAmeye ok cool, did the same thing