Reputation: 435
Given a file name, and the id of a folder, is there a resource url that I can use to see if the file exists in the folder? Something like /me/drive/items/{parent-id}/{name} seems logical.
Right now I am doing /me/drive/items/{parent-id}/children and searching through the resulting array which work. But hey.
thanks
Upvotes: 3
Views: 3501
Reputation: 758
The following queries work with the Graph Explorer without any authentication. In the demo data provided by Microsoft, there is a file with the name 'Sales by Category.xlsx' within a subfolder 'Business Data'. Here are options to check, if that file exists:
GET:
https://graph.microsoft.com/v1.0/me/drive/root/search(q='Sales by Category.xlsx')
GET:
https://graph.microsoft.com/v1.0/me/drive/items/01BYE5RZ5MYLM2SMX75ZBIPQZIHT6OAYPB/search(q='Sales by Category.xlsx')
GET:
https://graph.microsoft.com/v1.0/me/drive/root:/Business%20Data:/search(q='Sales by Category.xlsx')
GET:
https://graph.microsoft.com/v1.0/me/drive/root:/Business%20Data/Sales%20by%20Category.xlsx
If you want to search only within a specific subfolder of a folder, you need to specify the folder prior to the search expression by using either the item id notation, the relative path or a combination of both. Subfolders are searched by default. Option 4 is intuitive and seems to be faster, but it will throw a 404 error, if the item is not found. The Azure Admin may not like this, since this should show up in their logs. The search options will not throw an error and only return an empty result. So, searching may be better.
Upvotes: 2