How to replace a file using Graph API

Ciprian Oltean 0 Reputation points
2024-03-08T07:35:28.5333333+00:00

Hello,

I am trying to replace a file in SPO using Postman and Graph API as follows:

and instead of replacing the file it marks with check-out even if the library is configured with Require documents to be checked out before they can be edited? = No

So we have to do another task to check in the file add a comment and in this way the file gets replaced.

This is not the way I want to replace a file.

Like this tutorial: https://learn.microsoft.com/en-us/graph/api/driveitem-update?view=graph-rest-1.0&tabs=http is telling us that it should automatically replace the existing file with the new one in one go. But unfortunately it doesn't like I said above.

I appreciate any help here.

Thank you.

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

1 answer

Sort by: Most helpful
  1. Ciprian Oltean 0 Reputation points
    2024-03-08T10:03:20.4266667+00:00

    Fortunately I have found the solution for my issue (following https://learn.microsoft.com/en-us/answers/questions/1184008/sharepoint-check-in-check-out-issue).

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