How to update People field using ‘Send an HTTP request to SharePoint’ in Power Automate?

Problem

It is not a problem. The question is how to update a people field (single or multiple) in Power Automate using “Send an HTTP request to SharePoint” REST api?

To simplify the solution here are three fields in the SharePoint list. Let’s use a default template ‘When an item created’ trigger to update the first field OneApprover and MoreThanOneApprovers fields.

We have three test users

DebraB@GOV019539.OnMicrosoft.com
JohannaL@GOV019539.OnMicrosoft.com
BobK@GOV019539.OnMicrosoft.com
The above three test users will be added to the approvers.
In the above list the ‘OneApprover’ field is a people field and its ‘Allow multiple selection’ setting is NO.
For the ‘MoreThanOneApprovers’ people field the ‘Allow multiple selection’ is YES

Step by Step solution

There is two step process, first to get IDs of the users by email ID and second to send the POST request to update the people field.

Step # 1

First get the ID of the user by email and Compose the value to use in the later step.

Use the following in the “Uri” field, note the email address and select of an ID.

NOTE: Please use Scope so that you can combine all the repetitive actions in one to get IDs.

_api/web/SiteUsers/getByEmail('DebraB@GOV019539.OnMicrosoft.com')?$select=Id
Note: Output of the above action will be following. We need to access the 'Id' value.

{
  "d": {
    "__metadata": {
      "id": "https://gov019539.sharepoint.com/sites/test/_api/Web/GetUserById(9)",
      "uri": "https://gov019539.sharepoint.com/sites/test/_api/Web/GetUserById(9)",
      "type": "SP.User"
    },
    "Id": 9
  }
}
Note: to access the Id value we will use the following formula in the Compose

body('Send_an_HTTP_request_to_SharePoint_to_get_Id_for_Debra')?['d']?['Id']

Step # 2

Now that we have an IDs of all there users we can call the POST method to update the two fields in the list.

Note: In the Uri field you will provide the following. This will invoke the call for the current list item,

_api/web/lists/GetByTitle('PeopleFieldDemo')/items('@{triggerBody()?['ID']}')

Note: In the headers section you will provide the following json.
TIP: click on the “T” circled as res to get in the text mode to copy and paste.


{
"content-type": "application/json;odata=verbose",
"IF-MATCH": "*",
"X-HTTP-Method": "MERGE"
}

Now very important step i.e. to update people field.

Notes:

1: Update the list name from ‘PeopleFieldDemo’ to your list name.
2: The Compose outputs are IDs of the users. They are typically an integer values. You need to put your values.
3: Please make a note the single field is just assign one value with multiple it is an array
4: Notice the field name “OnePrrover” and “MoreThanIneApprover” there is a “Id” suffix.

{
"__metadata": {
"type":"SP.Data.PeopleFieldDemoListItem"
},

"OneApproverId": @{outputs('ComposeIdForDebra')},

"MoreThanOneApproversId": {
"results": [
@{outputs('ComposeIdForJohanna')},
@{outputs('ComposeIdForBob')}
]
}
}

Result

The output of the list item will look like this in my case the IDs I have assigned.

The output of the flow ran.
SHAREPOINT REST WALL PAPERhttps://www.microsoft.com/en-us/download/details.aspx?id=41147
Use the above link to download the SharePoint Wall paper to explore more REST calls.

About Pankaj

I am a Developer and my linked profile is https://www.linkedin.com/in/pankajsurti/
This entry was posted in Power Automate, Uncategorized. Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s