Microsoft Graph Http Request Item Not Found

Donald King 0 Reputation points
2024-12-13T17:08:48.07+00:00

Hi I am new to Microsoft graph and I set up a Http call to Microsoft Graph that was working previously with the endpoint:

"https://graph.microsoft.com/v1.0/drives/{driveId}/root:{relative-path-to-root}:/children"

This was previously returning the one file in the folder but I am now getting a Item Not Found error.

This is the Code I have setup for this:

 `client.DefaultRequestHeaders.TryAddWithoutValidation("Authorization", "Bearer " + accessToken);

var send = client.GetAsync(siteEndPoint).GetAwaiter().GetResult();
var sendContent = send.Content.ReadAsStringAsync().GetAwaiter().GetResult();
var site = JsonConvert.DeserializeObject<Site>(sendContent);

var driveEndpoint = $"https://graph.microsoft.com/v1.0/sites/{site.id}/drive";
var driveSend = client.GetAsync(driveEndpoint).GetAwaiter().GetResult();
var driveSendContent = driveSend.Content.ReadAsStringAsync().GetAwaiter().GetResult();
var drive = JsonConvert.DeserializeObject<Drive>(driveSendContent);

var driveId = drive.id;

var folderName = customerId.ToString() + "-" + name;
var itemEndpoint =     $"https://graph.microsoft.com/v1.0/drives/{driveId}/root:/Folder1/{folderName}/Folder2:/children";
var itemSend = client.GetAsync(itemEndpoint).GetAwaiter().GetResult();
var itemSendContent =     itemSend.Content.ReadAsStringAsync().GetAwaiter().GetResult();
var itemList = JsonConvert.DeserializeObject<Items>(itemSendContent);`

I am getting values for the site and the drive it is only the items that are causing an issue. Am I using the wrong endpoint here?

I have made the request as simple as possible by removing all the filters.

I have tried https://graph.microsoft.com/v1.0/drives/{driveId}/items/root/children as a test and this returns items without an issue.

I was expecting to see the files in Folder2

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,766 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
11,189 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Yakun Huang-MSFT 8,905 Reputation points Microsoft Vendor
    2024-12-16T02:54:42.27+00:00

    Hello Donald King,

    Thank you for reaching out to Microsoft Support!

    According to your problem description, we ran the same test on this endpoint, which worked well, and the test results are as follows:

    User's image

    Screenshot 2024-12-16 024946

    For the reason why you have this error, please check in the SharePoint site to see if the file structure has changed, the folder name has changed, and the file location has moved.

    You can also try https://graph.microsoft.com/v1.0/drives/{driveId}/root:/Folder1:/children to test whether files in Folder1 can be listed correctly.

    Hope this helps.

    If the answer is helpful, please click Accept Answer and kindly upvote it. If you have any further questions about this answer, please click Comment.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.