Skip to content

Impossible to retrieve any items #339

@Tadaz

Description

@Tadaz

I am using the latest version of 3.1.1 and SharePoint online.

The only working snippet I got using this library is below - I can retrieve the root list of lists, any other command returns an empty list.

$credentials = new \Office365\Runtime\Auth\UserCredentials("USERNAME", "PASSWORD");
$ctx = (new \Office365\SharePoint\ClientContext("URL"))->withCredentials($credentials);

foreach ($ctx->getWeb()->getLists()->get()->executeQuery() as $list) {
    dump($list->getId() . ' ' . $list->getTitle());
}

I tweaked the code above to return all items from the Documents list but it always returns an empty list.

$credentials = new \Office365\Runtime\Auth\UserCredentials("USERNAME", "PASSWORD");
$ctx = (new \Office365\SharePoint\ClientContext("URL"))->withCredentials($credentials);

foreach ($ctx->getWeb()->getLists()->get()->executeQuery() as $list) {
    if($list->getTitle() === 'Documents') {
        $listItems = $list->getItems()->get()->executeQuery();
    
        //RETURNS EMPTY LIST OF ITEMS
        foreach ($listItems as $item){
            dump($item->getTitle());
        }
    }
}

I tried other different ways as well, e.g.

$credentials = new \Office365\Runtime\Auth\UserCredentials("USERNAME", "PASSWORD");
$ctx = (new \Office365\SharePoint\ClientContext("URL"))->withCredentials($credentials);

$list = $ctx->getWeb()->getList("Shared Documents")->executeQuery();
$listItems = $list->getItems()->get()->executeQuery();

//SAME ISSUE, THE LIST IS EMPTY
foreach ($listItems as $item){
    dump($item->getTitle());
}

I have read and edit permissions for the whole project.

Any suggestions?

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions