How to use Microsoft Graph API add password for OneDrive online file.

Scorpio 20 Reputation points
2024-01-19T05:12:52.73+00:00

I user Microsoft Graph API to upload file to OneDrive, require add password.

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,042 questions
OneDrive
OneDrive
A Microsoft file hosting and synchronization service.
1,306 questions
0 comments No comments
{count} votes

Accepted answer
  1. ChenLi-MSFT 235 Reputation points Microsoft Vendor
    2024-01-22T09:21:23.03+00:00

    Hi @Scorpio,

    Microsoft Graph does not seem to be able to directly add passwords to files on OneDrive, but you can add access passwords to shared file links:

    POST /me/drive/items/{item-id}/createLink
    Content-type: application/json
    
    {
      "type": "view",
      "password": "ThisIsMyPrivatePassword",
      "scope": "anonymous",
      "retainInheritedPermissions": false
    }
    

    For more detail, you can refer to this document: Create a sharing link for a DriveItem. If you receive error code sharingDisabled, you can refer to this document to open the corresponding permissions (if you are an administrator): Sharing errors in SharePoint and OneDrive. Hope this helps. If the reply is helpful, please click Accept Answer and kindly upvote it. If you have additional questions about this answer, please click Comment.


1 additional answer

Sort by: Most helpful
  1. Scorpio 20 Reputation points
    2024-01-22T09:24:28.6566667+00:00

    Thanks, I have solved the problem.

    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.