Microsoft 365 – Graph Explorer – How to find specific extension files in my drive (onedrive) – how to get ID of specific file from my drive

Microsoft - Graph Explorer - Query to get all excel files from my drive
Microsoft - Graph Explorer - Query to get all excel files from my drive

Hi All,

Greetings for the day!

We are exploring Microsoft Graph.

We have very good article series on Microsoft Graph. Kindly please have a look

Today sharing simple query – find useful so thought to share.

Use Case / Background :

  • I need to find my excel files which I uploaded / stored in my Onedrive
  • Get ID of specific file from Onedrive – for example if I need require to get worksheets of my excel then to use Graph API query I need the ID of excel file from my drive

Details :

  • Initial thought was to write PowerShell and get the report – which I’ll cover in next upcoming article – of course this we will require when we have large number of files in our drive
  • But then I have few excels in my drive so thought to use GRAPH Explorer

Scenario 1 – Get all the excel files from my drive

Following are the excel files in my drive

fig : Onedrive - all available excel files
fig : Onedrive – all available excel files

Query :

https://graph.microsoft.com/v1.0/me/drive/root/search(q='.xlsx')?select=name,id,webUrl

Response :

"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)",
    "@microsoft.graph.tips": "Use $select to choose only the properties your app needs, as this can lead to performance improvements. For example: GET me/drive/root/microsoft.graph.search(q=<key>)?$select=audio,bundle",
    "value": [
        {
            "@odata.type": "#microsoft.graph.driveItem",
            "id": "01BGY4JJ34EISW27UVXRF3WOF3FEDEBOF6",
            "name": "Book.xlsx",
            "webUrl": "https://knowledgejunction1-my.sharepoint.com/personal/prasham_knowledgejunction1_onmicrosoft_com/_layouts/15/Doc.aspx?sourcedoc=%7B6D25227C-957E-4BBC-BB38-BB290640B8BE%7D&file=Book.xlsx&action=default&mobileredirect=true&DefaultItemOpen=1"
        }
    ]
}

Microsoft - Graph Explorer - Query to get all excel files from my drive
fig : Microsoft – Graph Explorer – Query to get all excel files from my drive

Here, we have one excel available so one record only

Scenario 2 – Get all the presentations from my drive

Following image shows all the presentations in my drive

fig : Onedrive - all available presentation files
fig : Onedrive – all available presentation files

Query :

https://graph.microsoft.com/v1.0/me/drive/root/search(q='.pptx') 

Response:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(driveItem)",
    "@microsoft.graph.tips": "Use $select to choose only the properties your app needs, as this can lead to performance improvements. For example: GET me/drive/root/microsoft.graph.search(q=<key>)?$select=audio,bundle",
    "value": [
        {
            "@odata.type": "#microsoft.graph.driveItem",
            "createdDateTime": "2020-04-25T09:54:13Z",
            "id": "01BGY4JJYEGD552R6LCFDJUQWDN3QI5WJF",
            "lastModifiedDateTime": "2020-04-25T09:55:46Z",
            "name": "Power Platform.pptx",
            "webUrl": "https://knowledgejunction1-my.sharepoint.com/personal/prasham_knowledgejunction1_onmicrosoft_com/_layouts/15/Doc.aspx?sourcedoc=%7BDDFB3004-CB47-4611-9A42-C36EE08ED925%7D&file=Power%20Platform.pptx&action=edit&mobileredirect=true&DefaultItemOpen=1",
            "size": 365529,
            "createdBy": {
                "user": {
                    "email": "prasham@knowledgejunction1.onmicrosoft.com",
                    "displayName": "Prasham Sabadra"
                }
            },
            "lastModifiedBy": {
                "user": {
                    "email": "prasham@knowledgejunction1.onmicrosoft.com",
                    "displayName": "Prasham Sabadra"
                }
            },
            "parentReference": {
                "driveType": "business",
                "driveId": "b!9_YyU-7_sE-dJ7aOJl59tD7be5VdGtpKopNhNYykD8UdESepcV3BQ6LOUM0nrEkO",
                "id": "01BGY4JJYOJKRWBU6MARE2SKZDADKLJD5Z",
                "siteId": "5332f6f7-ffee-4fb0-9d27-b68e265e7db4"
            },
            "file": {
                "mimeType": "application/vnd.openxmlformats-officedocument.presentationml.presentation",
                "hashes": {}
            },
            "fileSystemInfo": {
                "createdDateTime": "2020-04-25T09:54:13Z",
                "lastModifiedDateTime": "2020-04-25T09:55:46Z"
            },
            "searchResult": {},
            "shared": {
                "scope": "users"
            }
        }

Microsoft - Graph Explorer - Query to get all presentation files from my drive
fig : Microsoft – Graph Explorer – Query to get all presentation files from my drive

Thanks for reading. HAVE a FANTASTIC LEARNING AHED ! LIFE IS BEAUTIFUL 🙂

Prasham Sabadra

LIFE IS VERY BEAUTIFUL. ENJOY THE WHOLE JOURNEY :) Founder of Microsoft 365 Junction, Speaker, Author, Learner, Developer, Passionate Techie. Certified Professional Workshop Facilitator / Public Speaker. Believe in knowledge sharing. Around 20+ years of total IT experience and 17+ years of experience in SharePoint and Microsoft 365 services Please feel free me to contact for any SharePoint / Microsoft 365 queries. I am also very much interested in behavioral (life changing) sessions like motivational speeches, Success, Goal Setting, About Life, How to live Life etc. My book - Microsoft 365 Power Shell hand book for Administrators and Beginners and 100 Power Shell Interview Questions - https://www.amazon.in/Microsoft-Administrators-Beginners-Interview-Questions/dp/9394901639/ref=tmm_pap_swatch_0?_encoding=UTF8&qid=1679029081&sr=8-11

You may also like...

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Discover more from Microsoft 365

Subscribe now to keep reading and get access to the full archive.

Continue reading