How do I set a retention label at the same time as creating a new driveItem?

catmanjan 61 Reputation points
2025-02-19T02:57:47.4366667+00:00

We are creating Microsoft Graph driveItems using the SDK.

We apply retention labels to the newly created driveItem - however this creates an opportunity for the driveItem to fail to be labelled for whatever reason.

What we want to know is, is it possible to set the retention label at the same time as uploading the driveItem, so its done atomically?

Microsoft Graph
Microsoft Graph
A Microsoft programmability model that exposes REST APIs and client libraries to access data on Microsoft 365 services.
13,149 questions
Microsoft Purview
Microsoft Purview
A Microsoft data governance service that helps manage and govern on-premises, multicloud, and software-as-a-service data. Previously known as Azure Purview.
1,421 questions
0 comments No comments
{count} votes

Accepted answer
  1. Saranya Madhu-MSFT 1,725 Reputation points Microsoft Vendor
    2025-02-20T07:14:01.5033333+00:00

    Hi catmanjan,

    Thanks for reaching out to Microsoft!

    Currently, the Microsoft Graph API does not support setting a retention label at the same time as uploading a driveItem automically.

    Apply (set) a retention label on a driveItem (files and folders) using Graph API-

    PATCH /driveitem/retentionLabel
    PATCH /drives/{drive-id}/items/{item-id}/retentionLabel
    
    

    Use retention labels to manage the lifecycle of documents stored in SharePoint

    Hope this helps.

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

    0 comments No comments

0 additional answers

Sort by: Most helpful

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.