Graph Upload .conflictBehavior rename works but not replace

Mark Fisher 0 Reputation points
2024-05-23T20:36:50.55+00:00

Hello,

I have a python application to upload an html file that has been generated and it works to upload the first time. If I want to replace the file however, the upload fails. I have tried setting the @microsoft.graph.conflictBehavior to "replace" but that doesn't work, however using "rename" does rename the old file and then allows uploading of the new one but I don't want to do that, I simply want to replace the existing file so I don't end up with a lot of extra files that have to be cleaned up.

Thanks.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
11,112 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Sourabh Gupta 795 Reputation points Microsoft Vendor
    2024-05-25T11:42:39.7766667+00:00

    Hi Mark Fisher

    Thanks for reaching out.

    The issue might be because of some file checkout thing. Could you please refer to the following

    https://learn.microsoft.com/en-us/answers/questions/1611304/how-to-replace-a-file-using-graph-api

    To replace a file in SPO using Graph API we must follow 2 steps, such as:

    1. call a PUT API with which the file get's uploaded.
      1. Here the original file with same name enter into a check out phase
    2. call a POST API with checkin property and a JSON as body including "comment" attribute and a value to preserve file history

    https://learn.microsoft.com/en-us/answers/questions/1184008/sharepoint-check-in-check-out-issue

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

    0 comments No comments