Microsoft Graph API for creating a folder with "replace" conflict behaviour

Diana Ivanova 0 Reputation points
2024-10-11T09:55:41.5033333+00:00

I want to use Microsoft Graph API rest to create a folder. I followed the documentation https://learn.microsoft.com/en-us/graph/api/driveitem-post-children?view=graph-rest-1.0&tabs=http

However, the documentation does not clearly state the idea of the following attribute.

It is only mentioned that there are 3 available values: replace, fail and rename.

I tested replace and used a name for the directory which already existed. It actually responded with 200 OK code and the directory remained the same. No change. The files inside it were preserved. Is this the expected behaviour?

@microsoft.graph.conflictBehavior"
Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
12,039 questions
OneDrive
OneDrive
A Microsoft file hosting and synchronization service.
1,118 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Rohit Raghuwanshi - MSFT 470 Reputation points Microsoft Vendor
    2024-10-11T11:41:47.7+00:00

    Hi Diana Ivanova,

    Thank you for reaching out, Microsoft!

    The @microsoft.graph.conflictBehavior attribute determines how conflicts are handled when a folder or file with the same name already exists. The three values you mentioned are:

    replace: This should replace the existing item with the new one.

    fail: This should fail the request if an item with the same name already exists.

    rename: This should rename the new item to avoid a conflict.

    From your description, it seems like using replace did not replace the existing folder but instead preserved it and its contents, which seems the justified behavior as it replaces particular drive item and not it's content. I tried to recreate the scenario and found that request does replaces the folder as lastModifiedDateTime changes for folder after API is executed but does not delete the files inside it.

    Please refer the below screenshot:

    Before API request
    User's image API request:
    User's image

    After POST request:
    User's image

    If my answer is helpful to this question, please remember to "Accept as answer" to close this case and this will help people in this forum who have similar questions to yours find the answer easier.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.