azuremicrosoft-graph-apimicrosoft-information-protection

Graph API: How do I get sensitivityLabel list using graph api


I'm trying to get sensitivityLabel list using graph API. I'm working on Graph Explorer to get proper REST url first.

https://learn.microsoft.com/en-us/graph/api/security-informationprotection-list-sensitivitylabels?view=graph-rest-beta&tabs=http

I look through this guid and tried several url but failed.

I got failed with these urls.

https://graph.microsoft.com/v1.0/security/informationProtection/sensitivityLabels
https://graph.microsoft.com/beta/users/me/security/informationProtection/sensitivityLabels

These are the error response

"error": {
    "code": "BadRequest",
    "message": "Resource not found for the segment 'informationProtection'.",
    "innerError": {
        "date": "2024-07-19T08:15:31",
        "request-id": "cb4a1134-b2af-4e74-9337-e65e142777c9",
        "client-request-id": "c7385ff6-bf4c-e989-3754-1b1a4e9bcba9"
    }
}
"error": {
    "code": "UnknownError",
    "message": "",
    "innerError": {
        "date": "2024-07-19T08:16:27",
        "request-id": "54ad97bd-8b45-44eb-a129-6a9a09e6eff7",
        "client-request-id": "7c3347bd-9dc6-ceca-9fd5-e12757890a3a"
    }
}

Please suggest.


Solution

  • Initially, I too got errors when I ran those URLs in my environment like this:

    GET https://graph.microsoft.com/v1.0/security/informationProtection/sensitivityLabels
    

    enter image description here

    GET https://graph.microsoft.com/beta/users/me/security/informationProtection/sensitivityLabels
    

    enter image description here

    To get sensitivityLabel list using graph API, the correct URLs should be

    GET https://graph.microsoft.com/beta/me/security/informationProtection/sensitivityLabels
    

    Response:

    enter image description here

    GET https://graph.microsoft.com/beta/users/userID/security/informationProtection/sensitivityLabels
    

    Response:

    enter image description here