Files that should exist cannot be retrieved from the API

Mitsutoshi Shibuya 0 Reputation points
2023-04-28T07:28:48.39+00:00

My application uses "GET /drives/{drive-id}/items/{item-id}/children" to search for items in the drive and make sure no files with the same name exist.

However, uploading a file using "POST /drives/{driveId}/items/{itemId}/createUploadSession" returns "nameAlreadyExists" and the upload fails.

Please let me know if there are any conditions for items that cannot be retrieved with GET /drives/{drive-id}/items/{item-id}/children.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
9,063 questions
SharePoint Development
SharePoint Development
SharePoint: A group of Microsoft Products and technologies used for sharing and managing content, knowledge, and applications.Development: The process of researching, productizing, and refining new or existing technologies.
2,389 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. RaytheonXie_MSFT 26,791 Reputation points Microsoft Vendor
    2023-05-01T02:25:01.0333333+00:00

    Hi @Mitsutoshi Shibuya

    The request options in your question can only be used to upload a new version of an already existing document by using the id of the document. A folder does not have a document, that can be replace with a newer version. Therefore, it is not possible to create an upload session for a folder. You need to specify the name of the file as a relative path after the folder id in order to create an upload session for a new file in the folder:

    https://graph.microsoft.com/v1.0/sites/{siteId}/drives/{driveId}/items/{folderId}:/{fileNameUploadFile}:/createUploadSession
    

    You can also use the folder name instead of the folder id:

    https://graph.microsoft.com/v1.0/sites/{siteId}/drives/{driveId}/root:/{folderName}/{fileNameUploadFile}:/createUploadSession
    
    

    If the answer is helpful, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.