microsoft-graph-apionedrivemicrosoft-graph-sdksazure-china

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


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?


Solution

  • 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.