Re: Unsubscribed emails

Anonymous
Not applicable

Unsubscribed emails

Hi,

I want to take a custom report using api, wherein I want the date, email id and the mail through which the user has unsubscribed from the mailers.

I have checked the marketo API docs but could not find relevant information. Any ideas?

Thanks and Regards,

Bharani 

5 REPLIES 5
Alok_Ramsisaria
Level 10

Re: Unsubscribed emails

You can try the "getLeadActivity" function with parameter "activityFilter->includeAttributes->activityType" having the value "UnsubscribeEmail".

Hope this will help you.

Anonymous
Not applicable

Re: Unsubscribed emails

Thanks for the responce!

I have already tried that, but the Offset is 0.

Here is the snippet for reference, Let me know if there is any issue in this code.

MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);

            MktowsPort port = service.getMktowsApiSoapPort();

           

        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");

            String text = df.format(new Date());

            String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);         

            String encryptString = requestTimestamp + marketoUserId ;

           

            SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");

            Mac mac = Mac.getInstance("HmacSHA1");

            mac.init(secretKey);

            byte[] rawHmac = mac.doFinal(encryptString.getBytes());

            char[] hexChars = Hex.encodeHex(rawHmac);

            String signature = new String(hexChars);

           

  

            AuthenticationHeader header = new AuthenticationHeader();

            header.setMktowsUserId(marketoUserId);

            header.setRequestTimestamp(requestTimestamp);

            header.setRequestSignature(signature);

           

   

            ParamsGetLeadActivity request = new ParamsGetLeadActivity();

            LeadKey key = new LeadKey();

            key.setKeyType(LeadKeyRef.EMAIL);

            key.setKeyValue("t@t.com");

            request.setLeadKey(key);

            ObjectFactory objectFactory = new ObjectFactory();

            JAXBElement<Integer> batchSize = objectFactory.createParamsGetLeadActivityBatchSize(10);

            request.setBatchSize(batchSize);

           

            ActivityTypeFilter atv = new ActivityTypeFilter();

            ArrayOfActivityType aatt = new ArrayOfActivityType();

           

          

            aatt.getActivityTypes().add(ActivityType.UNSUBSCRIBE_EMAIL);

           

            atv.setIncludeTypes(aatt);

            JAXBElement<ActivityTypeFilter> typeFilter = objectFactory.createParamsGetLeadActivityActivityFilter(atv);

            request.setActivityFilter(typeFilter);

           

            SuccessGetLeadActivity result = port.getLeadActivity(request, header);

            JAXBContext context = JAXBContext.newInstance(SuccessGetLeadActivity.class);

            Marshaller m = context.createMarshaller();

            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

            m.marshal(result, System.out);

Alok_Ramsisaria
Level 10

Re: Unsubscribed emails

As per the WSDL file, Activity type should be "UnsubscribeEmail" not "UNSUBSCRIBE_EMAIL".

Can you try this?

Alok_Ramsisaria
Level 10

Re: Unsubscribed emails

Here is the working code for reference

$apiObj = new mktSampleMktowsClient($this->accessKey, $this->secretKey, $this->soapEndPoint);   

$getdata = $apiObj->getLeadActivity('EMAIL', $email, 'UnsubscribeEmail');

function getLeadActivity($keyType, $keyValue, $activityTypeFilter='') {

    $retLeadActivity = null;

    $leadKey = new LeadKey();

    $leadKey->keyType = $keyType;

    $leadKey->keyValue = $keyValue;

    $activityFilter = new ActivityTypeFilter();

    $activityType = new ArrayOfActivityType();

    $activityType->activityType = $activityTypeFilter;

   

    $activityFilter->includeTypes = $activityType;

    $params = new paramsGetLeadActivity();

    $params->leadKey = $leadKey;

    $params->activityFilter = $activityFilter;

    $params->batchSize = 1;

   

    $options = array();

    $authHdr = $this->_getAuthenticationHeader();

    $retLeadActivity = $this->soapClient->__soapCall('getLeadActivity', array($params), $options, $authHdr);

     

    return $retLeadActivity;

  }

In response, I am getting all the details like Mailer Name, Date of Activity, Device Used, Campaign name etc.

Anonymous
Not applicable

Re: Unsubscribed emails

Thanks for the reference Alok!

Will try this and let you know soon.