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.
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.
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
{ "type": "array", "items": { "type": "string", "title": "memberId" } }
{ "type": "object", "properties": { "baseEntityLogicalName": { "type": "string" }, "primaryKeyColumnName": { "type": "string" }, "members": { "type": "array", "items": { "type": "string" } }, "additionalProperties": { "type": "object", "properties": {} } } }
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 thankyou to the segment builder for helping you!
All together now!
In case you got lost, this start to end flow view might help.