Store and access files in SharePoint Embedded with Microsoft Graph REST APIs
Developers creating apps that use SharePoint Embedded will use well known and established Microsoft Graph APIs to access the files and documents in these Containers. The Microsoft Graph Drive endpoint can access data stored within a SharePoint Embedded Container. In this section, you'll learn how to use the Microsoft Graph REST APIs to store and retrieve files and documents in SharePoint Embedded Containers.
Important
At this time, many of the Microsoft Graph endpoints used to create, access, and manage SharePoint Embedded-specific resource only exist on the Microsoft Graph beta endpoint. However, all endpoints that access the Containers and content within contains are on the Microsoft Graph v1.0 endpoint.
Working with Containers
Once you've completed all the setup and registration processes between the provider and consuming tenants, you need to create a Container in the consuming tenant.
Create a new Container
To create a Container, submit an HTTP POST with a JSON payload that specifies name, description, and the associated ContainerType ID:
POST https://graph.microsoft.com/beta/storage/fileStorage/containers
{
"displayName": "Sample App Container 1",
"description": "First container description.",
"containerTypeId": "{{ContainerTypeId}}"
}
Microsoft Graph will respond with the details of the new Container:
{
"id": "b!qEMTpi-XGEKZ1W...",
"displayName": "Sample App Container 1",
"description": "First container description.",
"containerTypeId": "3a6b1fc4-0b09-04b3-3a2a-4843fbb60914",
"status": "inactive",
"createDateTime": 2023-11-T00:15:25.84Z"
}
List all Containers
To get a list of all Containers created, submit an HTTP GET request and filter by the ContainerType ID:
GET https://graph.microsoft.com/beta/storage/fileStorage/containers?$filter=containerTypeId eq {{ContainerTypeId}}
Get a specific Container
To get a specific Container, submit an HTTP GET request to the Containers
endpoint:
GET https://graph.microsoft.com/beta/storage/fileStorage/containers/{{ContainerID}}?$select=id,displayName,containerTypeId,status,description,customProperties&$expand=permissions
Working with the contents of a Container
To work with the contents, or files, in a Container, you'll use the same Microsoft Graph endpoints available for reading and writing to SharePoint document libraries or OneDrive: the drives
endpoint. This is because a SharePoint Embedded Container is seen as the same thing as a Microsoft Graph Drive
object and files within the Drive
are DriveItems
.
Get a specific Container as a Drive
object
To get a specific Container as a Drive object, submit an HTTP GET request to the Microsoft Graph drives
endpoint:
GET https://graph.microsoft.com/v1.0/drives/{{ContainerID}}
To learn more about the Microsoft Graph drives
endpoint, see Microsoft Graph REST API: Get Drive.
List the contents of a Container
To get the contents of a Container, submit an HTTP GET request to the same endpoint but go to the children of the Container:
GET https://graph.microsoft.com/v1.0/drives/{{ContainerID}}/items/root/children
Upload a file to a Container
To upload a file to a Container, submit an HTTP POST request to the drives
endpoint and include the content of the file in the request:
PUT https://graph.microsoft.com/v1.0/drives/{{ContainerId}}/root:/Jan2024.docx:/content
<binary contents of the file>
Delete the contents of a Container
To delete a file from a Container, submit an HTTP DELETE request to the drives
endpoint:
DELETE https://graph.microsoft.com/v1.0/drives/{{ContainerID}}/items/root/{{driveItemID}}
To learn more about working with files using Microsoft Graph, see Microsoft Graph REST API: Drive Items.
Summary
Developers creating apps that use SharePoint Embedded will use well known and established Microsoft Graph APIs to access the files and documents in these Containers. The Microsoft Graph Drive endpoint can access data stored within a SharePoint Embedded Container.
In this section, you learned how to use the Microsoft Graph REST APIs to store and retrieve files and documents in SharePoint Embedded Containers.