Re: Empty streamPosition but non-zero remainingCount on getMultipleLeads call

Anonymous
Not applicable

Empty streamPosition but non-zero remainingCount on getMultipleLeads call

Hi, I made the following SOAP call -

<env:Envelope xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="http://www.marketo.com/mktows/" xmlns:env="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ins0="http://www.marketo.com/mktows/">
  <env:Header>
    <ns1:AuthenticationHeader>
<!--- Removed -->
    </ns1:AuthenticationHeader>
  </env:Header>
  <env:Body>
    <ns1:paramsGetMultipleLeads>
      <leadSelector xsi:type="ns1:LeadKeySelector">
        <keyType>EMAIL</keyType>
        <keyValues>
          <stringItem>test@test.com</stringItem>
        </keyValues>
      </leadSelector>
    </ns1:paramsGetMultipleLeads>
  </env:Body>
</env:Envelope>

This is the response I received - 

<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="http://www.marketo.com/mktows/">
  <SOAP-ENV:Body>
    <ns1:successGetMultipleLeads>
      <result>
        <returnCount>3</returnCount>
        <remainingCount>1</remainingCount>
        <newStreamPosition/>
        <leadRecordList>
          <!-- 3 leadRecords with email = 'test@test.com' -->
        </leadRecordList>
      </result>
    </ns1:successGetMultipleLeads>
  </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

 
As you can see, the remainingCount is reported to be 1 but the newStreamPosition is empty. The condition I use to terminate the stream is 'remainingCount == 0'. So the empty newStreamPosition leads to an infinite loop.

I've temporarily modified the condition to 'remainingCount == 0 OR newStreamPosition is blank'. What's going on here?
Tags (1)
1 REPLY 1
Rick_Bergen
Level 1

Re: Empty streamPosition but non-zero remainingCount on getMultipleLeads call

I've found that if the returnCount is less than the batchSize I can conclude that there are no more records to get despite the remainingCount being greater than zero.  The remainingCount is notoriously unreliable with the excuse being it is an "estimate".  I vaguely recall the errors in remainingCount may have something to do with Marketo including SFDC Users in their remainingCount but not at their returned results.

This is the hack I put in my code to avoid the somewhat infinate loops I was getting:

                    if (returnCount < batchSize)
                    {
                        remainingCount = 0;
                    }


A better solution may indeed be to look for a blank newStreamPosition as you have suggested as I suppose having exactly a batch size of records is possible.