I am trying to fetch the @microsoft.graph.downloadUrl for items in a SharePoint list using a plain HTTP call to the Microsoft Graph API. However, the downloadUrl field is always returned as blank. Here is the HTTP request I am using:
GET https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items?expand=driveItem(select=id,contentType,@microsoft.graph.downloadUrl)&$top=900
When I try the same request using the Microsoft Graph SDK, the downloadUrl is correctly populated:
var listItemsResponse = await graphServiceClient.Sites[site.Id].Lists[documentList.Id].Items.GetAsync((requestConfiguration) =>
{
requestConfiguration.QueryParameters.Expand = new string[] { "driveItem" };
requestConfiguration.QueryParameters.Select = new string[] { "id", "contentType" };
requestConfiguration.QueryParameters.Top = 900;
});
bool hasDownloadUrl = driveItem.AdditionalData.TryGetValue("@microsoft.graph.downloadUrl", out object? downloadUrl);
Note that, @microsoft.graph.downloadUrl property won't be populated for SharePoint folders having content type as "Folder".
I have one SharePoint site having one folder and few files of different types as below:
When I ran HTTP request, @microsoft.graph.downloadUrl property is not populated for testfolder as it's ContentType
is "Folder" as below:
GET https://graph.microsoft.com/v1.0/sites/siteId/lists/listId/items?expand=driveItem(select=id,@microsoft.graph.downloadUrl)&$top=500
Response:
For remaining SharePoint files where ContentType
is "Document", @microsoft.graph.downloadUrl property will be populated in response like this:
GET https://graph.microsoft.com/v1.0/sites/siteId/lists/listId/items?expand=driveItem(select=id,@microsoft.graph.downloadUrl)&$top=500
Response:
From your screenshot, you are not getting downloadUrl for drive item having ContentType
as "Folder".