3

I'm currently using the Java bindings of the Partner API to extract unsubs, clicks, bounces and other events. This is working as expected, however I'd like to slice my requests by a date range (similar to this).

I'm trying to replicate the following logic (Ignore the fact that I've used SQL as pseudo-code) in my request such that I'm able to dynamically slice my requests using two input parameters (xxx, yyy): Select * from Unsubs Where EventDate > xxx and EventDate < yyy

I'm currently using two SimpleFilterPart's combined in a ComplexFilter part to achieve this filtering logic. As below:

// Init Request data
RetrieveRequestMsgDocument retrieveRequestMsgDocument = RetrieveRequestMsgDocument.Factory
    .newInstance();
RetrieveRequest rreq = RetrieveRequest.Factory.newInstance();

// Other stuff removed from this extract ....

// Setup filter 1
SimpleFilterPart filter1 = SimpleFilterPart.Factory.newInstance();
filter1.setProperty("EventDate");
filter1.setSimpleOperator(SimpleOperators.GREATER_THAN);
filter1.setDateValue1Array(new GregorianCalendar[] { (GregorianCalendar) startDate });

// Setup filter 2
SimpleFilterPart filter2 = SimpleFilterPart.Factory.newInstance();
filter2.setProperty("EventDate");
filter2.setSimpleOperator(SimpleOperators.LESS_THAN);
filter2.setDateValue1Array(new GregorianCalendar[] { (GregorianCalendar) endDate });

// Combine filters
ComplexFilterPart cfp1 = ComplexFilterPart.Factory.newInstance();
cfp1.setLeftOperand(filter1);
cfp1.setLogicalOperator(LogicalOperators.AND);
cfp1.setRightOperand(filter2);
rreq.setFilter(cfp1);

RetrieveRequestMsgDocument.RetrieveRequestMsg retrieveRequestMsg = retrieveRequestMsgDocument
    .addNewRetrieveRequestMsg();
retrieveRequestMsg.setRetrieveRequest(rreq);

Ultimately the Java builds the following SOAP extract:

 <xml-fragment xmlns:par="http://exacttarget.com/wsdl/partnerAPI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <par:ClientIDs>
    Stuff omitted
  </par:ClientIDs>
  <par:ObjectType>UnsubEvent</par:ObjectType>
  <par:Properties>Client.ID</par:Properties>
  <par:Properties>SendID</par:Properties>
  <par:Properties>SubscriberKey</par:Properties>
  <par:Properties>List.ID</par:Properties>
  <par:Properties>EventDate</par:Properties>
  <par:Properties>EventType</par:Properties>
  <par:Properties>BatchID</par:Properties>
  <par:Properties>TriggeredSendDefinitionObjectID</par:Properties>
  <par:Filter xsi:type="par:ComplexFilterPart">
    <par:LeftOperand xsi:type="par:SimpleFilterPart">
      <par:Property>EventDate</par:Property>
      <par:SimpleOperator>greaterThan</par:SimpleOperator>
      <par:DateValue>2015-01-07T00:00:00.749Z</par:DateValue>
    </par:LeftOperand>
    <par:LogicalOperator>AND</par:LogicalOperator>
    <par:RightOperand xsi:type="par:SimpleFilterPart">
      <par:Property>EventDate</par:Property>
      <par:SimpleOperator>lessThan</par:SimpleOperator>
      <par:DateValue>2015-01-08T00:00:00.749Z</par:DateValue>
    </par:RightOperand>
  </par:Filter>
</xml-fragment>

In the above example I’m attempting to extract Unsubs between 07/01/2015 and 08/01/2015 (UK date format).

My question - is this the correct way to filter requests by date? I'm seeing data from 06/01 and 07/01 returned from this request which implies my lower bound isn't working correctly. Am I fundimentally builing my requests incorrectly or is there some date normalization need to perform?

2
  • 1
    Are you doing some sort of timezone conversion after the results are returned? ET web services always works on ET server time (-6 GMT CST, no daylight savings observed)
    – mobo
    Jan 9, 2015 at 17:22
  • Nope, I'm creating a SimpleDateFormat and just dumping the string to the console for debugging. I thought ET WS were based on UTC? Jan 12, 2015 at 12:13

1 Answer 1

1

Here are a couple of date formats I've used with success in filtering by date:

<RightOperand xsi:type="SimpleFilterPart">
    <Property>InsertDate</Property>
    <SimpleOperator>lessThan</SimpleOperator>
    <DateValue>2015-01-23T00:00:00-06:00</DateValue>
</RightOperand>

<RightOperand xsi:type="SimpleFilterPart">
    <Property>InsertDate</Property>
    <SimpleOperator>lessThan</SimpleOperator>
    <DateValue>2015-01-23T10:12:21</DateValue>
</RightOperand>

You must log in to answer this question.

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