3
votes

I'm trying to download a file from SharePoint online using Microsoft Graph API. Graph API is not allowing me to use /Content.

This is the endpoint I'm using:

https://graph.microsoft.com/v1.0/sites/<host.sharepoint.com>/lists/<ListID>/items/<ItemID>

This is what get (Values Removed):

{
"@odata.context","@odata.etag","createdDateTime","eTag","id","lastModifiedDateTime","webUrl","createdBy"{"user": {"email","id","displayName"}},   "lastModifiedBy": {"user": {"email","id","displayName"}},
"parentReference": {"id"},
"contentType": {"id"},
"fields@odata.context",
"fields": {"@odata.etag","FileLeafRef","id","ContentType","Created",    "AuthorLookupId","Modified","EditorLookupId","_CheckinComment",      "LinkFilenameNoMenu","LinkFilename","DocIcon","FileSizeDisplay",       "ItemChildCount","FolderChildCount","_ComplianceFlags","_ComplianceTag",        "_ComplianceTagWrittenTime","_ComplianceTagUserId","_CommentCount",        "_LikeCount","Edit","_UIVersionString","ParentVersionStringLookupId",       "ParentLeafNameLookupId"
}

}

When i try to add /content i get:

{
"error": {
    "code": "BadRequest",
    "message": "Resource not found for the segment 'content'.",
    "innerError": {
        "request-id": "<ReqID>",
        "date": "<date>"
    }
}

}

How do i download this file using the API?

1

1 Answers

8
votes

The endpoint https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items/{item-id} returns ListItem resource but Content is a property of DriveItem resource which

Represents an item within a drive, like a document, photo, video, or folder resource

that's the reason this error occurs.

Given the provided endpoint it could be modified to

GET https://graph.microsoft.com/v1.0/sites/{site-id}/lists/{list-id}/items/{item-id}/driveItem/content

to download a content