I’m currently working on a project that integrates with SharePoint Online, and I’m trying to search for a folder named “Documentos” in a specific SharePoint site using two different approaches: the Microsoft Graph API (msgraph package) and the SharePoint REST API (vgrem/phpSPO package).
I’ve been able to authenticate successfully with both APIs, but I’m struggling to find the correct way to search for this folder and list its contents.
What I’ve Tried:
**Microsoft Graph API (**msgraph package):
I can successfully get an access token and retrieve data from other endpoints.
I'm using the endpoint:
[“https://graph.microsoft.com/v1.0/sites/{site-id}/drives/{drive-id}/root:/Documentos:/children”]
However, I either get an error or the folder contents don’t appear. I’m unsure if I’m using the correct drive ID or if the folder path is wrong.
**SharePoint REST API (**vgrem/phpSPO package):
I’ve successfully authenticated and can access the SharePoint site.
I’m using this method to try and retrieve the folder:
$folder = $ctx->getWeb()->getFolderByServerRelativeUrl(‘/sites/{site-name}/Documentos’);
$ctx->load($folder);
$ctx->executeQuery();
But I’m getting an error, or the folder isn’t found, even though it exists in SharePoint.
If I use $ctx->load($folder);, I get an error saying the token type is not valid. However, if I just use $folder = $ctx->getWeb()->getFolderByServerRelativeUrl('/sites/{site-name}/Documentos'); and call $ctx->executeQuery();, it runs but doesn’t return any results.
I’ve tried using $folder->getFiles() and $folder->getFiles()->getAll(), but both return nothing.
My Environment:
PHP version: 8.3.3
Microsoft Graph API: msgraph package
SharePoint REST API: vgrem/phpSPO package
Folder Name: "Documentos" (also known as "Documentos Partilhados" in some places)
What I Need Help With:
Microsoft Graph API: How can I properly search for and retrieve the "Documentos" folder using the Graph API? Am I using the correct endpoint?
SharePoint REST API (vgrem/phpSPO): How do I correctly reference the folder path in the SharePoint REST API?
Any insights or suggestions would be greatly appreciated! Thanks in advance!
Sergui Sergio is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.
1