1
votes

The Microsoft Graph API is driving me nuts. I am trying and reading for hours and still can't get it to work.

I work with Sharepoint which contains a subsite, where there is DocumentLibrary with serveral folders.

I search the API: (https://graph.microsoft.com/v1.0/search/query)

                   "hits": [
                        {
                            "hitId": "01XPDM72T7SCIOG6BP4BAYQ5QI5RFFAESK",
                            "rank": 1,
                            "summary": "<c0>test</c0><ddd/><c0>test</c0><ddd/>",
                            "resource": {
                                "@odata.type": "#microsoft.graph.driveItem",
                                "size": 4,
                                "id": "3",
                                "createdDateTime": "2021-01-08T12:11:12Z",
                                "lastModifiedDateTime": "2021-01-08T12:11:12Z",
                                "name": "test.txt",
                                "webUrl": "https://tenant.sharepoint.com/sites/SubSite/Gedeelde documenten/test.txt",
                                "fileSystemInfo": {
                                    "createdDateTime": "2021-01-08T12:11:12Z",
                                    "lastModifiedDateTime": "2021-01-08T12:11:12Z"
                                },
                                "lastModifiedBy": {
                                    "user": {
                                        "displayName": "Admin"
                                    }
                                },
                                "parentReference": {
                                    "driveId": "2",
                                    "siteId": "1",
                                    "sharepointIds": {
                                        "listId": "[snip]",
                                        "listItemUniqueId": "[snip]"
                                    }
                                }
                            }
                        },

So far so good. I find a driveItem, and now want to get the contents.

in the parentReference I see driveId, siteId and id in the resource. to my knowledge:

{site-id} = 1;
{drive-id} = 2;
{item-id} = 3;

If I look at https://docs.microsoft.com/en-us/graph/api/driveitem-get I can use several functions.

I start with /sites/{site-id}/drive/items/{item-id} and /drives/{drive-id}/items/{item-id}

Response: "error": { "code": "itemNotFound", "message": "The resource could not be found.",

/sites/{site-id}/lists/{list-id}/items/{item-id}/driveItem

Response:

"error": { "code": "itemNotFound", "message": "The specified list was not found",

Nothing works. Can someone please help me out?

1

1 Answers

0
votes

Please firstly get the valid site id using this endpoint:

https://graph.microsoft.com/v1.0/sites?search=yoursitename, the site id shouldn't be a int value, it will like this:

enter image description here

Then access the specific libray like this:

https://graph.microsoft.com/v1.0/sites/TenantName.sharepoint.com,91a47a59-db5e-4d17-a689-479ee8905533,274459c9-4c96-42bf-9b96-838ffa387aaa/lists/doc2/items/10/driveItem

The library is named "doc2" and get the item id "10":

enter image description here

enter image description here