Skip to main content

Read / Write SharePoint Files

graphRequirements: explorerGraph Explorer knowledge needed

Create App Registration

App Registration will be used to authenticate against Microsoft Graph API.

Permissions

With API Permission "Sites.Selected" you can specify on which SharePoint-Sites the App Registration will have permissions to read/write files and properties.

image.png

Get Site ID

To get the site id of your sharepoint sites to to the following link in a Webbrowser:

GET https://<tenantname>.sharepoint.com/sites/<sitename>/_api/site/id
Example: https://lucanoahcaprez.sharepoint.com/sites/SPS-LNC-WebFiles-PROD/_api/site/id

Example XML Response in Browser:

image.png

Get Folder ID

Folder IDs can be found using the graph explorer and the Site ID:

GET https://graph.microsoft.com/v1.0/sites/<SiteID>/drives
Example: https://graph.microsoft.com/v1.0/sites/22c1c748-f7e0-4f10-97f4-64b51694a0ca/drives

Example JSON Response from Graph API
{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives",
    "value": [
        {
            "createdDateTime": "2021-04-03T23:11:15Z",
            "description": "",
            "id": "b!SMfBIuD3EE-X9GS1FpSgypE4hAdzBPVAhzjowjy6CTAFMPrY5yGSRYYXW7Jhy97f",
            "lastModifiedDateTime": "2022-05-06T07:25:15Z",
            "name": "Dokumente",
            "webUrl": "https://bkwfmbenergie.sharepoint.com/sites/T_BKW_Test_CAPRL/Freigegebene%20Dokumente",
            "driveType": "documentLibrary",
            "createdBy": {
                "user": {
                    "displayName": "Systemkonto"
                }
            },
            "lastModifiedBy": {
                "user": {
                    "displayName": "Systemkonto"
                }
            },
            "owner": {
                "group": {
                    "email": "T_BKW_Test_CAPRL@bkwfmbenergie.onmicrosoft.com",
                    "id": "bab76dba-25aa-4804-8cad-4fde62da958b",
                    "displayName": "Besitzer von T_BKW_Test_CAPRL"
                }
            },
            "quota": {
                "deleted": 0,
                "remaining": 27487376431088,
                "state": "normal",
                "total": 27487790694400,
                "used": 414263312
            }
        },
        {
            "createdDateTime": "2021-04-06T13:42:16Z",
            "description": "",
            "id": "b!SMfBIuD3EE-X9GS1FpSgypE4hAdzBPVAhzjowjy6CTA3sb9Pi_NxRJ3lfYXRyKTz",
            "lastModifiedDateTime": "2021-10-02T21:16:08Z",
            "name": "Vertragsablage",
            "webUrl": "https://bkwfmbenergie.sharepoint.com/sites/T_BKW_Test_CAPRL/Vertragsablage",
            "driveType": "documentLibrary",
            "createdBy": {
                "user": {
                    "displayName": "Systemkonto"
                }
            },
            "lastModifiedBy": {
                "user": {
                    "displayName": "Systemkonto"
                }
            },
            "owner": {
                "group": {
                    "email": "T_BKW_Test_CAPRL@bkwfmbenergie.onmicrosoft.com",
                    "id": "bab76dba-25aa-4804-8cad-4fde62da958b",
                    "displayName": "Besitzer von T_BKW_Test_CAPRL"
                }
            },
            "quota": {
                "deleted": 0,
                "remaining": 27487376431088,
                "state": "normal",
                "total": 27487790694400,
                "used": 414263312
            }
        },
        {
            "createdDateTime": "2022-09-15T09:41:10Z",
            "description": "sharepoint list",
            "id": "b!SMfBIuD3EE-X9GS1FpSgypE4hAdzBPVAhzjowjy6CTC6kAXUUK7qSLG7oSTLYNsQ",
            "lastModifiedDateTime": "2022-09-15T09:41:10Z",
            "name": "Teams Wiki Data",
            "webUrl": "https://bkwfmbenergie.sharepoint.com/sites/T_BKW_Test_CAPRL/Teams%20Wiki%20Data",
            "driveType": "documentLibrary",
            "createdBy": {
                "user": {
                    "email": "luca.caprez@bkw.ch",
                    "id": "9e5da9b4-7023-4d36-86f5-33768907270f",
                    "displayName": "Caprez Luca Noah, BKW"
                }
            },
            "lastModifiedBy": {
                "user": {
                    "email": "luca.caprez@bkw.ch",
                    "id": "9e5da9b4-7023-4d36-86f5-33768907270f",
                    "displayName": "Caprez Luca Noah, BKW"
                }
            },
            "owner": {
                "group": {
                    "email": "T_BKW_Test_CAPRL@bkwfmbenergie.onmicrosoft.com",
                    "id": "bab76dba-25aa-4804-8cad-4fde62da958b",
                    "displayName": "Besitzer von T_BKW_Test_CAPRL"
                }
            },
            "quota": {
                "deleted": 0,
                "remaining": 27487376431088,
                "state": "normal",
                "total": 27487790694400,
                "used": 414263312
            }
        }
    ]
}

Get Folder Documents

Get folder documents and content with graph api:

GET https://graph.microsoft.com/v1.0/sites/<SiteID>/drives/<FolderID>
Example: https://graph.microsoft.com/v1.0/sites/22c1c748-f7e0-4f10-97f4-64b51694a0ca/drives/b!SMfBIuD3EE-X9GS1FpSgypE4hAdzBPVAhzjowjy6CTAFMPrY5yGSRYYXW7Jhy97f

Example JSON Response in Graph Explorer:

Example JSON Response from Graph API
{
    "@odata.context": "https://graph.microsoft.com/v1.0/$metadata#drives/$entity",
    "createdDateTime": "2021-04-03T23:11:15Z",
    "description": "",
    "id": "b!SMfBIuD3EE-X9GS1FpSgypE4hAdzBPVAhzjowjy6CTAFMPrY5yGSRYYXW7Jhy97f",
    "lastModifiedDateTime": "2022-05-06T07:25:15Z",
    "name": "Dokumente",
    "webUrl": "https://bkwfmbenergie.sharepoint.com/sites/T_BKW_Test_CAPRL/Freigegebene%20Dokumente",
    "driveType": "documentLibrary",
    "createdBy": {
        "user": {
            "displayName": "Systemkonto"
        }
    },
    "lastModifiedBy": {
        "user": {
            "displayName": "Systemkonto"
        }
    },
    "owner": {
        "group": {
            "email": "T_BKW_Test_CAPRL@bkwfmbenergie.onmicrosoft.com",
            "id": "bab76dba-25aa-4804-8cad-4fde62da958b",
            "displayName": "Besitzer von T_BKW_Test_CAPRL"
        }
    },
    "quota": {
        "deleted": 0,
        "remaining": 27487376431088,
        "state": "normal",
        "total": 27487790694400,
        "used": 414263312
    }
}