OneDrive Personal: supported atomic conditional replacement of an existing workbook

Pa Col Cassidy 0 Reputation points
2026-11-22T10:14:52.3766667+00:00

We are developing a private application using delegated Microsoft Graph access to personal OneDrive. An existing .xlsx file is approximately 93 KB. It must remain the same driveItem and must only be replaced if the original file revision still matches at the instant of publication.

Observed sequence:

  1. GET existing item's identity, parent, name and eTag E1.
  2. POST /me/drive/items/{file-id}/createUploadSession with If-Match: E1 and body {"item":{"@microsoft.graph.conflictBehavior":"replace"},"deferCommit":true}.
  3. PUT bytes to the returned upload URL; HTTP 202 received. The file remains at E1.
  4. Attempt metadata PUT with Content-Type: application/json, If-Match: E1 and body {"name":"disposable.xlsx","@microsoft.graph.conflictBehavior":"replace","@microsoft.graph.sourceUrl":"{upload-session-url}"}.

Variants tried:

  • Parent-plus-filename addressing: HTTP 400 invalidRequest on allocation commit.
  • Parent item addressing: HTTP 412 for both deliberately invalid and current workbook eTags.
  • Existing workbook item addressing: HTTP 400 invalidRequest on the first stale-revision diagnostic; no valid control ran.

No successful publication was observed. The disposable file remains at its original revision and hash. Upload-session cleanup is attempted; we retain unresolved operation records and do not automatically retry or fall back to unconditional upload.

Please clarify:

  1. What exact supported endpoint, method, headers and body atomically replace the contents of the same existing OneDrive Personal item only if its frozen file eTag still matches at publication?
  2. For deferred sessions, does final metadata PUT compare the destination file's revision or the addressed parent resource's revision? Which addressing form is supported for replacing an existing immutable item?
  3. Is PUT /me/drive/items/{file-id}/content with If-Match explicitly supported as an atomic final-write condition? The current simple-upload request-header table omits If-Match.
  4. How are concurrent native Excel edits, rename/move, and delete/recreate handled? Which checks are atomic versus application preflight only?
  5. Which returned codes guarantee that no content was published? After a timeout/lost response or rejected commit, how can we prove the staged session cannot publish later before releasing our application writer lock?
  6. Please identify the authoritative documentation for OneDrive Personal and distinguish it from OneDrive for Business/SharePoint behaviour.

We can provide sanitised timestamps, request IDs and request/response diagnostics through a suitable private support channel. This question intentionally excludes credentials, signed URLs, real item identifiers, workbook contents and account information.

References:

Microsoft Security | Microsoft Graph
0 comments No comments

1 answer

Sort by: Most helpful
  1. Walker Pollitt 400 Reputation points
    2026-11-22T11:20:09.3766667+00:00

    I couldn’t verify a Microsoft Graph v1.0 contract that guarantees your exact condition: replace this same existing driveItem only if its original file eTag still matches at publication. If-Match is documented when creating an upload session. For OneDrive Personal, Microsoft also documents a final metadata PUT, but its example addresses the parent path and uses conflict behavior rename. It doesn’t specify that this request compares the existing destination workbook’s eTag. The simple PUT /me/drive/items/{item-id}/content reference documents replacement by ID but omits If-Match from its header table.

    I’d keep your current behavior after an ambiguous commit: retain the operation record and avoid an unconditional retry. Graph documents DELETE on the upload URL to cancel a session, with 204 as the success response. Cancellation cleans up staged data. It can’t establish whether an earlier commit with a lost response already published the workbook. That distinction matters before releasing your writer lock.

    Upload session and deferred commit examples · Replace driveItem contents

    Drafted with ChatGPT. Learning path · Microsoft Graph fundamentals

    Was this answer helpful?


Your answer

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