Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
thomasa00 opened this issue Sep 21, 2022 · 5 comments

Comments

@thomasa00
Copy link

thomasa00 commented Sep 21, 2022

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
Copy link
Author

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

bcmetadata.zip

Any idea?

@ArneAmeye
Copy link

ArneAmeye commented Mar 1, 2023

@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
Copy link

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

@ArneAmeye
Copy link

@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
Copy link

@ArneAmeye ok cool, did the same thing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants