Announcements
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",
"Scope":270100000,
"TimeZone":null
}
-----------------------------------------------
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>" +
"</fetch>";
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
André Arnaud de Cal...
294,137
Super User 2025 Season 1
Martin Dráb
232,877
Most Valuable Professional
nmaenpaa
101,158
Moderator