pnp / pnp/cli-microsoft365

New command: Apply a sensitivity label to a file

Open
#4,714 6 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

feature request keep-open needs discussion
Dominant language
TypeScript
Stars
1.5k
Forks
413
Avg merge
5d 6h
Merged PRs (30d)
21

Description

Usage

m365 spo file sensitivitylabel ensure

Description

Applies a sensitivity label to a file

Options
Option Description
-u, --webUrl <webUrl> URL of the site where the file is located
-t, --listTitle [listTitle] The title of the library where the file is located that should be labelled. Specify either listTitle, listId, or listUrl but not multiple.
-l, --listId [listId] The ID of the library where the file is located that should be labelled. Specify either listTitle, listId, or listUrl but not multiple.
--listUrl [listUrl] Server- or web-relative URL of the library where the file is located that should be labelled. Specify either listTitle, listId, or listUrl but not multiple.
-f, --fileUrl [fileUrl] the URL of the file that should be labelled. Specify either fileUrl or fileId but not both.
--fileId [fileId] The UniqueId (GUID) of the file that should be labelled. Specify either fileUrl or fileId but not both.
-n, --name [name] Name of the sensitivity label to apply to the file. Specify either name or id but not both.
-i, --id [id] Id of the sensitivity label to apply to the file. Specify either name or id but not both.
Examples

Apply a sensitivity label based on the file url

m365 spo file sensitivitylabel ensure --webUrl 'https://contoso.sharepoint.com' --libraryName 'Shared Documents' --fileUrl '/Shared Documents/Document.docx' --name 'Label'

Apply a sensitivity label based on the file ID

m365 spo file sensitivitylabel ensure --webUrl 'https://contoso.sharepoint.com' --libraryName 'Shared Documents' --fileId '33f05b7a-c8d0-427d-8cc8-bceb11d33c30' --name 'Label'
Default properties

No response

Additional Info

If someone knows an easier solution, let me know. This was the only way I coud find:

POST https://contos.sharepoint.com/_api/v2.1/drives/[Drive ID]/items/[Document ID]/setsensitivityLabel
with body:

{ 
  "id": "[Sensitivity Label ID]"
}

This means we should retrieve 3 parameters:

  • The SharePoint Drive ID of the Document Library, this can be done by doing:
    GET https://graph.microsoft.com/v1.0/sites/contoso.sharepoint.com/drives
    It seems that this endpoint doesn't accept the filter query parameter, so we should do an in code filter based on the libraryName option
  • The document ID of the SharePoint file, this can be done by doing:
    GET https://contoso.sharepoint.com/_api/web/GetFileByServerRelativePath(DecodedUrl=[File Url]) or just use the fileId option
  • The Sensitivity Label ID which should be applied, this can be done by doing:
    GET https://graph.microsoft.com/beta/security/informationProtection/sensitivityLabels, also here an in code filtering should be done based on the name property

Let's also add to the docs:

  • Attention: This command is based on an API that is currently in preview and is subject to change once the API reached general availability.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the m365 spo file sensitivitylabel ensure command requirements and review the listed SharePoint and Microsoft Graph endpoints, including setsensitivityLabel, drive lookup, and sensitivity-label lookup. Confirm how the documented list and file selectors map to these requests, then verify that labels can be applied by name or ID and that the preview-API warning is included in the documentation.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, cli, cloud
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
42/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.