0

I'm new using power automate.
I've seen posts to send emails to the users of a specific group in a SharePoint site. But what I need is to send an email to each user from all the groups that my site has.

I've made an HTTP request for every group in the site (I have 13 groups in my site), but my problem is that I don't know how to merge each of the JSON returned in a single array and then delete the duplicated users (because some people are in more than one group), so I can then send the emails to each one of the users in the final array.

enter image description here

Also I don't know if there is an easier method to avoid putting so many HTTP requests. As you can see in my image, my flow is already big and I don't think it would be good if it becomes bigger. Of course I won't care if nothing can be done to reduce this, as long as it works.

Thanks in advance!

1

Here are the steps you can try:

  1. Declare an array and initialize it with group ids like [2, 3, 4, 5]
  2. Declare a string variable to store all the emails (email1;email2;)
  3. Declare another string variable to store current email from JSON parse action
  4. Add "Apply to each" action to process group id array
  5. Within "Apply to each", add "Send an HTTP request to SharePoint" to process each group id, that is, sending id dynamically
  6. Add "Parse JSON" to parse the return users. See the schema later in my response.
  7. Add another "Apply to each" to process each user from step 6
  8. Collect user email and append it to the string variable declared in step 2 Here, you can use "contains()" function to remove duplicates
  9. Send email to the address collected in the string variable

See the screenshots below:

enter image description here enter image description here

Detail 1

enter image description here

JSON Schema (Detail 2)

{
    "type": "object",
    "properties": {
        "value": {
            "type": "array",
            "items": {
                "type": "object",
                "properties": {
                    "Email": {
                        "type": "string"
                    }
                },
                "required": [
                    "Email"
                ]
            }
        }
    }
}

Detail 3

enter image description here

3
  • I have a question. If I need to change the first step to use the names of the groups.. because some people find it easier to use the names instead of IDs, something like: ['group 1','group 2','group 3']. But when I change this it throws this error: The variable 'groupNames' only supports values of types 'Array'. Do you know how to put the array with string values? – Soul Eeater Sep 22 '20 at 22:42
  • Ah forget it, I realized that I have to write the array items with double quotes (") and then add single quotes (') around the current group name in the HTTP request. – Soul Eeater Sep 22 '20 at 23:14
  • Good to know that it has been resolved. Let me know if you still have questions – Matiur Rahman Sep 22 '20 at 23:19
1

You could get all the site users with the below rest api.

/_api/web/siteusers
3
  • The bad thing with this is that it's giving me the emails of "more people". I think they are people who have permissions on the tenant but I'm not really sure, as it's throwing emails of people who is not in any of my site's groups. – Soul Eeater Sep 21 '20 at 23:30
  • You could remove these users from your site. Every site has a hidden user information list. You could remove users from that list. URL of the hidden list: /_layouts/15/people.aspx?MembershipGroupId=0 – Michael Han_MSFT Sep 22 '20 at 7:41
  • Okay, so investigating a little I see that every time a person is invited to this site it will store his email in this hidden list, which complicates things. Because they will start receiving emails even when they aren't on my other groups. Unless there's a way to make Flows to ignore this hidden list. – Soul Eeater Sep 22 '20 at 22:27

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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