Skip to main content



No record found.

Customer Insights - Journeys forum
Suggested answer

Filter Members in Segment

Posted on by 25

Dears, I am using below code to get Segment members but how can I apply filter on it? I tried to add condition in the fetchXML but it neglected it as if it doesn't exist. I even tried to add .FILTER() on the query but it returned an error that query is not correct. 

Eventually, I need to get all segments where current contact is part of, but my segments are dynamic not static so they are changing every while.


Retrieve segment members (recommended)

POST {{OrgUrl}}/api/data/v9.0/msdyncrm_FetchContactsByQuery
    "Query":"(SEGMENT(SEGMENT_CRM_ID_e1fa7fdc5c78ea11a811000d3a8e8fcc)).ORDERBY(fullname ASC).SKIP(0).TAKE(15).SELECT(contactid)",
    "FetchXml":"<fetch version=\"1.0\" output-format=\"xml-platform\" mapping=\"logical\" count=\"15\" page=\"1\" returntotalrecordcount=\"true\"><entity name=\"contact\"><attribute name=\"fullname\"/><attribute name=\"emailaddress1\"/><attribute name=\"company\"/><attribute name=\"parentcustomerid\"/><attribute name=\"contactid\"/><order attribute=\"fullname\" descending=\"false\"/></entity></fetch>","OwningBusinessUnit":"0b4b85cc-7f6c-ea11-a811-000d3a54d359",
  • Suggested answer
    Community member Profile Picture
    Community member 10 on at
    Filter Members in Segment
    Hi Sohs,

    The approach you are using is for Outbound segments it won't work for real time segments.

    For outbound segment :- The issue in your fetchxml seems is SEGMENT_CRM_ID_e1fa7fdc5c78ea11a811000d3a8e8fcc, you need to retrieve this seg id from the record and put in a variable according to the format.

    for realtime segments :- you can refer to the below link.
  • Suggested answer
    Sayen Zhang Profile Picture
    Sayen Zhang on at
    RE: Filter Members in Segment

    Hi Soha,

    According to your first question: how to use code to get segment members, you can refer to this fetch xml:

    <fetch version=\"1.0\" output-format=\"xml-platform\" mapping=\"logical\">" +

                "<entity name=\"contact\">" +

                "<attribute name=\"fullname\"/>" +

                "<attribute name=\"emailaddress1\"/>" +

                "<attribute name=\"company\"/>" +

                "<attribute name=\"parentcustomerid\"/>" +

                "<attribute name=\"contactid\"/>" +

                "<order attribute=\"fullname\" descending=\"false\"/>" +

                "</entity>" +


    You can also refer to this link: FetchXml to retrieve segment member - Dynamics 365 Marketing Forum Community Forum

    In additional, it is available for us to add http that you offered in power automate flow to get contacts, please refer to this link: How are Segments and Contacts related - I want to loop though contacts that are part of an segment with power automate - Dynamics 365 Marketing Forum Community Forum


    According to your second question, we can use “Web API” to get all segments where contact is part of no matter dynamic or static. Here are the steps that you can followed:

    1. Go to Power Apps home page.

    2. Click gear to select session details.

    3. Copy Instance URL.

    4. Enter the URL before “/api/data/v9.0/msdyncrm_segments”.


    5. If segments where contact is not part of, contact is not contained in segment’s profile.


    If you have any questions, you can also reply to let us know. Thank you!


    Best Regards,

    Sayen Zhang

Helpful resources

Quick Links

Replay now available! Dynamics 365 Community Call (CRM Edition)

Catch up on the first D365 Community Call held on 7/10

Community Spotlight of the Month

Kudos to Saurav Dhyani!

Congratulations to the June Top 10 community leaders!

These stars go above and beyond . . .


André Arnaud de Calavon Profile Picture

André Arnaud de Cal... 287,696 Super User

Martin Dráb Profile Picture

Martin Dráb 225,490 Super User

nmaenpaa Profile Picture

nmaenpaa 101,148


Featured topics

Product updates

Dynamics 365 release plans