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

Unable to Access Properties of DriveItem in DriveItemCollectionResponse Object #1636

Closed
huguesbert17 opened this issue Jan 11, 2025 · 1 comment
Assignees
Labels
type:question An issue that's a question

Comments

@huguesbert17
Copy link

huguesbert17 commented Jan 11, 2025

Issue Summary

When using the Microsoft Graph PHP SDK to retrieve items from a OneDrive directory, the DriveItemCollectionResponse and its nested DriveItem objects expose properties in the print_r() output. However, these properties cannot be accessed programmatically, making it impossible to extract data like name, createdBy, and other fields.

Steps to Reproduce

  1. Query OneDrive items using the SDK:

    $response = $graphClient->me()->drive()->items()->get();
    $items = $response->getValue();
    
    // Attempt to access properties
    foreach ($items as $item) {
        $name = $item->name; // Property does not exist or is inaccessible
        $createdBy = $item->createdBy; // Same issue
    }
  2. Inspect the object using print_r($response):

    • It shows that properties such as name and createdBy are present in the object structure.
  3. Try accessing these properties directly:

    $name = $item->getBackingStore()->get('name'); // Produces inconsistent results or null
  4. Attempt to convert the object to JSON or an array:

    function objectToArray($object) {
        if (is_object($object)) {
            $object = get_object_vars($object);
        }
        if (is_array($object)) {
            return array_map('objectToArray', $object);
        }
        return $object;
    }
    
    $data = objectToArray($response); // Results in null values

Expected Behavior

At a minimum, properties like name, createdBy, id, etc., should be accessible programmatically from the DriveItem objects within the DriveItemCollectionResponse.

Actual Behavior

  • DriveItem properties cannot be accessed programmatically even though they appear in the object structure when printed using print_r().
  • Converting the object to an array or JSON results in null values for most properties.

Workarounds Attempted

  1. Direct Access: Accessing properties like $item->name directly results in an error.
  2. Using Backing Store: The getBackingStore() method does not reliably return property values.
  3. Recursive Conversion: Converting the response to an array using custom functions results in null for properties.

Proposed Solution

  • Ensure all properties are accessible programmatically from DriveItem objects.
  • Add a built-in method to convert objects to arrays or JSON for easier integration with AJAX-based frontend applications.
  • Provide documentation with examples on how to access and use properties programmatically.

Environment

  • PHP Version: 8.4.2
  • SDK Version: 2.23

Additional Context

  • This issue significantly limits the usability of the SDK for modern applications.
  • Being unable to access properties programmatically or convert the response to JSON prevents integration with frontend frameworks like React.
  • If there is a specific intended way to access these properties, it should be explicitly documented.
@huguesbert17 huguesbert17 added status:waiting-for-triage An issue that is yet to be reviewed or assigned type:feature New experience request labels Jan 11, 2025
@Ndiritu Ndiritu self-assigned this Jan 13, 2025
@Ndiritu Ndiritu added type:question An issue that's a question and removed status:waiting-for-triage An issue that is yet to be reviewed or assigned type:feature New experience request labels Jan 13, 2025
@Ndiritu
Copy link
Contributor

Ndiritu commented Jan 13, 2025

@huguesbert17 thank you for reaching out.

The properties are accessible via getters. In the sample provided, getName(), getCreatedBy()

@Ndiritu Ndiritu closed this as completed Jan 13, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type:question An issue that's a question
Projects
None yet
Development

No branches or pull requests

2 participants