Microsoft Flow: Get the SharePoint GUID

Why?

In the Low-Code Power Platform default actions are covering by far the most business requirements. The SharePoint Connector gets new actions frequently but for the old-school SharePoint Designer Workflowers and for the REST Query fans the GUID of SharePoint objects is a must have.

What?

This post will show how to get some valuable GUID’s using the Send an HTTP request to SharePoint action. The SharePoint Rest Service has a lot of online documentation.

How?

The varWebUrl variable is one I use very often and is in format: https://[name of your tenant].sharepoint.com/sites/sitecollection-name/
Have a look at https://knowhere365.space/microsoft-flow-odata-filter-query/ for some expressions on how this variable can be dynamically set.

The variable varAcceptHeaderString is a default string I reuse when I create a flow with multiple HTTP requests: application/json;odata=verbose.

Get the GUID of a SharePoint Site

Example: I want to get the GUID of a SharePoint Site:

The code of the call:

_api/site

I’ll put the GUID in a variable by referencing the call:

The code of the variable:

@{body('Send_an_HTTP_request_to_SharePoint_-_GetSite')['d']['Id']}

A handy code to extract the Site URL part of the ServerRelativeUrl:

substring(body('Send_an_HTTP_request_to_SharePoint_-_GetSite')['d']['ServerRelativeUrl'],add(lastIndexOf(body('Send_an_HTTP_request_to_SharePoint_-_GetSite')['d']['ServerRelativeUrl'],'/'),1),sub(length(body('Send_an_HTTP_request_to_SharePoint_-_GetSite')['d']['ServerRelativeUrl']),add(lastIndexOf(body('Send_an_HTTP_request_to_SharePoint_-_GetSite')['d']['ServerRelativeUrl'],'/'),1)))

Get the GUID of a SharePoint List

Example: I want to get the GUID of a SharePoint List:

The code of the call:

_api/web/lists/GetByTitle('@{variables('varListTitle')}')

I’ll put the GUID in a variable by referencing the call:

The code of the variable:

@{body('Send_an_HTTP_request_to_SharePoint_-_GetList')['d']['Id']}

Get the ID of a SharePoint User

Example: I want to get a User ID of a person within a specific SharePoint Site Collection. This will only work if the person has logged on to the SharePoint Site collection of if that person account was selected in something like a people picker, share button, SharePoint Group etc. Anything that will place a user in the SharePoint Site Collection assigning it a unique Id in that specific SharePoint Site Collection.

The code of the call:

_api/web/SiteUsers/getByEmail('@{variables('varLoginName')}')

Get the ID of a SharePoint Group

Example: I want to get the Group ID of a SharePoint Group:

The code of the call:

_api/web/sitegroups/getByName('@{variables('varItemName')}')

I’ll put the Group ID in a variable by referencing the call:

The code of the variable:

@{body('Send_an_HTTP_request_to_SharePoint_-_GetGroup')['d']['Id']}

Get the ID of a Permission Level

Example: I want to get the Permission ID of a SharePoint Permission Level. The default levels have default ID’s but custom levels get their own ID. If you need this ID for quick reference the best way is to access the endpoint in a browser:

The url = https://[name of your tenant].sharepoint.com/sites/sitecollection-name/_api/web/roledefinitions/getbyname(‘Contribute’)
resulting in the output of Permission Id for Contribute being 1073741827:

<?xml version="1.0" encoding="utf-8"?><entry xml:base="https://devpvm.sharepoint.com/sites/group-contracts/_api/" xmlns="http://www.w3.org/2005/Atom" xmlns:d="http://schemas.microsoft.com/ado/2007/08/dataservices" xmlns:m="http://schemas.microsoft.com/ado/2007/08/dataservices/metadata" xmlns:georss="http://www.georss.org/georss" xmlns:gml="http://www.opengis.net/gml"><id>https://devpvm.sharepoint.com/sites/group-contracts/_api/Web/RoleDefinitions(1073741827)</id><category term="SP.RoleDefinition" scheme="http://schemas.microsoft.com/ado/2007/08/dataservices/scheme" /><link rel="edit" href="Web/RoleDefinitions(1073741827)" /><title /><updated>2019-09-16T13:24:19Z</updated><author><name /></author><content type="application/xml"><m:properties><d:BasePermissions m:type="SP.BasePermissions"><d:High m:type="Edm.Int64">432</d:High><d:Low m:type="Edm.Int64">1011028719</d:Low></d:BasePermissions><d:Description>Can view, add, update, and delete list items and documents.</d:Description><d:Hidden m:type="Edm.Boolean">false</d:Hidden><d:Id m:type="Edm.Int32">1073741827</d:Id><d:Name>Contribute</d:Name><d:Order m:type="Edm.Int32">64</d:Order><d:RoleTypeKind m:type="Edm.Int32">3</d:RoleTypeKind></m:properties></content></entry>

If you need this ID in your Flow:

The code of the call:

_api/web/roledefinitions/getbyname('@{variables('varPermissionName')}')/id

I’ll put the Group ID in a variable by referencing the call:

The code of the variable:

@{body('Send_an_HTTP_request_to_SharePoint_-_GetPermissionLevel')['d']['id']}

3 thoughts on “Microsoft Flow: Get the SharePoint GUID

Leave a comment