Accessing the shared documents folder within a private group of a sharepoint site using Graph API

Viewed 182

I am in the process of trying to use Graph API to upload a test file to a Sharepoint site. I am struggling to correctly point Graph API to a point within the Shared Documents folder on a private group.

Suppose the host is devsite.sharepoint.com and the private group is "Development". In the shared documents there is a folder called "TestFolder".

Private Group with folder "TestFolder"

By trial and error on graph explorer, I've successfully navigated to the private group using.

https://graph.microsoft.com/v1.0/sites/devsite.sharepoint.com:/sites/Development

I've unsuccessfully tried to access the shared documents folder using the following

https://graph.microsoft.com/v1.0/sites/devsite.sharepoint.com:/sites/Development/drive/root

https://graph.microsoft.com/v1.0/sites/devsite.sharepoint.com:/sites/Development/Shared%20Documents/TestFolder

all of which return

Code: BadRequestMessage: Url specified is invalid or The provided path does not exist, or does not represent a site

The graph API website documentation, unfortunately, doesn't yield anything of value, any help on this from the crowd would be appreciated!

1 Answers

Your first call https://graph.microsoft.com/v1.0/sites/devsite.sharepoint.com:/sites/Development:/drives returns something like this:

{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives",
    "value": [
        {
            "createdDateTime": "2021-07-24T23:35:00Z",
            "description": "",
            "id": "b!A1234567-ZYXWVUTSRQPONMLKJIHGFEDCBA9876543210",
            "lastModifiedDateTime": "2021-08-12T16:39:23Z",
            "name": "Dokumente",
            "webUrl": "https://organizationname.sharepoint.com/sites/yourSIteName/folderName",
            "driveType": "documentLibrary",
            "createdBy": {
                "user": {
                    "displayName": "abc"
                }
            },
            "lastModifiedBy": {
                "user": {
                    "email": "bla@organizationame.onmicrosoft.com",
                    "id": "12345678-4321-4321-4321-012345678901",
                    "displayName": "zz"
                }
            },
            "owner": {
                "group": {
                    "email": "x@y.onmicrosoft.com",
                    "id": "09876543-1234-1234-1234-012345678901",
                    "displayName": "Owner of something"
                }
            },
            "quota": {
                "deleted": 345678,
                "remaining": 27487788453406,
                "state": "normal",
                "total": 27487790694400,
                "used": 96120
            }
        }
    ]
}

The id parameter under description in the above json is the drive-id of your shared documents folder. You can use it like this to access and navigate your shared documents folder:

https://graph.microsoft.com/v1.0/sites/devsite.sharepoint.com/drives/b!A1234567-ZYXWVUTSRQPONMLKJIHGFEDCBA9876543210/root:/yourfile.docx
Related