A customer recently asked me to build an automation which grabs a file from a SharePoint Online (SPO) document library to process it. Everything beyond the download-the-file part was easy, but because getting the file required using Graph API, and Graph API is half-baked and poorly documented. So it took way longer than it should to do something so simple. My pain, is your gain.

I am including all of the Graph API calls, and their payloads, so it’s exactly clear which IDs are the IDs that matter in each context. This was part of what made it more complex. I knew that I had to use the Drive syntax to get the files, but it wasn’t clear how to get the right IDs from SPO, or how much Site Graph API I should interleave with the Drive. Like a lot of things, once you figure it out, it’s fairly simple, although if Microsoft provided proper documentation it would have been easy from the beginning. Which is what I’m trying to fix here :).

There are a few approaches that will work, so I’m including each of them for giggles. Couple things to note. The URLs below are URI encoded. I’m assuming that you know what you’re doing when it comes to URLs. I am including the full JSON responses with the important bits highlighted so you can see what to use. This is a test site that I spun up, this isn’t production data, so I haven’t mangled any URLs for any reason.

  1. When working with SPO in Graph API the first step is always to get the site id from the site name. To do this, call the sites endpoint with the site name in the format FQDN:/pathtosite.

    e.g. https://graph.microsoft.com/v1.0/sites/x088d.sharepoint.com%3A%2Fsites%2Fppm

    This will return the basic meta data for the site including the id.

    {
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites/$entity",
    "createdDateTime": "2023-01-17T15:42:24.713Z",
    "description": "PPM",
    "id": "x088d.sharepoint.com,c0c4c5cf-a0da-4540-a9cc-97c905af185e,7df402d7-3234-4ee9-ab48-4bdecba102b4",
    "lastModifiedDateTime": "2023-07-19T21:28:23Z",
    "name": "PPM",
    "webUrl": "https://x088d.sharepoint.com/sites/PPM",
    "displayName": "PPM",
    "root": {},
    "siteCollection": {
    "hostname": "x088d.sharepoint.com"
    }
    }
    
  2. The next step is to get the ID of the SharePoint list item for the folder. If you want all of the documents in the library, don’t include the filter in the query. The long bit of gibberish after /sites/ is the id from step one.

    e.g. https://graph.microsoft.com/v1.0/sites/x088d.sharepoint.com,c0c4c5cf-a0da-4540-a9cc-97c905af185e,7df402d7-3234-4ee9-ab48-4bdecba102b4/lists/Report Documents/items?$filter=fields%2FFileLeafRef%20eq%20%27Usage%20Report%27&$expand=fields

    If you included the filter in the query to limit the result to just the folder you’re interested in, you will also need to add the Prefer:HonorNonIndexedQueriesWarningMayFailRandomly HTTP header to the GET request. Frankly, it is mind-blowing that Microsoft didn’t index FileLeafRef. It’s the the name/path of an item, it totally makes sense that developers would target that in a filter query, and AFAIK there isn’t a way to index it manually, so…

    {
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites(\u0027x088d.sharepoint.com%2Cc0c4c5cf-a0da-4540-a9cc-97c905af185e%2C7df402d7-3234-4ee9-ab48-4bdecba102b4\u0027)/lists(\u0027Report%20Documents\u0027)/items(fields())",
    "value": [
    {
    "@odata.etag": "\"9387b0d6-d97c-4387-a8c6-3109aefb4a38,1\"",
    "createdDateTime": "2023-07-20T13:06:52Z",
    "eTag": "\"9387b0d6-d97c-4387-a8c6-3109aefb4a38,1\"",
    "id": "6",
    "lastModifiedDateTime": "2023-07-20T13:06:52Z",
    "webUrl": "https://x088d.sharepoint.com/sites/PPM/Report%20Documents/A%20Folder",
    "createdBy": {
    "user": {
    "email": "andyvt@x088d.onmicrosoft.com",
    "id": "363db96a-c3df-42f7-b8c2-55d4e82c71bd",
    "displayName": "Andrew Van Til"
    }
    },
    "lastModifiedBy": {
    "user": {
    "email": "andyvt@x088d.onmicrosoft.com",
    "id": "363db96a-c3df-42f7-b8c2-55d4e82c71bd",
    "displayName": "Andrew Van Til"
    }
    },
    "parentReference": {
    "id": "8b457556-3b06-4a8c-a928-47edff8444d1",
    "siteId": "x088d.sharepoint.com,c0c4c5cf-a0da-4540-a9cc-97c905af185e,7df402d7-3234-4ee9-ab48-4bdecba102b4"
    },
    "contentType": {
    "id": "0x012000BA713D4B2B88D34DAE510394F00206ED",
    "name": "Folder"
    },
    "fields@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites(\u0027x088d.sharepoint.com%2Cc0c4c5cf-a0da-4540-a9cc-97c905af185e%2C7df402d7-3234-4ee9-ab48-4bdecba102b4\u0027)/lists(\u0027Report%20Documents\u0027)/items(\u00276\u0027)/fields/$entity",
    "fields": {
    "@odata.etag": "\"9387b0d6-d97c-4387-a8c6-3109aefb4a38,1\"",
    "id": "6",
    "ContentType": "Folder",
    "Created": "2023-07-20T13:06:52Z",
    "AuthorLookupId": "11",
    "Modified": "2023-07-20T13:06:52Z",
    "EditorLookupId": "11",
    "FileLeafRef": "A Folder",
    "_CheckinComment": "",
    "LinkFilenameNoMenu": "A Folder",
    "LinkFilename": "A Folder",
    "ItemChildCount": "3",
    "FolderChildCount": "0",
    "_ComplianceFlags": "",
    "_ComplianceTag": "",
    "_ComplianceTagWrittenTime": "",
    "_ComplianceTagUserId": "",
    "_CommentCount": "",
    "_LikeCount": "",
    "_DisplayName": "",
    "Edit": "0",
    "_UIVersionString": "1.0",
    "ParentVersionStringLookupId": "6",
    "ParentLeafNameLookupId": "6"
    }
    }
    ]
    }
    
  3. Now that we have the ID of the folder, we can get the driveItem entities for its contents.

    e.g. https://graph.microsoft.com/v1.0/sites/x088d.sharepoint.com,c0c4c5cf-a0da-4540-a9cc-97c905af185e,7df402d7-3234-4ee9-ab48-4bdecba102b4/lists/Report Documents/items/6/driveItem/children.

    We’re interested in the elements in the value array.

    {
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#sites(\u0027x088d.sharepoint.com%2Cc0c4c5cf-a0da-4540-a9cc-97c905af185e%2C7df402d7-3234-4ee9-ab48-4bdecba102b4\u0027)/lists(\u0027Report%20Documents\u0027)/items(\u00276\u0027)/driveItem/children",
    "value": [
    {
    "@microsoft.graph.downloadUrl": "https://x088d.sharepoint.com/sites/PPM/_layouts/15/download.aspx?UniqueId\u003dcb070682-6f1f-43cb-9021-4d7ac0126f55\u0026Translate\u003dfalse\u0026tempauth\u003deyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAveDA4OGQuc2hhcmVwb2ludC5jb21AOWQ2M2YwMjgtODJiNi00ZDhmLThkNmMtMmNiMGI5NjA1NWNjIiwiaXNzIjoiMDAwMDAwMDMtMDAwMC0wZmYxLWNlMDAtMDAwMDAwMDAwMDAwIiwibmJmIjoiMTY4OTg1ODU3NCIsImV4cCI6IjE2ODk4NjIxNzQiLCJlbmRwb2ludHVybCI6IldEVkJ1N01tN2tUZ3RyNWVNbTlBWmJGaGphbENTR0dsbU1acWJuTE9rVzQ9IiwiZW5kcG9pbnR1cmxMZW5ndGgiOiIxMjYiLCJpc2xvb3BiYWNrIjoiVHJ1ZSIsImNpZCI6IkpTNzA0NGtBdTB1ZURzc2Y2ZDFwaVE9PSIsInZlciI6Imhhc2hlZHByb29mdG9rZW4iLCJzaXRlaWQiOiJZekJqTkdNMVkyWXRZVEJrWVMwME5UUXdMV0U1WTJNdE9UZGpPVEExWVdZeE9EVmwiLCJhcHBfZGlzcGxheW5hbWUiOiJzcG9jcmVkIiwibmFtZWlkIjoiYTFkYjBlODktMmJiMy00M2VhLWIxMzQtMGYxYjBkNWEyY2Y5QDlkNjNmMDI4LTgyYjYtNGQ4Zi04ZDZjLTJjYjBiOTYwNTVjYyIsInJvbGVzIjoic2hhcmVwb2ludHRlbmFudHNldHRpbmdzLnJlYWR3cml0ZS5hbGwgc2hhcmVwb2ludHRlbmFudHNldHRpbmdzLnJlYWQuYWxsIGFsbHNpdGVzLm1hbmFnZSBhbGxmaWxlcy53cml0ZSBhbGxwcm9maWxlcy5yZWFkIiwidHQiOiIxIiwiaXBhZGRyIjoiNDAuMTI2LjI3LjI0In0.cR85ts3eAOKub2RTn0_cJ7Dh0SYDAKwWklIsYZtRU9Q\u0026ApiVersion\u003d2.0",
    "createdDateTime": "2023-07-20T13:09:02Z",
    "eTag": "\"{CB070682-6F1F-43CB-9021-4D7AC0126F55},1\"",
    "id": "0153PWWGMCAYD4WH3PZNBZAIKNPLABE32V",
    "lastModifiedDateTime": "2023-07-20T13:09:02Z",
    "name": "Nextcloud Flyer.pdf",
    "webUrl": "https://x088d.sharepoint.com/sites/PPM/Report%20Documents/A%20Folder/Nextcloud%20Flyer.pdf",
    "cTag": "\"c:{CB070682-6F1F-43CB-9021-4D7AC0126F55},1\"",
    "size": 2529331,
    "createdBy": {
    "user": {
    "email": "andyvt@x088d.onmicrosoft.com",
    "id": "363db96a-c3df-42f7-b8c2-55d4e82c71bd",
    "displayName": "Andrew Van Til"
    }
    },
    "lastModifiedBy": {
    "user": {
    "email": "andyvt@x088d.onmicrosoft.com",
    "id": "363db96a-c3df-42f7-b8c2-55d4e82c71bd",
    "displayName": "Andrew Van Til"
    }
    },
    "parentReference": {
    "driveType": "documentLibrary",
    "driveId": "b!z8XEwNqgQEWpzJfJBa8YXtcC9H00MulOq0hL3suhArTKx_sizIFISY41xTuOMsC0",
    "id": "0153PWWGOWWCDZG7GZQ5B2RRRRBGXPWSRY",
    "path": "/drives/b!z8XEwNqgQEWpzJfJBa8YXtcC9H00MulOq0hL3suhArTKx_sizIFISY41xTuOMsC0/root:/A Folder",
    "siteId": "c0c4c5cf-a0da-4540-a9cc-97c905af185e"
    },
    "file": {
    "mimeType": "application/pdf",
    "hashes": {
    "quickXorHash": "4EbgYW7Y2TkNOFcV2ljEn1erBZA\u003d"
    }
    },
    "fileSystemInfo": {
    "createdDateTime": "2023-07-20T13:09:02Z",
    "lastModifiedDateTime": "2023-07-20T13:09:02Z"
    },
    "shared": {
    "scope": "users"
    }
    },
    {
    "@microsoft.graph.downloadUrl": "https://x088d.sharepoint.com/sites/PPM/_layouts/15/download.aspx?UniqueId\u003d45e9b1a7-0fe6-47e7-b480-caf8f1167ef6\u0026Translate\u003dfalse\u0026tempauth\u003deyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAveDA4OGQuc2hhcmVwb2ludC5jb21AOWQ2M2YwMjgtODJiNi00ZDhmLThkNmMtMmNiMGI5NjA1NWNjIiwiaXNzIjoiMDAwMDAwMDMtMDAwMC0wZmYxLWNlMDAtMDAwMDAwMDAwMDAwIiwibmJmIjoiMTY4OTg1ODU3NCIsImV4cCI6IjE2ODk4NjIxNzQiLCJlbmRwb2ludHVybCI6Im9qVkczdGlBTmJlZ1JMeTdHMGFsWmNKM3pRQkdQTzk3ZE00SzV6bGFmbTg9IiwiZW5kcG9pbnR1cmxMZW5ndGgiOiIxMjYiLCJpc2xvb3BiYWNrIjoiVHJ1ZSIsImNpZCI6IkpTNzA0NGtBdTB1ZURzc2Y2ZDFwaVE9PSIsInZlciI6Imhhc2hlZHByb29mdG9rZW4iLCJzaXRlaWQiOiJZekJqTkdNMVkyWXRZVEJrWVMwME5UUXdMV0U1WTJNdE9UZGpPVEExWVdZeE9EVmwiLCJhcHBfZGlzcGxheW5hbWUiOiJzcG9jcmVkIiwibmFtZWlkIjoiYTFkYjBlODktMmJiMy00M2VhLWIxMzQtMGYxYjBkNWEyY2Y5QDlkNjNmMDI4LTgyYjYtNGQ4Zi04ZDZjLTJjYjBiOTYwNTVjYyIsInJvbGVzIjoic2hhcmVwb2ludHRlbmFudHNldHRpbmdzLnJlYWR3cml0ZS5hbGwgc2hhcmVwb2ludHRlbmFudHNldHRpbmdzLnJlYWQuYWxsIGFsbHNpdGVzLm1hbmFnZSBhbGxmaWxlcy53cml0ZSBhbGxwcm9maWxlcy5yZWFkIiwidHQiOiIxIiwiaXBhZGRyIjoiNDAuMTI2LjI3LjI0In0.KirrAMKoF9fYoKGFRQRG96CkR_o8PxKK7z7duKoHT9M\u0026ApiVersion\u003d2.0",
    "createdDateTime": "2023-07-20T13:09:01Z",
    "eTag": "\"{45E9B1A7-0FE6-47E7-B480-CAF8F1167EF6},1\"",
    "id": "0153PWWGNHWHUULZQP45D3JAGK7DYRM7XW",
    "lastModifiedDateTime": "2023-07-20T13:09:01Z",
    "name": "strava billing.png",
    "webUrl": "https://x088d.sharepoint.com/sites/PPM/Report%20Documents/A%20Folder/strava%20billing.png",
    "cTag": "\"c:{45E9B1A7-0FE6-47E7-B480-CAF8F1167EF6},2\"",
    "size": 111751,
    "createdBy": {
    "user": {
    "email": "andyvt@x088d.onmicrosoft.com",
    "id": "363db96a-c3df-42f7-b8c2-55d4e82c71bd",
    "displayName": "Andrew Van Til"
    }
    },
    "lastModifiedBy": {
    "user": {
    "email": "andyvt@x088d.onmicrosoft.com",
    "id": "363db96a-c3df-42f7-b8c2-55d4e82c71bd",
    "displayName": "Andrew Van Til"
    }
    },
    "parentReference": {
    "driveType": "documentLibrary",
    "driveId": "b!z8XEwNqgQEWpzJfJBa8YXtcC9H00MulOq0hL3suhArTKx_sizIFISY41xTuOMsC0",
    "id": "0153PWWGOWWCDZG7GZQ5B2RRRRBGXPWSRY",
    "path": "/drives/b!z8XEwNqgQEWpzJfJBa8YXtcC9H00MulOq0hL3suhArTKx_sizIFISY41xTuOMsC0/root:/A Folder",
    "siteId": "c0c4c5cf-a0da-4540-a9cc-97c905af185e"
    },
    "file": {
    "mimeType": "image/png",
    "hashes": {
    "quickXorHash": "SDmJl3R1/4DPqfH/Ix+lr9iykYU\u003d"
    }
    },
    "fileSystemInfo": {
    "createdDateTime": "2023-07-20T13:09:01Z",
    "lastModifiedDateTime": "2023-07-20T13:09:01Z"
    },
    "image": {},
    "shared": {
    "scope": "users"
    }
    },
    {
    "@microsoft.graph.downloadUrl": "https://x088d.sharepoint.com/sites/PPM/_layouts/15/download.aspx?UniqueId\u003d5b79bbc0-7f44-4a60-8408-a35a6969fcbb\u0026Translate\u003dfalse\u0026tempauth\u003deyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAveDA4OGQuc2hhcmVwb2ludC5jb21AOWQ2M2YwMjgtODJiNi00ZDhmLThkNmMtMmNiMGI5NjA1NWNjIiwiaXNzIjoiMDAwMDAwMDMtMDAwMC0wZmYxLWNlMDAtMDAwMDAwMDAwMDAwIiwibmJmIjoiMTY4OTg1ODU3NCIsImV4cCI6IjE2ODk4NjIxNzQiLCJlbmRwb2ludHVybCI6IjdGK3lpUWZrcEpCWXNic1pXUVhoTTI3K0d4V2hzNXBQTERXaG5LYWJYdGc9IiwiZW5kcG9pbnR1cmxMZW5ndGgiOiIxMjYiLCJpc2xvb3BiYWNrIjoiVHJ1ZSIsImNpZCI6IkpTNzA0NGtBdTB1ZURzc2Y2ZDFwaVE9PSIsInZlciI6Imhhc2hlZHByb29mdG9rZW4iLCJzaXRlaWQiOiJZekJqTkdNMVkyWXRZVEJrWVMwME5UUXdMV0U1WTJNdE9UZGpPVEExWVdZeE9EVmwiLCJhcHBfZGlzcGxheW5hbWUiOiJzcG9jcmVkIiwibmFtZWlkIjoiYTFkYjBlODktMmJiMy00M2VhLWIxMzQtMGYxYjBkNWEyY2Y5QDlkNjNmMDI4LTgyYjYtNGQ4Zi04ZDZjLTJjYjBiOTYwNTVjYyIsInJvbGVzIjoic2hhcmVwb2ludHRlbmFudHNldHRpbmdzLnJlYWR3cml0ZS5hbGwgc2hhcmVwb2ludHRlbmFudHNldHRpbmdzLnJlYWQuYWxsIGFsbHNpdGVzLm1hbmFnZSBhbGxmaWxlcy53cml0ZSBhbGxwcm9maWxlcy5yZWFkIiwidHQiOiIxIiwiaXBhZGRyIjoiNDAuMTI2LjI3LjI0In0.0IBaFTc7BmYUyQACASMFM1QCXXktEj5N08nF0e3DpZ8\u0026ApiVersion\u003d2.0",
    "createdDateTime": "2023-07-20T13:09:01Z",
    "eTag": "\"{5B79BBC0-7F44-4A60-8408-A35A6969FCBB},1\"",
    "id": "0153PWWGOAXN4VWRD7MBFIICFDLJUWT7F3",
    "lastModifiedDateTime": "2023-07-20T13:09:01Z",
    "name": "TireWidths.xlsx",
    "webUrl": "https://x088d.sharepoint.com/sites/PPM/_layouts/15/Doc.aspx?sourcedoc\u003d%7B5B79BBC0-7F44-4A60-8408-A35A6969FCBB%7D\u0026file\u003dTireWidths.xlsx\u0026action\u003ddefault\u0026mobileredirect\u003dtrue",
    "cTag": "\"c:{5B79BBC0-7F44-4A60-8408-A35A6969FCBB},2\"",
    "size": 17793,
    "createdBy": {
    "user": {
    "email": "andyvt@x088d.onmicrosoft.com",
    "id": "363db96a-c3df-42f7-b8c2-55d4e82c71bd",
    "displayName": "Andrew Van Til"
    }
    },
    "lastModifiedBy": {
    "user": {
    "email": "andyvt@x088d.onmicrosoft.com",
    "id": "363db96a-c3df-42f7-b8c2-55d4e82c71bd",
    "displayName": "Andrew Van Til"
    }
    },
    "parentReference": {
    "driveType": "documentLibrary",
    "driveId": "b!z8XEwNqgQEWpzJfJBa8YXtcC9H00MulOq0hL3suhArTKx_sizIFISY41xTuOMsC0",
    "id": "0153PWWGOWWCDZG7GZQ5B2RRRRBGXPWSRY",
    "path": "/drives/b!z8XEwNqgQEWpzJfJBa8YXtcC9H00MulOq0hL3suhArTKx_sizIFISY41xTuOMsC0/root:/A Folder",
    "siteId": "c0c4c5cf-a0da-4540-a9cc-97c905af185e"
    },
    "file": {
    "mimeType": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",
    "hashes": {
    "quickXorHash": "WbzG+Up6bogUkmJIBuG3D9Q6dwE\u003d"
    }
    },
    "fileSystemInfo": {
    "createdDateTime": "2023-07-20T13:09:01Z",
    "lastModifiedDateTime": "2023-07-20T13:09:01Z"
    },
    "shared": {
    "scope": "users"
    }
    }
    ]
    }
    
  4. We can now loop through the files in the folder. Choosing one of them (the middle just because), we want to grab a few values to provide the meta data that we’ll use to grab the file itself.
    {
    "eTag" : "\"{45E9B1A7-0FE6-47E7-B480-CAF8F1167EF6},1\"",
    "createdBy" : {
    "user" : {
    "email" : "andyvt@x088d.onmicrosoft.com",
    "id" : "363db96a-c3df-42f7-b8c2-55d4e82c71bd",
    "displayName" : "Andrew Van Til"
    }
    },
    "file" : {
    "mimeType" : "image/png",
    "hashes" : {
    "quickXorHash" : "SDmJl3R1/4DPqfH/Ix+lr9iykYU="
    }
    },
    "name" : "strava billing.png",
    "fileSystemInfo" : {
    "lastModifiedDateTime" : "2023-07-20T13:09:01Z",
    "createdDateTime" : "2023-07-20T13:09:01Z"
    },
    "image" : {},
    "size" : 111751,
    "cTag" : "\"c:{45E9B1A7-0FE6-47E7-B480-CAF8F1167EF6},2\"",
    "shared" : {
    "scope" : "users"
    },
    "lastModifiedBy" : {
    "user" : {
    "email" : "andyvt@x088d.onmicrosoft.com",
    "id" : "363db96a-c3df-42f7-b8c2-55d4e82c71bd",
    "displayName" : "Andrew Van Til"
    }
    },
    "@microsoft.graph.downloadUrl" : "https://x088d.sharepoint.com/sites/PPM/_layouts/15/download.aspx?UniqueId=45e9b1a7-0fe6-47e7-b480-caf8f1167ef6&Translate=false&tempauth=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAveDA4OGQuc2hhcmVwb2ludC5jb21AOWQ2M2YwMjgtODJiNi00ZDhmLThkNmMtMmNiMGI5NjA1NWNjIiwiaXNzIjoiMDAwMDAwMDMtMDAwMC0wZmYxLWNlMDAtMDAwMDAwMDAwMDAwIiwibmJmIjoiMTY4OTg1ODU3NCIsImV4cCI6IjE2ODk4NjIxNzQiLCJlbmRwb2ludHVybCI6Im9qVkczdGlBTmJlZ1JMeTdHMGFsWmNKM3pRQkdQTzk3ZE00SzV6bGFmbTg9IiwiZW5kcG9pbnR1cmxMZW5ndGgiOiIxMjYiLCJpc2xvb3BiYWNrIjoiVHJ1ZSIsImNpZCI6IkpTNzA0NGtBdTB1ZURzc2Y2ZDFwaVE9PSIsInZlciI6Imhhc2hlZHByb29mdG9rZW4iLCJzaXRlaWQiOiJZekJqTkdNMVkyWXRZVEJrWVMwME5UUXdMV0U1WTJNdE9UZGpPVEExWVdZeE9EVmwiLCJhcHBfZGlzcGxheW5hbWUiOiJzcG9jcmVkIiwibmFtZWlkIjoiYTFkYjBlODktMmJiMy00M2VhLWIxMzQtMGYxYjBkNWEyY2Y5QDlkNjNmMDI4LTgyYjYtNGQ4Zi04ZDZjLTJjYjBiOTYwNTVjYyIsInJvbGVzIjoic2hhcmVwb2ludHRlbmFudHNldHRpbmdzLnJlYWR3cml0ZS5hbGwgc2hhcmVwb2ludHRlbmFudHNldHRpbmdzLnJlYWQuYWxsIGFsbHNpdGVzLm1hbmFnZSBhbGxmaWxlcy53cml0ZSBhbGxwcm9maWxlcy5yZWFkIiwidHQiOiIxIiwiaXBhZGRyIjoiNDAuMTI2LjI3LjI0In0.KirrAMKoF9fYoKGFRQRG96CkR_o8PxKK7z7duKoHT9M&ApiVersion=2.0",
    "parentReference" : {
    "driveId" : "b!z8XEwNqgQEWpzJfJBa8YXtcC9H00MulOq0hL3suhArTKx_sizIFISY41xTuOMsC0",
    "siteId" : "c0c4c5cf-a0da-4540-a9cc-97c905af185e",
    "driveType" : "documentLibrary",
    "path" : "/drives/b!z8XEwNqgQEWpzJfJBa8YXtcC9H00MulOq0hL3suhArTKx_sizIFISY41xTuOMsC0/root:/A Folder",
    "id" : "0153PWWGOWWCDZG7GZQ5B2RRRRBGXPWSRY"
    },
    "createdDateTime" : "2023-07-20T13:09:01Z",
    "id" : "0153PWWGNHWHUULZQP45D3JAGK7DYRM7XW",
    "lastModifiedDateTime" : "2023-07-20T13:09:01Z",
    "webUrl" : "https://x088d.sharepoint.com/sites/PPM/Report%20Documents/A%20Folder/strava%20billing.png"
    }
    

    The three methods that we can use are:

    1. By File Name: This uses the driveId (36) of the parent [folder] and name (16) properties to build the GET request path.
      e.g. https://graph.microsoft.com/v1.0/sites/x088d.sharepoint.com,c0c4c5cf-a0da-4540-a9cc-97c905af185e,7df402d7-3234-4ee9-ab48-4bdecba102b4/drives/b!z8XEwNqgQEWpzJfJBa8YXtcC9H00MulOq0hL3suhArTKx_sizIFISY41xTuOMsC0/root:/A Folder/strava billing.png:/content
    2. By Drive Id: This uses the driveId (36) of the parent [folder] and id (43) properties to build the GET request path. This is functionally equivalent with option 1, but it’s my preferred approach. Using an ID value removes any potential weirdness that might happen when URI encoding a file name. I don’t expect that to be a major concern, but why make it harder than it needs to be?

      e.g. https://graph.microsoft.com/v1.0/sites/x088d.sharepoint.com,c0c4c5cf-a0da-4540-a9cc-97c905af185e,7df402d7-3234-4ee9-ab48-4bdecba102b4/drives/b!z8XEwNqgQEWpzJfJBa8YXtcC9H00MulOq0hL3suhArTKx_sizIFISY41xTuOMsC0/items/0153PWWGNHWHUULZQP45D3JAGK7DYRM7XW/content

    3. By Download Url:  This is the value of @microsoft.graph.downloadUrl (34). This is an interesting one because it encodes a time limited access token into the URI query, so it’s the better option for use cases where the URL will be shared, or embedded in the UI of an app that doesn’t have access to valid credentials. I don’t know how long the token is valid, it’s not very long. So something to keep in mind.

      e.g. https://x088d.sharepoint.com/sites/PPM/_layouts/15/download.aspx?UniqueId=45e9b1a7-0fe6-47e7-b480-caf8f1167ef6&Translate=false&tempauth=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJhdWQiOiIwMDAwMDAwMy0wMDAwLTBmZjEtY2UwMC0wMDAwMDAwMDAwMDAveDA4OGQuc2hhcmVwb2ludC5jb21AOWQ2M2YwMjgtODJiNi00ZDhmLThkNmMtMmNiMGI5NjA1NWNjIiwiaXNzIjoiMDAwMDAwMDMtMDAwMC0wZmYxLWNlMDAtMDAwMDAwMDAwMDAwIiwibmJmIjoiMTY4OTg1ODU3NCIsImV4cCI6IjE2ODk4NjIxNzQiLCJlbmRwb2ludHVybCI6Im9qVkczdGlBTmJlZ1JMeTdHMGFsWmNKM3pRQkdQTzk3ZE00SzV6bGFmbTg9IiwiZW5kcG9pbnR1cmxMZW5ndGgiOiIxMjYiLCJpc2xvb3BiYWNrIjoiVHJ1ZSIsImNpZCI6IkpTNzA0NGtBdTB1ZURzc2Y2ZDFwaVE9PSIsInZlciI6Imhhc2hlZHByb29mdG9rZW4iLCJzaXRlaWQiOiJZekJqTkdNMVkyWXRZVEJrWVMwME5UUXdMV0U1WTJNdE9UZGpPVEExWVdZeE9EVmwiLCJhcHBfZGlzcGxheW5hbWUiOiJzcG9jcmVkIiwibmFtZWlkIjoiYTFkYjBlODktMmJiMy00M2VhLWIxMzQtMGYxYjBkNWEyY2Y5QDlkNjNmMDI4LTgyYjYtNGQ4Zi04ZDZjLTJjYjBiOTYwNTVjYyIsInJvbGVzIjoic2hhcmVwb2ludHRlbmFudHNldHRpbmdzLnJlYWR3cml0ZS5hbGwgc2hhcmVwb2ludHRlbmFudHNldHRpbmdzLnJlYWQuYWxsIGFsbHNpdGVzLm1hbmFnZSBhbGxmaWxlcy53cml0ZSBhbGxwcm9maWxlcy5yZWFkIiwidHQiOiIxIiwiaXBhZGRyIjoiNDAuMTI2LjI3LjI0In0.KirrAMKoF9fYoKGFRQRG96CkR_o8PxKK7z7duKoHT9M&ApiVersion=2.

Subscribe
Notify of
guest

CAPTCHA


0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments