datRedHeadedGuy
datRedHeadedGuy

Reputation: 21

Get Documents from a List using Graph API

With the SharePoint REST API, there was the /files endpoint that did a recursive search and gave you all the files from a List. Is there anything like that with the Graph API? I've been looking and have not found anything like that.

I've tried a couple of ways:

/items?$isDocument=true

/items?$filter=isDocument eq true

/items?$filter=contentType.name eq 'Document'

Upvotes: 2

Views: 256

Answers (1)

user2250152
user2250152

Reputation: 20788

You can filter list items by ContentType field

GET /v1.0/sites/{site_id}/lists/{list_id}/items?$filter=fields/ContentType eq 'Document'

But the request requires the header Prefer with the value HonorNonIndexedQueriesWarningMayFailRandomly

The second option is to use the Graph search API to search for list items and reduce the search to a specific document library specifying by URL

POST https://graph.microsoft.com/v1.0/search/query

{
    "requests": [
        {
            "entityTypes": [
                "listItem"
            ],
            "query": {
                "queryString": "path:\"https://contoso.sharepoint.com/sites/{site_name}/{document_library_name}\" ContentTypeId:0x0101*"
            }
        }
    ]
}

Content type ID uniquely identify the content type

Upvotes: 2

Related Questions