Get All Leads

Anonymous
Not applicable

Get All Leads

I have a User Id and Encryption key... Is it possible to pull all leads in php using SOAP? 
Tags (1)
6 REPLIES 6
Anonymous
Not applicable

Re: Get All Leads

Yes, it is, using SOAP API's getMultiupleLeads.
 
In PHP you need to:
- provide User ID and Encryption key to generate the server signature and timestamp
- define a XML call in a loop to read leads in batches

SOAP API Calls returning multiple records - reading the next batch
 
The article "Marketo Enterprise SOAP API"
links to a PHP example containing the authentication method to generate the server signature and timestamp.

 
 
 
The generic XML call is
 
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mkt="http://www.marketo.com/mktows/">
   <soapenv:Header>
      <mkt:AuthenticationHeader>
         <mktowsUserId>?</mktowsUserId>
         <requestSignature>?</requestSignature>
         <requestTimestamp>?</requestTimestamp>
         <!--Optional:-->
         <audit>?</audit>
         <!--Optional:-->
         <mode>?</mode>
      </mkt:AuthenticationHeader>
   </soapenv:Header>
   <soapenv:Body>
      <mkt:paramsGetMultipleLeads>
         <!--Optional:-->
         <leadSelector/>
         <!--Optional:-->
         <lastUpdatedAt>?</lastUpdatedAt>
         <!--Optional:-->
         <streamPosition>?</streamPosition>
         <!--Optional:-->
         <batchSize>?</batchSize>
         <!--Optional:-->
         <includeAttributes>
            <!--Zero or more repetitions:-->
            <stringItem>?</stringItem>
         </includeAttributes>
      </mkt:paramsGetMultipleLeads>
   </soapenv:Body>
</soapenv:Envelope>
 


A generic PHP authentication can be defined as


$signature = '';
if(isset($_POST["user"]) && isset($_POST["encryption"])){ // execute only if both are set
$request_time = date(DATE_W3C, time());
$access_key = trim($_POST["user"]);
$secret_key = trim($_POST["encryption"]);
$encrypt_input = $request_time . $access_key;
$signature = hash_hmac('sha1', $encrypt_input, $secret_key);
}
else {
$_POST["user"] = '';
$_POST["encryption"] = '';
}



and then

$attrs = array(
'mktowsUserId'     => $access_key,
'requestSignature' => $signature,
'requestTimestamp' => $request_time,
);
 
$header = new SoapHeader('http://www.marketo.com/mktows/', 'AuthenticationHeader', $attrs);
 
Anonymous
Not applicable

Re: Get All Leads

Hi,


Thanks for the reply.

Couple of doubt...

should the offsets incrment only in multiples of two?
And should the offset always start with 4?
Also i don't see where the marketo end point is used.


Anonymous
Not applicable

Re: Get All Leads

The offset is ncremented by the same number you would use for <batchSize>

Each getMultipleLeads function call can only return batches of 1000 leads, maximum. If this call needs to return more than 1000 leads, the result will return a start position, which should be used in subsequent calls to retrieve the next set of leads. 
Please keep in mind 1000 leads per batch is the maximum. It is always a good idea to start with a lower number (say 500 or even 250 for testing) and increase while you do not receive errors caused by PHP (server-side) memory exhaustion. 

 
Anonymous
Not applicable

Re: Get All Leads

The endpoint is used when you generate the server signature and timestamp.

Please review the article "Marketo SOAP API PHP client" for details and a fully working example
https://community.marketo.com/MarketoArticle?id=kA050000000Kz59CAC

Anonymous
Not applicable

Re: Get All Leads

this is the code i've managed to write till now... no output though... 😞 can anyone guide me please!

 

 

$signature = "xxxxx";
$user_id = "xxxx";
$encryption_key = "";
if (isset($user_id) && isset($encryption_key)) { // execute only if both are set
    $request_time = date(DATE_W3C, time());
    $access_key = trim($user_id);
    $secret_key = trim($encryption_key);
    $encrypt_input = $request_time . $access_key;
    $signature = hash_hmac('sha1', $encrypt_input, $secret_key);
} else {
    $user_id = '';
    $encryption_key = '';
}
 
 
 
//$client = new SoapClient(null);
$attrs = array(
    'mktowsUserId' => $access_key,
    'requestSignature' => $signature,
    'requestTimestamp' => $request_time,
);
 
$client = new SoapClient("http://090-BZJ-603.mktoapi.com/soap/mktows/1_2?WSDL");
$header = new SoapHeader('http://www.marketo.com/mktows/', 'AuthenticationHeader', $attrs);
$client->__setSoapHeaders($header);
 
$xml = '<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mkt="http://www.marketo.com/mktows/">
   <soapenv:Header>
      <mkt:AuthenticationHeader>
         <mktowsUserId>'.$access_key.'</mktowsUserId>
         <requestSignature>'.$signature.'</requestSignature>
         <requestTimestamp>'.$request_time.'</requestTimestamp>
        
      </mkt:AuthenticationHeader>
   </soapenv:Header>
   <soapenv:Body>
      <mkt:paramsGetMultipleLeads>
        
      </mkt:paramsGetMultipleLeads>
   </soapenv:Body>
</soapenv:Envelope>';
 
 
print_r($client->__call("getMultipleLeads",$xml));
Anonymous
Not applicable

Re: Get All Leads

mkt:paramsGetMultipleLeads defines the database query. It is not declared yet, the reason there is no output.

lastUpdatedAt would allow to set a well define point in time or includeAttributes would allow to set a more granular filter.