Get Marketing List members details. Active marketing list data you can see in crm from sales >> marketing list.
Soap query for getting all list:
URL: http://mcc.enfusen.com/crm-api/list/
$xml =”<s:Body>”;
$xml .=”<Execute xmlns=\”http://schemas.microsoft.com/xrm/2011/Contracts/Services\” xmlns:i=\”http://www.w3.org/2001/XMLSchema-instance\”>”;
$xml .=”<request i:type=\”a:RetrieveMultipleRequest\” xmlns:a=\”http://schemas.microsoft.com/xrm/2011/Contracts\”>”;
$xml .=”<a:Parameters xmlns:b=\”http://schemas.datacontract.org/2004/07/System.Collections.Generic\”>”;
$xml .=”<a:KeyValuePairOfstringanyType>”;
$xml .=”<b:key>Query</b:key>”;
$xml .=”<b:value i:type=\”a:QueryExpression\”>”;
$xml .=”<a:ColumnSet>”;
$xml .=”<a:AllColumns>true</a:AllColumns>”;
$xml .=”<a:Columns xmlns:c=\”http://schemas.microsoft.com/2003/10/Serialization/Arrays\”>”;
// $xml .=”<c:string>listname</c:string>”;
// $xml .=”<c:string>query</c:string>”;
// $xml .=”<c:string>listid</c:string>”;
$xml .=”</a:Columns>”;
$xml .=”</a:ColumnSet>”;
$xml .= “<a:Criteria>”;
$xml .= “<a:Conditions />”;
// $xml .= “<a:ConditionExpression >”;
// $xml .= “<a:AttributeName>statuscode</a:AttributeName>”;
// $xml .= “<a:Operator>Equal</a:Operator>”;
// $xml .= “<a:Values xmlns:c=\”http://schemas.microsoft.com/2003/10/Serialization/Arrays\”>”;
// $xml .= “<c:anyType i:type=\”d:string\” xmlns:d=\”http://www.w3.org/2001/XMLSchema\”>0</c:anyType>”;
// $xml .= “</a:Values>”;
// $xml .= “</a:ConditionExpression>”;
// $xml .= “</a:Conditions>”;
$xml .= “<a:FilterOperator>And</a:FilterOperator>”;
$xml .= “<a:Filters />”;
$xml .= “</a:Criteria>”;
$xml .=”<a:Distinct>false</a:Distinct>”;
$xml .=”<a:EntityName>list</a:EntityName>”;
$xml .=”<a:LinkEntities />”;
$xml .=”<a:Orders />”;
$xml .=”<a:PageInfo>”;
$xml .=”<a:Count>0</a:Count>”;
$xml .=”<a:PageNumber>0</a:PageNumber>”;
$xml .=”<a:PagingCookie i:nil=\”true\” />”;
$xml .=”<a:ReturnTotalRecordCount>false</a:ReturnTotalRecordCount>”;
$xml .=”</a:PageInfo>”;
$xml .=”<a:NoLock>false</a:NoLock>”;
$xml .=”</b:value>”;
$xml .=”</a:KeyValuePairOfstringanyType>”;
$xml .=”</a:Parameters>”;
$xml .=”<a:RequestId i:nil=\”true\” />”;
$xml .=”<a:RequestName>RetrieveMultiple</a:RequestName>”;
$xml .=”</request>”;
$xml .=”</Execute>”;
$xml .=”</s:Body>”;
It will return soap response of marketing list in CRM.
Select any marketing list and you will find list members associated to list. Basically members are not related to a single entity, it could be Lead, Contact, Account entities and type of static of dynamics.
Getting static list types are straight than getting dynamic list types. Here you can see select list is lead and dynamic type. It means that members listed for list are dynamic.
Get list detail and check list is dynamic or static and targeted entity of lead using example soap:
URL: http://mcc.enfusen.com/crm-api/members/?lid=6e9d5016-6a35-e611-80e0-5065f38a4b71
$xml =”<s:Body>”;
$xml .=”<Execute xmlns=\”http://schemas.microsoft.com/xrm/2011/Contracts/Services\” xmlns:i=\”http://www.w3.org/2001/XMLSchema-instance\”>”;
$xml .=”<request i:type=\”a:RetrieveMultipleRequest\” xmlns:a=\”http://schemas.microsoft.com/xrm/2011/Contracts\”>”;
$xml .=”<a:Parameters xmlns:b=\”http://schemas.datacontract.org/2004/07/System.Collections.Generic\”>”;
$xml .=”<a:KeyValuePairOfstringanyType>”;
$xml .=”<b:key>Query</b:key>”;
$xml .=”<b:value i:type=\”a:QueryExpression\”>”;
$xml .=”<a:ColumnSet>”;
$xml .=”<a:AllColumns>false</a:AllColumns>”;
$xml .=”<a:Columns xmlns:c=\”http://schemas.microsoft.com/2003/10/Serialization/Arrays\”>”;
$xml .=”<c:string>query</c:string>”;
$xml .=”<c:string>membertype</c:string>”;
$xml .=”</a:Columns>”;
$xml .=”</a:ColumnSet>”;
$xml .= “<a:Criteria>”;
$xml .= “<a:Conditions>”;
$xml .= “<a:ConditionExpression>”;
$xml .= “<a:AttributeName>listid</a:AttributeName>”;
$xml .= “<a:Operator>Equal</a:Operator>”;
$xml .= “<a:Values xmlns:c=\”http://schemas.microsoft.com/2003/10/Serialization/Arrays\”>”;
$xml .= “<c:anyType i:type=\”d:string\” xmlns:d=\”http://www.w3.org/2001/XMLSchema\”>”.$listid.”</c:anyType>”;
$xml .= “</a:Values>”;
$xml .= “</a:ConditionExpression>”;
$xml .= “</a:Conditions>”;
$xml .= “<a:FilterOperator>And</a:FilterOperator>”;
$xml .= “<a:Filters />”;
$xml .= “</a:Criteria>”;
$xml .=”<a:Distinct>false</a:Distinct>”;
$xml .=”<a:EntityName>list</a:EntityName>”;
$xml .=”<a:LinkEntities />”;
$xml .=”<a:Orders />”;
$xml .=”<a:PageInfo>”;
$xml .=”<a:Count>0</a:Count>”;
$xml .=”<a:PageNumber>0</a:PageNumber>”;
$xml .=”<a:PagingCookie i:nil=\”true\” />”;
$xml .=”<a:ReturnTotalRecordCount>false</a:ReturnTotalRecordCount>”;
$xml .=”</a:PageInfo>”;
$xml .=”<a:NoLock>false</a:NoLock>”;
$xml .=”</b:value>”;
$xml .=”</a:KeyValuePairOfstringanyType>”;
$xml .=”</a:Parameters>”;
$xml .=”<a:RequestId i:nil=\”true\” />”;
$xml .=”<a:RequestName>RetrieveMultiple</a:RequestName>”;
$xml .=”</request>”;
$xml .=”</Execute>”;
$xml .=”</s:Body>”;
For getting member details, first you need to check members type and make call to targeting entity accordingly. Example code
$membertype=$leadDetails[“membertype”];
$xml=””;
switch ($membertype) {
case 1:
echo “Entity Type : Company “;
$xml=CompanyXml($leadDetails, $listid);
break;
case 2:
echo “Entity Type : Contact “;
$xml=ContactXml($leadDetails , $listid);
break;
case 4:
echo “Entity Type : Lead “;
$xml=LeadXml($leadDetails, $listid);
break;
default:
echo “Member type does not match with a any CRM entity”;
break;
}
Soap for getting list members are bit different for both static and dynamic types. For static list members you can create fetchXml query manually. For example:
$query=”<fetch distinct=’true’ mapping=’logical’ output-format=’xml-platform’ version=’1.0′><entity name=’account’><attribute name=’name’/><attribute name=’primarycontactid’/><attribute name=’telephone1’/><attribute name=’accountid’/><order descending=’false’ attribute=’accountnumber’/><link-entity name=’listmember’ intersect=’true’ visible=’false’ to=’accountid’ from=’entityid’><link-entity name=’list’ to=’listid’ from=’listid’ alias=’ag’><filter type=’and’><condition attribute=’listid’ value='”.$listid.”‘ operator=’eq’/></filter></link-entity></link-entity></entity></fetch>”;
$fetchXml .=$query;
$query = str_replace(‘<‘, ‘<’, $query);
$query = str_replace(‘>’, ‘>’, $query);
$xml .= “<s:Body>”;
$xml .= “<Execute xmlns=\”http://schemas.microsoft.com/xrm/2011/Contracts/Services\” xmlns:i=\”http://www.w3.org/2001/XMLSchema-instance\”>”;
$xml .= ” <request i:type=\”a:RetrieveMultipleRequest\” xmlns:a=\”http://schemas.microsoft.com/xrm/2011/Contracts\”>”;
$xml .= ” <a:Parameters xmlns:b=\”http://schemas.datacontract.org/2004/07/System.Collections.Generic\”>”;
$xml .= ” <a:KeyValuePairOfstringanyType>”;
$xml .= ” <b:key>Query</b:key>”;
$xml .= ” <b:value i:type=\”a:FetchExpression\”>”;
$xml .=” <a:Query>”.$query.”</a:Query>”;
$xml .= ” </b:value>”;
$xml .= ” </a:KeyValuePairOfstringanyType>”;
$xml .= ” </a:Parameters>”;
$xml .= ” <a:RequestId i:nil=\”true\” />”;
$xml .= ” <a:RequestName>RetrieveMultiple</a:RequestName>”;
$xml .= ” </request>”;
$xml .= ” </Execute>”;
$xml .= ” </s:Body>”;
For dynamic types, Microsoft dynamics crm stores dynamic query in query field of CRM list. So you can build FetchXML query like this.
$query=$leadDetails[“query”];
$fetchXml .=$query;
$query = str_replace(‘”‘, ‘\”, $query);
$query = str_replace(‘<‘, ‘<’, $query);
$query = str_replace(‘>’, ‘>’, $query);
$xml .= “<s:Body>”;
$xml .= “<Execute xmlns=\”http://schemas.microsoft.com/xrm/2011/Contracts/Services\” xmlns:i=\”http://www.w3.org/2001/XMLSchema-instance\”>”;
$xml .= ” <request i:type=\”a:RetrieveMultipleRequest\” xmlns:a=\”http://schemas.microsoft.com/xrm/2011/Contracts\”>”;
$xml .= ” <a:Parameters xmlns:b=\”http://schemas.datacontract.org/2004/07/System.Collections.Generic\”>”;
$xml .= ” <a:KeyValuePairOfstringanyType>”;
$xml .= ” <b:key>Query</b:key>”;
$xml .= ” <b:value i:type=\”a:FetchExpression\”>”;
$xml .=” <a:Query>”.$query.”</a:Query>”;
$xml .= ” </b:value>”;
$xml .= ” </a:KeyValuePairOfstringanyType>”;
$xml .= ” </a:Parameters>”;
$xml .= ” <a:RequestId i:nil=\”true\” />”;
$xml .= ” <a:RequestName>RetrieveMultiple</a:RequestName>”;
$xml .= ” </request>”;
$xml .= ” </Execute>”;
$xml .= ” </s:Body>”;
Response of this soap return list members for targeted entity.
Based on targeting entity and ID you can get details like:
Contact:
Soap XML:
$xml =”<s:Body>”;
$xml .=”<Execute xmlns=\”http://schemas.microsoft.com/xrm/2011/Contracts/Services\” xmlns:i=\”http://www.w3.org/2001/XMLSchema-instance\”>”;
$xml .=”<request i:type=\”a:RetrieveMultipleRequest\” xmlns:a=\”http://schemas.microsoft.com/xrm/2011/Contracts\”>”;
$xml .=”<a:Parameters xmlns:b=\”http://schemas.datacontract.org/2004/07/System.Collections.Generic\”>”;
$xml .=”<a:KeyValuePairOfstringanyType>”;
$xml .=”<b:key>Query</b:key>”;
$xml .=”<b:value i:type=\”a:QueryExpression\”>”;
$xml .=”<a:ColumnSet>”;
$xml .=”<a:AllColumns>true</a:AllColumns>”;
$xml .=”<a:Columns xmlns:c=\”http://schemas.microsoft.com/2003/10/Serialization/Arrays\”>”;
// $xml .=”<c:string>query</c:string>”;
// $xml .=”<c:string>membertype</c:string>”;
$xml .=”</a:Columns>”;
$xml .=”</a:ColumnSet>”;
$xml .= “<a:Criteria>”;
$xml .= “<a:Conditions>”;
$xml .= “<a:ConditionExpression>”;
$xml .= “<a:AttributeName>contactid</a:AttributeName>”;
$xml .= “<a:Operator>Equal</a:Operator>”;
$xml .= “<a:Values xmlns:c=\”http://schemas.microsoft.com/2003/10/Serialization/Arrays\”>”;
$xml .= “<c:anyType i:type=\”d:string\” xmlns:d=\”http://www.w3.org/2001/XMLSchema\”>”.$contactid.”</c:anyType>”;
$xml .= “</a:Values>”;
$xml .= “</a:ConditionExpression>”;
$xml .= “</a:Conditions>”;
$xml .= “<a:FilterOperator>And</a:FilterOperator>”;
$xml .= “<a:Filters />”;
$xml .= “</a:Criteria>”;
$xml .=”<a:Distinct>false</a:Distinct>”;
$xml .=”<a:EntityName>contact</a:EntityName>”;
$xml .=”<a:LinkEntities />”;
$xml .=”<a:Orders />”;
$xml .=”<a:PageInfo>”;
$xml .=”<a:Count>0</a:Count>”;
$xml .=”<a:PageNumber>0</a:PageNumber>”;
$xml .=”<a:PagingCookie i:nil=\”true\” />”;
$xml .=”<a:ReturnTotalRecordCount>false</a:ReturnTotalRecordCount>”;
$xml .=”</a:PageInfo>”;
$xml .=”<a:NoLock>false</a:NoLock>”;
$xml .=”</b:value>”;
$xml .=”</a:KeyValuePairOfstringanyType>”;
$xml .=”</a:Parameters>”;
$xml .=”<a:RequestId i:nil=\”true\” />”;
$xml .=”<a:RequestName>RetrieveMultiple</a:RequestName>”;
$xml .=”</request>”;
$xml .=”</Execute>”;
$xml .=”</s:Body>”;
Lead entity:
URL: http://mcc.enfusen.com/crm-api/lead/?ldid=92bfddf8-8e34-e611-80e3-5065f38a3bb1
$xml =”<s:Body>”;
$xml .=”<Execute xmlns=\”http://schemas.microsoft.com/xrm/2011/Contracts/Services\” xmlns:i=\”http://www.w3.org/2001/XMLSchema-instance\”>”;
$xml .=”<request i:type=\”a:RetrieveMultipleRequest\” xmlns:a=\”http://schemas.microsoft.com/xrm/2011/Contracts\”>”;
$xml .=”<a:Parameters xmlns:b=\”http://schemas.datacontract.org/2004/07/System.Collections.Generic\”>”;
$xml .=”<a:KeyValuePairOfstringanyType>”;
$xml .=”<b:key>Query</b:key>”;
$xml .=”<b:value i:type=\”a:QueryExpression\”>”;
$xml .=”<a:ColumnSet>”;
$xml .=”<a:AllColumns>true</a:AllColumns>”;
$xml .=”<a:Columns xmlns:c=\”http://schemas.microsoft.com/2003/10/Serialization/Arrays\”>”;
// $xml .=”<c:string>query</c:string>”;
// $xml .=”<c:string>membertype</c:string>”;
$xml .=”</a:Columns>”;
$xml .=”</a:ColumnSet>”;
$xml .= “<a:Criteria>”;
$xml .= “<a:Conditions>”;
$xml .= “<a:ConditionExpression>”;
$xml .= “<a:AttributeName>leadid</a:AttributeName>”;
$xml .= “<a:Operator>Equal</a:Operator>”;
$xml .= “<a:Values xmlns:c=\”http://schemas.microsoft.com/2003/10/Serialization/Arrays\”>”;
$xml .= “<c:anyType i:type=\”d:string\” xmlns:d=\”http://www.w3.org/2001/XMLSchema\”>”.$leadid.”</c:anyType>”;
$xml .= “</a:Values>”;
$xml .= “</a:ConditionExpression>”;
$xml .= “</a:Conditions>”;
$xml .= “<a:FilterOperator>And</a:FilterOperator>”;
$xml .= “<a:Filters />”;
$xml .= “</a:Criteria>”;
$xml .=”<a:Distinct>false</a:Distinct>”;
$xml .=”<a:EntityName>lead</a:EntityName>”;
$xml .=”<a:LinkEntities />”;
$xml .=”<a:Orders />”;
$xml .=”<a:PageInfo>”;
$xml .=”<a:Count>0</a:Count>”;
$xml .=”<a:PageNumber>0</a:PageNumber>”;
$xml .=”<a:PagingCookie i:nil=\”true\” />”;
$xml .=”<a:ReturnTotalRecordCount>false</a:ReturnTotalRecordCount>”;
$xml .=”</a:PageInfo>”;
$xml .=”<a:NoLock>false</a:NoLock>”;
$xml .=”</b:value>”;
$xml .=”</a:KeyValuePairOfstringanyType>”;
$xml .=”</a:Parameters>”;
$xml .=”<a:RequestId i:nil=\”true\” />”;
$xml .=”<a:RequestName>RetrieveMultiple</a:RequestName>”;
$xml .=”</request>”;
$xml .=”</Execute>”;
$xml .=”</s:Body>”;
Company (account) entity:
URL: http://mcc.enfusen.com/crm-api/company/?aid=b760dff7-da0c-e611-80e8-fc15b428aa58
Soap request: $xml =”<s:Body>”;
$xml .=”<Execute xmlns=\”http://schemas.microsoft.com/xrm/2011/Contracts/Services\” xmlns:i=\”http://www.w3.org/2001/XMLSchema-instance\”>”;
$xml .=”<request i:type=\”a:RetrieveMultipleRequest\” xmlns:a=\”http://schemas.microsoft.com/xrm/2011/Contracts\”>”;
$xml .=”<a:Parameters xmlns:b=\”http://schemas.datacontract.org/2004/07/System.Collections.Generic\”>”;
$xml .=”<a:KeyValuePairOfstringanyType>”;
$xml .=”<b:key>Query</b:key>”;
$xml .=”<b:value i:type=\”a:QueryExpression\”>”;
$xml .=”<a:ColumnSet>”;
$xml .=”<a:AllColumns>true</a:AllColumns>”;
$xml .=”<a:Columns xmlns:c=\”http://schemas.microsoft.com/2003/10/Serialization/Arrays\”>”;
// $xml .=”<c:string>query</c:string>”;
// $xml .=”<c:string>membertype</c:string>”;
$xml .=”</a:Columns>”;
$xml .=”</a:ColumnSet>”;
$xml .= “<a:Criteria>”;
$xml .= “<a:Conditions>”;
$xml .= “<a:ConditionExpression>”;
$xml .= “<a:AttributeName>accountid</a:AttributeName>”;
$xml .= “<a:Operator>Equal</a:Operator>”;
$xml .= “<a:Values xmlns:c=\”http://schemas.microsoft.com/2003/10/Serialization/Arrays\”>”;
$xml .= “<c:anyType i:type=\”d:string\” xmlns:d=\”http://www.w3.org/2001/XMLSchema\”>”.$accountid.”</c:anyType>”;
$xml .= “</a:Values>”;
$xml .= “</a:ConditionExpression>”;
$xml .= “</a:Conditions>”;
$xml .= “<a:FilterOperator>And</a:FilterOperator>”;
$xml .= “<a:Filters />”;
$xml .= “</a:Criteria>”;
$xml .=”<a:Distinct>false</a:Distinct>”;
$xml .=”<a:EntityName>account</a:EntityName>”;
$xml .=”<a:LinkEntities />”;
$xml .=”<a:Orders />”;
$xml .=”<a:PageInfo>”;
$xml .=”<a:Count>0</a:Count>”;
$xml .=”<a:PageNumber>0</a:PageNumber>”;
$xml .=”<a:PagingCookie i:nil=\”true\” />”;
$xml .=”<a:ReturnTotalRecordCount>false</a:ReturnTotalRecordCount>”;
$xml .=”</a:PageInfo>”;
$xml .=”<a:NoLock>false</a:NoLock>”;
$xml .=”</b:value>”;
$xml .=”</a:KeyValuePairOfstringanyType>”;
$xml .=”</a:Parameters>”;
$xml .=”<a:RequestId i:nil=\”true\” />”;
$xml .=”<a:RequestName>RetrieveMultiple</a:RequestName>”;
$xml .=”</request>”;
$xml .=”</Execute>”;
$xml .=”</s:Body>”;