0

Using SOAP Services, we used to be able to add multiple items in a list that contains a people field just using the email address and without knowing the user id. In that case the value to provide was -1;#email@address.

Example of a SOAP body to send:

<Field Name='ID'>New</Field><Field Name='Title'>Example</Field><Field Name='Name'>-1;#[email protected]</Field></Method>

It was very handy because we could add 50 items in 1 call.

I'm trying to do the same thing in SharePoint Online, without using SOAP services. It could be either REST or Graph.

So far I found that I need to first use ensureUser to get the user id for each email address, and then add the items using that user id… So instead of doing 1 call to add 50 items, I have to do 50 calls to get the user id, and then 50 more calls to add them (I may reduce the number of calls using the $batch but I'm not sure it can work with ensureUser).

Is there any other way to directly add a user using an email address to SPO?

1 Answer 1

0

If users you are trying to add to people field are already added to your SharePoint site (collection), you can use below API call to get all users & their email/user id using single API call:

https://<tenant>.sharepoint.com/sites/<siteName>/_api/web/siteusers?$select=Title,Email,Id

You can compare the email addresses you have with the response from above API call & get the user IDs you need for next API call.

If you don't find any user (email address) in the response from above API call, you have to use the ensureUser() method to add particular user to SharePoint site ("User Information List").


After getting all user IDs you need, you can set people field with multiple users using single API call like below:

  • Considering field name is AssignedTo, the format for people field value in your payload should be like:
data: JSON.stringify({
        "__metadata": { type: "SP.Data.PostsListItem" },
        "AssignedToId": { 'results': [1, 2, 3] }
      })

Where 1, 2, 3 are ID of users.

For more information on this, check my answer given at: Update People picker column using REST API in Power Automate

2
  • Thanks. It's not multiple users in one field, but 1 user by entry. With 150,000 entries (with unique users) to add in a list. They are not in the SiteUsers list yet… I ended using the SOAP service to do it. Quick & easy.
    – AymKdn
    Aug 5, 2021 at 10:34
  • If you are trying to create multiple entries/rows in list, you have to batch the multiple requests to add/update the entries in list. Aug 5, 2021 at 10:50

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.