List Segment Members from Customer Insights – Journeys in Power Automate

Once you work out how to wrangle with segments in the new ‘real-time marketing’ segment builder for in Dynamics 365 Marketing (Customer Insights – Journeys) you can build some seriously impressive and complex data queries for Leads or Contacts stored in Dynamics 365 Dataverse.

Using Real-time Segments in Power Automate

Why not just use FetchXML you muggle?!

Segments can query data up to 5 hops away from the Lead or Contact record; ‘behavioural’ interaction data (email sends, opens and clicks; page views; form views and fills) which is not stored in Dataverse; and marketing specific data such as compliance, consent and topics which are not directly related to contacts/leads. By building the query in Customer Insights – Journeys, you are giving power to the users and marketers to control the data that feeds your automations, instead of hiding the queries behind code and configuration.

Official developer docs on working with segments here. How to create and publish segments with Power Automate here.

NOTE: This blog focuses on real-time marketing segments.

Use case: Perform a bulk update or deletion of Contacts who have Hard Bounced one or more marketing emails.

A hard bounce is an email that has been sent to an invalid mailbox or an invalid domain. This means that the recipient’s email address or the domain doesn’t exist.

The interaction data for email delivery is super valuable in helping to clean up your data. A hard bounced email is a clear indicator for an invalid email address. It would be great to use this to identify Contacts which can be either unsubscribed, deleted or updated to protect the sender reputation of your domain and also to give a clearer view on conversion rates. Which sound like a great job for Power Automate!

Prepare your Segment

The segment query is entirely up to you but for the purposes of this example lets have a segment for all Contacts who have had a Hard Bounced (real-time marketing) email in the last 3 months. Select ‘Bounced’ from the Behavioural tab on the segment builder. If you select the Group, you can then add filtering attributes for the bounce interaction. Add a filter for Bounce Type to be ‘Hard’. Remove the condition for ‘Email’ as we want this segment to apply to all emails/journeys. See image below.

A segment for contacts who have Hard Bounced one or more marketing emails

Then, edit the interaction timeframe to your needs, for example ‘At least once in the last 3 months’.

Ensure your segment is marked ‘Ready to use’ and then find the Virtual Segment (msdynmkt_virtualsegment) ID as shown below to pass into the flow.

Build a Power Automate Flow

I’m going to let you work out for yourself how this process is triggered, it might be a schedule, a custom page or an automated process the main thing is that you need to provide the Virtual Segment ID (msdynmkt_virtualsegment). if you select a segment from the segment view you are seamlessly taken to either msdynmkt_segmentdefinition or msdyncrm_segment depending on if the segment is from outbound or real-time marketing, but if you right click and open in a new tab, you will get the virtual segment record – this is the ID you need to return the segment members in Power Automate.

How to find the virtual segment (msdynmkt_virtualsegment) ID

Manually trigger a flow – Flow button for mobile

For the purposes of this demo we will manually trigger the flow and pass in the Virtual Segment ID as a text input ‘Virtual Segment GUID’.

Invoke an HTTP request – HTTP with Microsoft Entra ID (preauthorized)

Name: GetSegmentMembers
Method: POST
Url of request: https://orgname.crm6.dynamics.com/api/data/v9.0/msdynmkt_MembersList
Body of the request:

{ "SegmentId": "[Virtual Segment GUID]"}

If you haven’t used this connector before you will need to create the connection, you just need to use your dynamics 365 base URL in both boxes like below

Parse JSON – Data Operation for memberIDs

This action parses the HTTP Request outputs so that you can get the array of Contact or Lead GUIDs, know as ‘memberID’Name: ParseMembers
Content: json(body(‘GetSegmentMembers’)?[‘ResultText’])?[‘members’]
Schema:

{
    "type": "array",
    "items": {
        "type": "string",
        "title": "memberId"
    }
}

Apply to Each – Control & Compose – Data Operation

In terms of what you do with the Lead or Contact GUIDs that’s up to you but this shows you how you can create an Apply to each and loop through each segment member to apply an automation (such as delete, update etc.)

A sample output from the apply to each action, just a lovely little GUID looking for a job to do.

Parse JSON – Data Operation for the full HTTP Request outputs

There are a few more bits of information that are returned other than the member ID array so using this Parse JSON action you can easily extract that information too.

Name: ParseResults
Content: json(body(‘GetSegmentMembers’)?[‘ResultText’])
Schema:

{
    "type": "object",
    "properties": {
        "baseEntityLogicalName": {
            "type": "string"
        },
        "primaryKeyColumnName": {
            "type": "string"
        },
        "members": {
            "type": "array",
            "items": {
                "type": "string"
            }
        },
        "additionalProperties": {
            "type": "object",
            "properties": {}
        }
    }
}

Additional properties available from the ‘ParseResults’ action

Manually test your flow

Using the virtual segment ID you identified earlier, you can manually test the flow to return the segment members.

That’s it – done!. Now go clean up your dodgy data and say thank you to the segment builder for helping you!

All together now!

In case you got lost, this start to end flow view might help.

And if it doesn’t help please send all complaints to cleo@ameyholden.com 🐶

About the Author

A proud Microsoft Most Valuable Professional and dedicated ABC (Anything But Code) enthusiast. I am passionate about extending and improving Dynamics Customer Engagement & Marketing with the mighty Power Platform.

I’m an active and energetic member of the Microsoft community. The helpfulness, engagement and support I get from the Microsoft family is what inspires me to give back.

Read more.

References

Holden, A., (2024), ‘List Segment Members from Customer Insights – Journeys in Power Automate’, available at: https://www.ameyholden.com/articles/use-realtime-segment-membership-power-automate-dynamics-365 [accessed 25th March 2024].

Share this on...

Rate this Post:

Share: