web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Graph Copy API returni...
Power Automate
Suggested Answer

Graph Copy API returning “Unauthenticated” (401) but file still gets replaced in SharePoint

(0) ShareShare
ReportReport
Posted on by

Hi Team,

I’m facing an inconsistent issue with the Microsoft Graph Copy DriveItem API when replacing SharePoint files. The request to:

POST /sites/{site-id}/drive/items/{item-id}/copy?@microsoft.graph.conflictBehavior=replace

now returns:

{"error":{"code":"unauthenticated","message":"Unauthenticated"}}

even though the file sometimes does get updated. Other times the update fails completely. Token, scopes, itemId, and siteId are all valid, and other Graph endpoints work. Graph Explorer also returns 401.

Are there any known issues, changes, or alternative recommended APIs for reliable file replacement?

Categories:
  • Suggested answer
    Mohsin Ali Profile Picture
    2,862 on at
    Hello @AK-17020736-0 -  Since the same 401 happens in Graph Explorer, I would not assume your token, scopes, siteId, or itemId are the root cause.

    A few things to check:

    • Copy DriveItem is asynchronous, so confirm whether the request returns 202 Accepted and monitor the Location URL for the final result.
    • Test once without @microsoft.graph.conflictBehavior=replace to confirm whether the issue is specifically tied to replacement behavior.
    • Capture the request-id, timestamp, and response headers when the 401 occurs.
    • Check Microsoft 365 Service Health.
    If your actual requirement is only to replace the contents of an existing file, I would consider using the upload/update API instead of copy. For larger files, createUploadSession is the more reliable option.

    Since Graph Explorer reproduces the same behavior, I would also raise a Microsoft support case with the request-id and UTC timestamp.


  • CU23090823-0 Profile Picture
    2 on at
     Yes, the driveItem/copy API has known quirks, and the “unauthenticated” error you’re seeing is a documented issue. It’s not a stable way to replace files in SharePoint. The recommended approach for reliable file replacement is to use myloancare com the PUT /sites/{site-id}/drive/items/{item-id}/content (upload/replace) endpoint instead of copy with conflictBehavior=replace.  
  • Suggested answer
    M Bilal Khan Profile Picture
    1,172 on at

    One thing I would check here is the asynchronous nature of the Graph Copy API.

    The driveItem/copy endpoint doesn't perform the replacement synchronously. Microsoft documents it as returning 202 Accepted with a Location header containing a monitor URL. The actual copy/replacement is then processed in the background.

    So if you're seeing a 401 Unauthenticated while the SharePoint file is sometimes actually replaced, I would capture the complete HTTP response, including:

    • HTTP status code
    • Response body
    • Location header
    • Correlation/request IDs
    • Whether the replacement completed afterward

    Also verify that you're using the documented syntax:

    POST /sites/{site-id}/drive/items/{item-id}/copy?@microsoft.graph.conflictBehavior=replace
    

    For SharePoint/OneDrive for Business, replace is supported for file conflicts.

    If you receive a 202, follow the monitor URL and check its final status rather than treating the initial response as the final result.

    For reliability, I'd also test an alternative approach: if your real requirement is simply replace the contents of an existing SharePoint file, consider updating the existing DriveItem's content rather than using copy. The Graph upload/content APIs support replacing file content and can use upload sessions for larger files.

    Since Graph Explorer is also returning 401, I'd additionally test the exact request against a known-good file and verify the token's permissions and the target item's access. That helps distinguish an authentication/authorization problem from an issue specific to the Copy operation.

    The fact that the file is actually replaced is an important clue, so I wouldn't assume the 401 alone means the entire operation failed. The actual Graph response + copy monitor status should tell you where the failure is occurring.

  • Mohsin Ali Profile Picture
    2,862 on at
    Hello @AK-17020736-0 - Just wanted to follow-up if the suggestions I shared above really helped, pointed in right directions or if you have any further questions.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Season of Sharing Community Challenge Winners!

Congratulations to our community stars!

Kudos to our 2025 Community Spotlight Honorees

Expanding mentorship, skilling, and AI innovation

Leaderboard > Power Automate

#1
11manish Profile Picture

11manish 321 Super User 2026 Season 2

#2
Mohsin Ali Profile Picture

Mohsin Ali 244

#3
Henil Profile Picture

Henil 102

Last 30 days Overall leaderboard