Graph API: Upload contents of driveItem throws 501 not_implemented error for AzureChina

699 Views Asked by At

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.

https://graph.microsoft.com

However, when I am trying this on AzureChina it is throwing me 501 error.

https://microsoftgraph.chinacloudapi.cn

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?

2

There are 2 best solutions below

0
SO-User-vtas1409 On BEST ANSWER

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.

1
user2250152 On

According to this page OneDrive and Excel features of Graph API are limited by Microsoft Cloud China but without more details what exactly is not supported.