Open Sam-Othman opened 3 years ago
I have found that this also works in the API Explorer but unsure which class to use as it returns an empty array when using the Site class as per my last snippet:
/sites/{site-id}/lists/{list-id}/items?$expand=fields
Any help would be greatly appreciated.
Hello @Sam-Othman
You need to return a List not a Site object.
$list = $graph->createCollectionRequest("GET", "/sites/{site-id}/lists/{list-id}/?expand=columns,items(expand=columns)")
->setReturnType(Model\List::class)
->execute();
Let me know if that helps. If it doesn't, please reopen this issue. Thank you!
Hi @MIchaelMainer
Thanks for replying to me on this. I have tried to use the List Object however I am getting the below error:
PHP Parse error: syntax error, unexpected 'List' (T_LIST), expecting identifier (T_STRING) in D:\inetpub\wwroot\ithub-staging\resources\graph-get-list.php on line 11
I couldn't find a file named "List" within the Models folder, however I did find one called ListItems which I attempted and it ran successfully and populated the information regarding the list (column names and properties) however the 'Items' array was still empty. It works fine with the Graph Explorer so I believe I have the URL correct, I must just be doing something wrong when trying to do this via the SDK.
Hopefully this all makes sense!
Sam
Hi @MIchaelMainer,
Any chance I can get this issue reopened and looked into?
Thanks!
Sam
@Sam-Othman Thank you raising this some more. I just realized that we have to rename List to GraphList since List is keyword. Can you try the following:
$list = $graph->createCollectionRequest("GET", "/sites/{site-id}/lists/{list-id}/?expand=columns,items(expand=columns)")
->setReturnType(Model\GraphList::class)
->execute();
@MIchaelMainer Thank you for reopening this. When I do the above, I still get the full array for [columns] but only the below for [items]
[items@odata.context] => https://graph.microsoft.com/v1.0/$metadata#sites('91a780c5-5ffc-43dc-987f-f410ed137ed3')/lists('b05cc6af-9fb5-4223-9320-3d34bcb351e5')/items [items] => Array ( )
I think what's happening is that we don't support the embedded expansion in deserializing our models.
At this point, I think you'll need to either perform this in two calls like (I haven't tried this out and I'm not familiar with the endpoint):
$listwithcolumns = $graph->createCollectionRequest("GET", "/sites/{site-id}/lists/{list-id}/?expand=columns,items(expand=columns)")
->setReturnType(Model\GraphList::class)
->execute();
$listitemswith columns = $graph->createCollectionRequest("GET", "/sites/{site-id}/lists/{list-id}/items?expand=columns")
->setReturnType(Model\ListItem::class)
->execute();
Or
$response = $graph->createCollectionRequest("GET", "/sites/{site-id}/lists/{list-id}/?expand=columns,items(expand=columns)")
->execute();
$rawbody = $response->getRawBody();
/* Parse it out of the json */
Hi team,
I am a bit of a rookie but keen to see if this is an issue or if I am doing something wrong. I have searched everywhere but can't seem to find a solution so sorry if this is the wrong place to log this.
I am trying to read the data from a SharePoint list. It is working within the API explorer but not when I move it into PHP. In the API explorer I am hitting the below endpoint:
https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/?expand=columns,items(expand=columns)
When I do the below code in PHP it brings back the columns but the items are coming back in an empty array:
$list = $graph->createRequest("GET", "/sites/{site-id}/lists/{list-id}/?expand=columns,items(expand=columns)") ->setReturnType(Model\Site::class) ->execute();
Any help would be really appreciated!
Thanks
Sam AB#7976