How to get Purview GUID from Office365 Graph API?

166 Views Asked by At

I'm using the Microsoft Graph API to process a bunch of files and emails from Office365 (OneDrive, Sharepoint, Exchange Online).

This works well, fetching the OneDrive records via https://learn.microsoft.com/en-us/graph/api/driveitem-list-children?view=graph-rest-1.0&tabs=http = https://graph.microsoft.com/v1.0/drives/{drive_id}/items/{dir_id}/children. No problem there.

But now I need to assign a Purview label to some of these items using the Purview API: https://learn.microsoft.com/en-us/rest/api/purview/catalogdataplane/entity/add-label?tabs=HTTP

All the Purview API documentation talks about "guid – The globally unique identifier of the entity" as input, to specify which document I want to assign the label to. How do I get that guid?

I don't see any "guid" attribute in my OneDrive responses. To be honest I got completely lost in the infinite indirections and IDs of the Microsoft API.

How do Graph API responses relate to Purview GUIDs?

1

There are 1 best solutions below

2
user2250152 On

Not sure whether it's the same, but the Graph API beta allows you to set retention label on driveItem

PATCH beta/drives/{drive-id}/items/{id}/retentionLabel

Probably, you don't need to call Purview API.

If you want apply a label using Purview API, parse GUID from eTag property of the driveItem.

Resource:

Apply retention policy