3,270 total views, 11 views today
In this “Apply sensitivity label in SharePoint” article, we will learn how to apply a sensitivity label in SharePoint using the postman tool. Here we have assumed that you have a basic understanding of what is a sensitivity label and how to apply it to the Microsoft Office file (like Word, Excel, PPT, etc).
In simple words, a sensitivity label is a data classification like Public, Confidential, Highly Confidential, etc.
Sensitivity labels in SharePoint online (Apply sensitivity label in SharePoint)
To know more about the data classification & sensitivity label, you may look at the below articles:
Now, let’s get back to the context of this article. In the previous article, we have learned how to get and copy the bearer token value from Sharepoint – in this article, we will learn how to use that bearer token value in the postman tool to do a post-operation in SharePoint Online, here as an example we will use how to apply a sensitivity label using the SharePoint API.
Apply sensitivity labels to SharePoint site (sensitivity labels in sharepoint online)
Here is the SharePoint API which we will use for applying the sensitivity label:
API Syntax:
https://yourspositeURL/_api/v2.1/drives/DocumentLibraryID/items/DocumentID/setsensitivityLabel
Example:
https://globalsharepoint2020.sharepoint.com/_api/v2.1/drives/b!_gbrdwjBJUi-RT40bK2ugHGZ7QDqj1RFnI_Q4lVGhqmtoFYS9HieT5Rl6tvwhWR2/items/0A5D5112-B937-4246-8339-85E4795A0A65/setsensitivityLabel
Notes:
- Here the site URL is – the site where your document is hosted.
- Get the Document library ID from this article – Get Document Library ID using SharePoint API
- To get the document or file ID follow the below steps.
How to get the Document ID in SharePoint Online (sensitivity labels in SharePoint online)?
We just, need to open the document for which we want to apply the sensitivity label in the browser. For an example, below:

Notes:
- Note down the URL, and the URL will look like below:
https://globalsharepoint2020.sharepoint.com/:w:/r/_layouts/15/Doc.aspx?sourcedoc=%7B0A5D5112-B937-4246-8339-85E4795A0A65%7D&file=My%20Test%20File.docx&action=default&mobileredirect=true&cid=5743bcd3-c190-4c31-96a8-44194bcab7d2
- In the URL, we can see one of the query string parameters is the “sourcedoc” which is in an encoded format, we need to decode it (sourcedoc=%7B0A5D5112-B937-4246-8339-85E4795A0A65%7D).
- Using the Online tool like URL Decoder/Encoder, we can decode it, after decoding the “sourcedoc” value will be like “0A5D5112-B937-4246-8339-85E4795A0A65“
- So, by now we got the document ID also.
- And the right topmost corner, we can see there are two sensitivity labels to this location, and we can apply any of them – at present this document has not been applied with any sensitivity labels. In this demo, we will apply the “Confidential Test – Label” to this document.
By now we have all the needed parameters for this sensitivity label API like:
- Site URL – https://globalsharepoint2020.sharepoint.com
- Document Library ID – b!_gbrdwjBJUi-RT40bK2ugHGZ7QDqj1RFnI_Q4lVGhqmtoFYS9HieT5Rl6tvwhWR2
- Document ID – 0A5D5112-B937-4246-8339-85E4795A0A65
One more thing we need to get is the sensitivity label ID the one which we are going to apply. We can get the sensitivity label ID using this article – Get sensitivity labels using PowerShell script.
For this demo, the sensitivity label ID is: 90ebdb98-631f-453a-bf00-6f388e5b5206 (Confidential Test – Label).
Now, everything is ready, we are ready to go for postman execution.
Let’s launch the postman tool.
Select the operation as “POST”
Pass the Sensitivity Label API URL like below:
https://globalsharepoint2020.sharepoint.com/_api/v2.1/drives/b!_gbrdwjBJUi-RT40bK2ugHGZ7QDqj1RFnI_Q4lVGhqmtoFYS9HieT5Rl6tvwhWR2/items/0A5D5112-B937-4246-8339-85E4795A0A65/setsensitivityLabel

Header Configuration should be as below:
Authorization – Bearer
Accept – application/json;odata=verbose
Content-Type – application/json;odata=verbose
Now, let’s configure the Body of the API:

In the body of the API pass the below:
Note:
- In the above, the “id” is the sensitivity label id parameter which is mandatory rest of other parameters are optional. We have got this sensitivity label ID (90ebdb98-631f-453a-bf00-6f388e5b5206 (Confidential Test – Label)) in the above step which we are going to apply to the particular document.
Then let’s configure the authorization section for this API.

Click on the “Authorization” tab.
From the type of Authorization, select the “Bearer Token”.
And in the Token Text Box, place or paste the bearer token value that we got referring to this article – How to get Bearer Token For SharePoint?.
Finally, click on the “Send” button.

We can see the status as “200 Ok” which means, this API has been executed successfully.
Now, if we open the particular file from the SharePoint document library we can see that the “Confidential Test – Label” has been applied to this document which was not there before executing the API from the postman tool.

Notes:
- Sometimes, we might get a token expiration error like the one below from the postman tool, in this case, we need to generate the token value freshly and pass it to the postman authorization configuration.
{“error”:{“code”:”unauthenticated”,”innerError”:{“code”:”expiredToken”},”message”:”The access token has expired. It’s valid from ‘4/17/2022 5:31:52 AM’ and to ‘4/17/2022 6:31:52 AM’.”}}
- And sometimes, we might get a document lock state error while applying the sensitivity label, in this case, we need to close the document from the browser.
Summary: what did we have here in – Apply sensitivity label in SharePoint (sensitivity labels SharePoint site)?
Thus, in this article, we have learned how to apply the sensitivity label in the document stored in the SharePoint document library using the postman tool and SharePoint API.
See Also: Sensitivity labels in SharePoint online (apply sensitivity labels to SharePoint site)
You might be interested in the following sensitivity & postman tool-related articles:
- How to get Bearer Token For SharePoint?
- Get Document Library ID using SharePoint API
- Get sensitivity labels using PowerShell script
- Enable Sensitivity label for Groups, Sites & Teams
- In 4 steps access SharePoint online data using postman tool