New command: Apply a sensitivity label to a file
Nobody has claimed this yet.
- 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 thelibraryNameoption - 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 thefileIdoption - 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 thenameproperty
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
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- 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