SOLVED

Re: How to use complex stream position?

Go to solution
Anonymous
Not applicable

How to use complex stream position?

In the documentation I found the following snip for complex stream position (startPosition in this case)

  1. (http://developers.marketo.com/documentation/soap/stream-position/)
  2.  
  3. <startPosition>
  4. <latestCreatedAt />
  5. <oldestCreatedAt>2013-08-01T00:13:13+00:00</oldestCreatedAt>
  6. <activityCreatedAt />
  7. <offset>ID:1086173</offset>
  8. </startPosition>

I've successfully used the <streamPosition>id:0:ts:0:os:0:rc:0</streamPosition> style to return results but am interested in the offset piece of the complex stream position.

1. Does the startPosition need to be coupled with a streamPosition?
2. If not, is it possible to use a qualified offset where the ID is the Marketo lead ID (wondering about the sample above)
3. Are there any examples of using startPosition specifically with getMultipleLeads as all of the attempts I've made with this seem to be failing (returns either no results or ignores the startPosition data I've passed in)?


Really appreciate any assistance!

Tags (1)
1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Re: How to use complex stream position?

Hi Eric - Apologies for the confusion.  getMultipleLeads uses the simple stream position type.  We had documented it using the complex stream position type.  The documentation has been corrected.

Here is a sample XML of two API calls using sthe simple stream position.

First call to getMultipleLeads:
REQUEST:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<ns2:paramsGetMultipleLeads xmlns:ns2="http://www.marketo.com/mktows/">

    <leadSelector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:LastUpdateAtSelector">

        <latestUpdatedAt>2013-11-06T09:58:58.862-08:00</latestUpdatedAt>

        <oldestUpdatedAt>2013-11-05T09:58:58.863-08:00</oldestUpdatedAt>

    </leadSelector>

    <streamPosition></streamPosition>

    <batchSize>1</batchSize>

    <includeAttributes>

        <stringItem>Email</stringItem>

        <stringItem>munchkinID</stringItem>

    </includeAttributes>

</ns2:paramsGetMultipleLeads>



RESPONSE:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<ns2:successGetMultipleLeads xmlns:ns2="http://www.marketo.com/mktows/">

    <result>

        <returnCount>1</returnCount>

        <remainingCount>1</remainingCount>

        <newStreamPosition>id:1937:to:1383674338:tl:1383760738:os:1:rc:1</newStreamPosition>

        <leadRecordList>

            <leadRecord>

                <Id>1937</Id>

                <Email>raj.rajamani+mktoblog@gmail.com</Email>

                <ForeignSysPersonId xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>

                <ForeignSysType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>

                <leadAttributeList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>

            </leadRecord>

        </leadRecordList>

    </result>

</ns2:successGetMultipleLeads>

The second call to getMultipleLeads passes the newStreamPosition value from the first call.


REQUEST:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<ns2:paramsGetMultipleLeads xmlns:ns2="http://www.marketo.com/mktows/">

    <leadSelector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:LastUpdateAtSelector">

        <latestUpdatedAt>2013-11-06T09:59:57.516-08:00</latestUpdatedAt>

        <oldestUpdatedAt>2013-11-05T09:59:57.517-08:00</oldestUpdatedAt>

    </leadSelector>

    <streamPosition>id:1937:to:1383674338:tl:1383760738:os:1:rc:1</streamPosition>

    <batchSize>1</batchSize>

    <includeAttributes>

        <stringItem>Email</stringItem>

        <stringItem>munchkinID</stringItem>

    </includeAttributes>

</ns2:paramsGetMultipleLeads>

RESPONSE:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<ns2:successGetMultipleLeads xmlns:ns2="http://www.marketo.com/mktows/">

    <result>

        <returnCount>1</returnCount>

        <remainingCount>0</remainingCount>

        <newStreamPosition>id:1091275:to:1383674338:tl:1383760738:os:2:rc:0</newStreamPosition>

        <leadRecordList>

            <leadRecord>

                <Id>1091275</Id>

                <Email>jthao@marketo.com</Email>

                <ForeignSysPersonId xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>

                <ForeignSysType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>

                <leadAttributeList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>

            </leadRecord>

        </leadRecordList>

    </result>

</ns2:successGetMultipleLeads>

 

View solution in original post

6 REPLIES 6
Anonymous
Not applicable

Re: How to use complex stream position?

Eric,
You can find details about StreamPosition at http://developers.marketo.com/documentation/soap/stream-position/

I
'll reiterate that you should treat this as an opaque object and not modify it.  
Anonymous
Not applicable

Re: How to use complex stream position?

Here's sample code for getMultipleLeads() in Java -

import java.net.URL;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;
 
import javax.crypto.Mac;
import javax.crypto.spec.SecretKeySpec;
import javax.xml.bind.JAXBContext;
import javax.xml.bind.JAXBElement;
import javax.xml.bind.Marshaller;
import javax.xml.namespace.QName;
 
import org.apache.commons.codec.binary.Hex;
 
import com.marketo.mktows.ArrayOfString;
import com.marketo.mktows.AuthenticationHeader;
import com.marketo.mktows.MktMktowsApiService;
import com.marketo.mktows.MktowsPort;
import com.marketo.mktows.ObjectFactory;
import com.marketo.mktows.ParamsGetMultipleLeads;
import com.marketo.mktows.StaticListSelector;
import com.marketo.mktows.StreamPosition;
import com.marketo.mktows.SuccessGetLead;
import com.marketo.mktows.SuccessGetMultipleLeads;
 
public class GetMultipleLeads {
 
public static void main(String[] args) {
System.out.println("Executing GetMultipleLeads");
try {
URL marketoSoapEndPoint = new URL(
"https://100-AEK-913.mktoapi.com/soap/mktows/2_2" + "?WSDL");
String marketoUserId = "demo17_1_809934544BFABAE58E5D27";
String marketoSecretKey = "27272727aa";
 
QName serviceName = new QName("http://www.marketo.com/mktows/",
"MktMktowsApiService");
MktMktowsApiService service = new MktMktowsApiService(
marketoSoapEndPoint, serviceName);
MktowsPort port = service.getMktowsApiSoapPort();
 
// Create Signature
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);
 
// Set Authentication Header
AuthenticationHeader header = new AuthenticationHeader();
header.setMktowsUserId(marketoUserId);
header.setRequestTimestamp(requestTimestamp);
header.setRequestSignature(signature);
 
// Create Request
ParamsGetMultipleLeads request = new ParamsGetMultipleLeads();
 
// Request Using LeadKey Selector
// //////////////////////////////////////////////////////
// LeadKeySelector keySelector = new LeadKeySelector();
// keySelector.setKeyType(LeadKeyRef.EMAIL);
//
// ArrayOfString aos = new ArrayOfString();
// aos.getStringItems().add("formtest1@marketo.com");
// aos.getStringItems().add("joe@marketo.com");
// keySelector.setKeyValues(aos);
// request.setLeadSelector(keySelector);
 
/*
* // Request Using LastUpdateAtSelector
* ////////////////////////////////////////////////////////
* LastUpdateAtSelector leadSelector = new LastUpdateAtSelector();
* GregorianCalendar gc = new GregorianCalendar();
* gc.setTimeInMillis(new Date().getTime()); gc.add(
* GregorianCalendar.DAY_OF_YEAR, -2);
* DatatypeFactory factory = DatatypeFactory.newInstance();
* ObjectFactory objectFactory = new ObjectFactory();
* JAXBElement<XMLGregorianCalendar> until
* =objectFactory.createLastUpdateAtSelectorLatestUpdatedAt
* (factory.newXMLGregorianCalendar(gc));
* GregorianCalendar since = new GregorianCalendar();
* since.setTimeInMillis(new Date().getTime()); since.add(
* GregorianCalendar.DAY_OF_YEAR, -5);
* leadSelector.setOldestUpdatedAt(factory.newXMLGregorianCalendar(since
* )); leadSelector.setLatestUpdatedAt(until);
* request.setLeadSelector(leadSelector);
*/
 
// Request Using StaticList Selector
// //////////////////////////////////////////////////////
StaticListSelector staticListSelector = new StaticListSelector();
 
// staticListSelector.setStaticListId(value)
ObjectFactory objectFactory = new ObjectFactory();
JAXBElement<String> listName = objectFactory
.createStaticListSelectorStaticListName("CustomFormula.listOfLeads");
staticListSelector.setStaticListName(listName);
 
// JAXBElement<Integer> listId =
// objectFactory.createStaticListSelectorStaticListId(6926);
// staticListSelector.setStaticListId(listId);
 
request.setLeadSelector(staticListSelector);
 
ArrayOfString attributes = new ArrayOfString();
attributes.getStringItems().add("FirstName");
attributes.getStringItems().add("AnonymousIP");
attributes.getStringItems().add("Company");
 
request.setIncludeAttributes(attributes);
JAXBElement<Integer> batchSize = new ObjectFactory()
.createParamsGetMultipleLeadsBatchSize(150);
 
request.setBatchSize(batchSize);
 
SuccessGetMultipleLeads result = null;
int count = 0;
do {
if (count > 0) {
String pos = result.getResult().getNewStreamPosition();
JAXBElement<String> streamPos = new ObjectFactory()
.createParamsGetMultipleLeadsStreamPosition(pos);
request.setStreamPosition(streamPos);
}
result = port.getMultipleLeads(request, header);
 
JAXBContext context = JAXBContext
.newInstance(SuccessGetLead.class);
Marshaller m = context.createMarshaller();
m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
m.marshal(request, System.out);
m.marshal(result, System.out);
count += result.getResult().getReturnCount();
} while (result.getResult().getRemainingCount() > 0);
 
System.out.println("Returned a total of :" + count + " items");
} catch (Exception e) {
e.printStackTrace();
}
}
}
Anonymous
Not applicable

Re: How to use complex stream position?

Could you provide instead a sample SOAP request which uses the above startPosition?

*EDIT: and uses the <offset>ID:XYZ</offset> style
Anonymous
Not applicable

Re: How to use complex stream position?

sorry, you cannot use <offset> for getMultipleLeads.  Here's a request sample that works - you'll notice that it uses <streamPosition> to pass in the offset

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ns2:paramsGetMultipleLeads xmlns:ns2="http://www.marketo.com/mktows/">
    <leadSelector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:StaticListSelector">
        <staticListName>CustomFormula.listOfLeads</staticListName>
    </leadSelector>
    <streamPosition>id:72020:ln:CustomFormula.listOfLeads:os:150:rc:301</streamPosition>
    <batchSize>150</batchSize>
    <includeAttributes>
        <stringItem>FirstName</stringItem>
        <stringItem>AnonymousIP</stringItem>
        <stringItem>Company</stringItem>
    </includeAttributes>
</ns2:paramsGetMultipleLeads>
Anonymous
Not applicable

Re: How to use complex stream position?

This is directly from the getMultipleLeads documentation, I'd like to know how to get these options to work.  Every time I try to use the startPosition with any of the below I just receive an empty result.  Is there any special formatting I need to be aware of?  I've used litterally every W3C WSDL date format listed on this page http://www.w3.org/TR/NOTE-datetime without success. 

startPosition->offset

Optional

Used to paginate through large number of activity responses. The offset value is returned by the previous calls response field newStartPosition->offset.

startPosition->activityCreatedAt

Optional

Used to paginate through large number of activity responses. The activityCreatedAt is returned by the previous call's response field newStartPosition->activityCreatedAt. (W3C WSDL date format).

startPosition->latestCreatedAt

Optional

Used to paginate through large number of activity responses. The latestCreatedAt is returned by the previous call's response field newStartPosition->latestCreatedAt. (W3C WSDL date format).

startPosition->oldestCreatedAt

Optional

Used to paginate through large number of activity responses. The oldestCreatedAt is returned by the previous call's response field newStartPosition->oldestCreatedAt. (W3C WSDL date format).


Anonymous
Not applicable

Re: How to use complex stream position?

Hi Eric - Apologies for the confusion.  getMultipleLeads uses the simple stream position type.  We had documented it using the complex stream position type.  The documentation has been corrected.

Here is a sample XML of two API calls using sthe simple stream position.

First call to getMultipleLeads:
REQUEST:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<ns2:paramsGetMultipleLeads xmlns:ns2="http://www.marketo.com/mktows/">

    <leadSelector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:LastUpdateAtSelector">

        <latestUpdatedAt>2013-11-06T09:58:58.862-08:00</latestUpdatedAt>

        <oldestUpdatedAt>2013-11-05T09:58:58.863-08:00</oldestUpdatedAt>

    </leadSelector>

    <streamPosition></streamPosition>

    <batchSize>1</batchSize>

    <includeAttributes>

        <stringItem>Email</stringItem>

        <stringItem>munchkinID</stringItem>

    </includeAttributes>

</ns2:paramsGetMultipleLeads>



RESPONSE:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<ns2:successGetMultipleLeads xmlns:ns2="http://www.marketo.com/mktows/">

    <result>

        <returnCount>1</returnCount>

        <remainingCount>1</remainingCount>

        <newStreamPosition>id:1937:to:1383674338:tl:1383760738:os:1:rc:1</newStreamPosition>

        <leadRecordList>

            <leadRecord>

                <Id>1937</Id>

                <Email>raj.rajamani+mktoblog@gmail.com</Email>

                <ForeignSysPersonId xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>

                <ForeignSysType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>

                <leadAttributeList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>

            </leadRecord>

        </leadRecordList>

    </result>

</ns2:successGetMultipleLeads>

The second call to getMultipleLeads passes the newStreamPosition value from the first call.


REQUEST:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<ns2:paramsGetMultipleLeads xmlns:ns2="http://www.marketo.com/mktows/">

    <leadSelector xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="ns2:LastUpdateAtSelector">

        <latestUpdatedAt>2013-11-06T09:59:57.516-08:00</latestUpdatedAt>

        <oldestUpdatedAt>2013-11-05T09:59:57.517-08:00</oldestUpdatedAt>

    </leadSelector>

    <streamPosition>id:1937:to:1383674338:tl:1383760738:os:1:rc:1</streamPosition>

    <batchSize>1</batchSize>

    <includeAttributes>

        <stringItem>Email</stringItem>

        <stringItem>munchkinID</stringItem>

    </includeAttributes>

</ns2:paramsGetMultipleLeads>

RESPONSE:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>

<ns2:successGetMultipleLeads xmlns:ns2="http://www.marketo.com/mktows/">

    <result>

        <returnCount>1</returnCount>

        <remainingCount>0</remainingCount>

        <newStreamPosition>id:1091275:to:1383674338:tl:1383760738:os:2:rc:0</newStreamPosition>

        <leadRecordList>

            <leadRecord>

                <Id>1091275</Id>

                <Email>jthao@marketo.com</Email>

                <ForeignSysPersonId xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>

                <ForeignSysType xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>

                <leadAttributeList xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true"/>

            </leadRecord>

        </leadRecordList>

    </result>

</ns2:successGetMultipleLeads>