0

I need to get a list of customers from Exact Target (this version:mc.s4.exacttarget.com) and update our internal database with subscription changes.

The reason for this is that we need our internal system to know if a customer has unsubscribed from the link in the marketing email they get.

Here is the code I use to get modifications in the last 10 minutes:

        // Set up the filter - Search for the subscriber
        SimpleFilterPart sfp = new SimpleFilterPart();
        sfp.Property = "ModifiedDate";
        sfp.SimpleOperator = SimpleOperators.greaterThanOrEqual;
        sfp.Value = new string[] { DateTime.Now.AddMinutes(howManyMinutesAgo * -1).ToString("yyyyMMdd hh:mm:ss") };

        RetrieveRequest rr = new RetrieveRequest();
        rr.ObjectType = "ListSubscriber"; // <-- Important
        rr.Properties = new string[] { "SubscriberKey", "Status", "ModifiedDate" };
        rr.Filter = sfp; // Attach the filter

The problem is that this gets me a list of customers who have had any modification (like opening an email). I only want to know about people who have unsubscribed. Is this possible? Is there an entirely different way of doing this?

Thank you, Bobby

2 Answers 2

1

If you are using standard Marketing Cloud unsubscribe functionality or a well constructed custom preference centre/one-click unsub page, you should look at doing a retrieve on the UnsubEvent object. Your code would be similar to these examples of retrieves on OpenEvents.

A handy feature would be to use the utilise the "RetrieveAllSinceLastBatch" switch. It frees you from maintaining a counter of where you got to the last time you checked for events and ensure you do not miss records or process any records twice. Example SOAP would look like this:

Request

<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Header>
      <wsse:Security soapenv:mustUnderstand="1" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
         <wsse:UsernameToken wsu:Id="UsernameToken-24440876" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
            <wsse:Username>{{Username}}</wsse:Username>
            <wsse:Password Type="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-username-token-profile-1.0#PasswordText">{{Password}}</wsse:Password>
         </wsse:UsernameToken>
      </wsse:Security>
   </soapenv:Header>
   <soapenv:Body>
      <RetrieveRequestMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
         <RetrieveRequest>
            <!--
            <ClientIDs><ID>123456</ID></ClientIDs>
            <QueryAllAccounts>true</QueryAllAccounts>
            -->
            <ObjectType>UnsubEvent</ObjectType>
            <RetrieveAllSinceLastBatch>true</RetrieveAllSinceLastBatch>
            <Properties>ID</Properties>
            <Properties>ObjectID</Properties>
            <Properties>PartnerKey</Properties>
            <Properties>CreatedDate</Properties>
            <Properties>ModifiedDate</Properties>
            <Properties>Client.ID</Properties>
            <Properties>SendID</Properties>
            <Properties>SubscriberKey</Properties>
            <Properties>EventDate</Properties>
            <Properties>EventType</Properties>
            <Properties>TriggeredSendDefinitionObjectID</Properties>
            <Properties>BatchID</Properties>
            <Properties>List.ID</Properties>
            <Properties>List.Type</Properties>
            <Properties>List.ListClassification</Properties>
            <Properties>IsMasterUnsubscribed</Properties>
         </RetrieveRequest>
      </RetrieveRequestMsg>
   </soapenv:Body>
</soapenv:Envelope>

Response

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <soap:Header>
        <wsa:Action>RetrieveResponse</wsa:Action>
        <wsa:MessageID>urn:uuid:784c2f38-2451-4307-9502-b06d9870d913</wsa:MessageID>
        <wsa:RelatesTo>urn:uuid:2edc9527-50a4-4033-9756-3e6e9a6f951b</wsa:RelatesTo>
        <wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
        <wsse:Security>
            <wsu:Timestamp wsu:Id="Timestamp-8844c5a2-6282-45d7-8aa3-5ce207b05aa9">
                <wsu:Created>2017-06-02T11:27:42Z</wsu:Created>
                <wsu:Expires>2017-06-02T11:32:42Z</wsu:Expires>
            </wsu:Timestamp>
        </wsse:Security>
    </soap:Header>
    <soap:Body>
        <RetrieveResponseMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
            <OverallStatus>OK</OverallStatus>
            <RequestID>a925de8b-cc05-4643-8099-0bf569523aeb</RequestID>
            <Results xsi:type="UnsubEvent">
                <Client>
                    <ID>123456</ID>
                </Client>
                <PartnerKey />
                <CreatedDate>2015-11-30T18:55:07.577</CreatedDate>
                <ModifiedDate>2015-11-30T18:55:07.577</ModifiedDate>
                <ID>38925933</ID>
                <ObjectID>38925933</ObjectID>
                <SendID>26529121</SendID>
                <SubscriberKey>1</SubscriberKey>
                <EventDate>2015-11-30T18:55:07.577</EventDate>
                <EventType>Unsubscribe</EventType>
                <TriggeredSendDefinitionObjectID />
                <BatchID>1</BatchID>
                <List>
                    <PartnerKey xsi:nil="true" />
                    <ID>123456</ID>
                    <ObjectID xsi:nil="true" />
                    <Type>Private</Type>
                    <ListClassification>PublicationList</ListClassification>
                </List>
                <IsMasterUnsubscribed>false</IsMasterUnsubscribed>
            </Results>
        </RetrieveResponseMsg>
    </soap:Body>
</soap:Envelope>

One thing to consider is the fact that, although SFMC does not have the ability to measure it at this moment in time, API calls are bundled with your licence. At some point in the future your Account Executive may come to you with a bill for overages. For the most scalable solution, you may want to consider tracking extracts (flat files), instead API integration. These can be scheduled in Automation Studio and you can collect them from the Enhanced FTP periodically. Possible files to include are the Unubs file and the Status Changes file

2
  • Wow that's great. I will look into doing that thanks
    – Bobby
    Commented Jun 2, 2017 at 11:12
  • I've added a bit more detail around that to expect from the UnsubEvent retrieve. You should also consider the comment about going old-school and just getting a file out of SFMC. More scalable and doesn't chew up API quotas.
    – Macca
    Commented Jun 2, 2017 at 11:39
1

So my solution is to use a complex filter and add two simple filters to it.

Simple filter 1 is for modified date. Simple filter 2 is for the customers status set as unsubscribed.

https://developer.salesforce.com/docs/atlas.en-us.noversion.mc-apis.meta/mc-apis/using_complex_filter_parts.htm

Thanks, Bobby

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .