I want to update the content of the file on OneDrive item. For that I used this API.
PUT /drives/{drive-id}/items/{parent-id}:/{filename}:/content
This works perfectly fine for non China azure with Microsoft graph endpoint.
However, when I am trying this on AzureChina it is throwing me 501 error.
Error:
This is the error response I am getting event though I am uploading data to file.
{
"error": {
"code": "notSupported",
"message": "Cannot upload content to an item representing a folder.",
"innerError": {
"date": "2021-05-10T09:01:12",
"request-id": "98a8b075-bb90-42fe-8620-7303e669f4ec",
"client-request-id": "98a8b075-bb90-42fe-8620-7303e669f4ec"
}
}
}
Is this not implemented in AzureChina? Another thing is graph explorer does not work with AzureChina. Is there separate graph explorer available for AzureChina?
For Azure China, Work around for Graph API is to use SharePoint REST API v1.
To upload the file contents of drive items
URL: https://{site_url}/_api/web/GetFolderByServerRelativeUrl('/Folder Name')/Files/add(url='newFile.txt',overwrite=true)
Headers:
"Accept": "application/json; odata=verbose",
"Authorization": "Bearer " + accessToken
Method: "POST",
Body:
<File_contents>
Auth URL: https://login.partner.microsoftonline.cn/{{TenantID}}/oauth2/v2.0/authorize
Access Token URL: https://login.partner.microsoftonline.cn/{{TenantID}}/oauth2/v2.0/token
Scope : https://{tenantId}-my.sharepoint.cn/.default
Make sure you have added appropriate API Permissions for SharePoint & granted Admin consent in Azure AD portal within corresponding Application.