{"id":3988,"date":"2013-07-23T13:17:03","date_gmt":"2013-07-23T18:17:03","guid":{"rendered":"http:\/\/ahmeddirie.com\/?p=3988"},"modified":"2014-06-20T16:09:07","modified_gmt":"2014-06-20T23:09:07","slug":"marketos-updated-soap-php-client-and-the-new-way-to-submit-leads","status":"publish","type":"post","link":"https:\/\/ahmeddirie.com\/blog\/web-development\/marketos-updated-soap-php-client-and-the-new-way-to-submit-leads\/","title":{"rendered":"Marketo&#8217;s updated SOAP PHP Client and the new way to submit leads"},"content":{"rendered":"<p>This is an update to my previous post, <a href=\"\/technology\/web-development\/submitting-leads-to-marketos-soap-api-using-php\" title=\"Submitting Leads to Marketo's SOAP API using PHP\">Submitting Leads to Marketo&#8217;s SOAP API using PHP<\/a>. Recently, Marketo did an update to their SOAP PHP Client and a few things changed along the way. More specifically, what information you pass in to the sync lead function. <\/p>\n<p>I&#8217;ll quickly go through the code needed for the new change. You might want to read the previous post to get an idea of how it all works together.<\/p>\n<p><!--more--><\/p>\n<h2>Your Marketo Lead Array<\/h2>\n<p>At this point, you&#8217;ve collected your user&#8217;s data from most likely a web form. We&#8217;ll store these details in an array and pass that array to our function for lead submission.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\/\/Creating the array\r\n$marketoArray = array(\r\n\t'Company' =&gt; $_POST['company'],\r\n\t'FirstName' =&gt; $_POST['firstname'],\r\n\t'LastName' =&gt; $_POST['lastname'],\r\n\t'Email' =&gt; $_POST['email'],\r\n\t'ListSource' =&gt; 'Name of your list source',\r\n\t'LeadSource' =&gt; 'Name of your lead source'\r\n);\r\n\r\nmarketo_submit_lead($marketoArray);\r\n\r\n<\/pre>\n<h2>Function to submit lead<\/h2>\n<p>Here is the lead submit function which gets your array from the previous secion and calls the marketo class. You&#8217;ll notice that we&#8217;re no longer passing in a cookie to the syncLead function.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\r\n\/\/Submitting the user's registration info to Marketo\r\nfunction marketo_submit_lead($marketoArray) {\r\n\t\r\n\t\/\/Marketo SOAP PHP Client Class\r\n\trequire_once('marketo.php');\r\n\t\r\n\t$marketo_user_id = 'YOUR MARKETO USER ID';\r\n\t$marketo_encryption_key = 'YOUR MARKETO ENCRYPTION KEY';\r\n\t$marketo_soap_host = 'YOUR MARKETO SOAP END POINT';\r\n\t\r\n\t\/\/Connecting to Marketo\r\n\t$marketo_client = new MarketoAPI($marketo_user_id, $marketo_encryption_key, $marketo_soap_host);\r\n\t\r\n\t\/\/Checking for the existence of a lead\r\n\t\/\/If lead exists, setting the lead record and submit the lead to Marketo\r\n\t$checkLead = $marketo_client-&gt;getLead('EMAIL', $marketoArray['Email']);\r\n\tif ($checkLead == null) {\r\n \t\t\t\/\/This is a new lead\r\n \t\t\t$marketo_client-&gt;syncLead($marketoArray['Email'], $marketoArray);\r\n\t} else {\r\n\t\t\/\/This is an existing lead\r\n\t\t$leadId = $checkLead-&gt;Id;\r\n\t\t$marketo_client-&gt;syncLead($leadId, $marketoArray);\t\r\n\t}\r\n\t\r\n\t\/\/Adding the Lead to a campaign\r\n\t$campaign_name = &quot;NAME OF YOUR MARKETO SMART CAMPAIGN&quot;;\r\n\t\r\n\t\/\/Getting List of Campaigns\r\n\t$campaign_list = $marketo_client-&gt;getCampaignsForSource();\r\n\t\r\n\t\/\/Checking if out campaign is available in the list\r\n\tif (empty($campaign_list[$campaign_name])) {\r\n\t\t\/\/No campaign found.\r\n\t} else {\r\n\t\t$campaign_id = $campaign_list[$campaign_name];\r\n\t\t\r\n\t\t\/\/Get Lead ID if new lead. Otherwise, add lead to campaign\r\n\t\tif ($leadId) {\r\n\t\t\t$marketo_client-&gt;requestCampaign($campaign_id, $leadId);\t\r\n\t\t} else {\r\n\t\t\t$getLead = $marketo_client-&gt;getLead('EMAIL', $marketoArray['Email']);\r\n\t\t\tif ($checkLead != null) {\r\n\t\t\t\t$leadId = $getLead-&gt;Id;\r\n\t\t\t\t$marketo_client-&gt;requestCampaign($campaign_id, $leadId);\r\n\t\t\t}\t\r\n\t\t}\r\n\t}\t\t\r\n}\r\n<\/pre>\n<h2>The updated SOAP PHP Client\/Class from Marketo (marketo.php)<\/h2>\n<p>This one is slightly modified from the original. I&#8217;ve removed the credentials from the class. This allows you to pass that in from your lead submit function and do interesting things like, encrypt it outside of the class and decrypt before passing in.<\/p>\n<pre class=\"brush: php; title: ; notranslate\" title=\"\">\r\n\/\/ PHP classes corresponding to the data types in defined in WSDL\r\n\r\nclass ActivityRecord {\r\n\r\n    \/**\r\n     * @var int\r\n     *\/\r\n    public $id;\r\n\r\n    \/**\r\n     * @var dateTime\r\n     *\/\r\n    public $activityDateTime;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $activityType;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $mktgAssetName;\r\n\r\n    \/**\r\n     * @var (object)ArrayOfAttribute\r\n     *\/\r\n    public $activityAttributes;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $campaign;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $personName;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $mktPersonId;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $foreignSysId;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $orgName;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $foreignSysOrgId;\r\n\r\n}\r\n\r\nclass ActivityTypeFilter {\r\n\r\n    \/**\r\n     * @var (object)ArrayOfActivityType\r\n     *\/\r\n    public $includeTypes;\r\n\r\n    \/**\r\n     * @var (object)ArrayOfActivityType\r\n     *\/\r\n    public $excludeTypes;\r\n\r\n}\r\n\r\nclass Attribute {\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $attrName;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $attrType;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $attrValue;\r\n\r\n}\r\n\r\nclass AuthenticationHeaderInfo {\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $mktowsUserId;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $requestSignature;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $requestTimestamp;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $audit;\r\n\r\n    \/**\r\n     * @var int\r\n     *\/\r\n    public $mode;\r\n\r\n}\r\n\r\nclass CampaignRecord {\r\n\r\n    \/**\r\n     * @var int\r\n     *\/\r\n    public $id;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $name;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $description;\r\n\r\n}\r\n\r\nclass LeadActivityList {\r\n\r\n    \/**\r\n     * @var int\r\n     *\/\r\n    public $returnCount;\r\n\r\n    \/**\r\n     * @var int\r\n     *\/\r\n    public $remainingCount;\r\n\r\n    \/**\r\n     * @var (object)StreamPosition\r\n     *\/\r\n    public $newStartPosition;\r\n\r\n    \/**\r\n     * @var (object)ArrayOfActivityRecord\r\n     *\/\r\n    public $activityRecordList;\r\n\r\n}\r\n\r\nclass LeadChangeRecord {\r\n\r\n    \/**\r\n     * @var int\r\n     *\/\r\n    public $id;\r\n\r\n    \/**\r\n     * @var dateTime\r\n     *\/\r\n    public $activityDateTime;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $activityType;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $mktgAssetName;\r\n\r\n    \/**\r\n     * @var (object)ArrayOfAttribute\r\n     *\/\r\n    public $activityAttributes;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $campaign;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $mktPersonId;\r\n\r\n}\r\n\r\nclass LeadKey {\r\n\r\n    \/**\r\n     * @var string\r\n     *     NOTE: keyType should follow the following restrictions\r\n     *     You can have one of the following value\r\n     *     IDNUM\r\n     *     COOKIE\r\n     *     EMAIL\r\n     *     LEADOWNEREMAIL\r\n     *     SFDCACCOUNTID\r\n     *     SFDCCONTACTID\r\n     *     SFDCLEADID\r\n     *     SFDCLEADOWNERID\r\n     *     SFDCOPPTYID\r\n     *\/\r\n    public $keyType;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $keyValue;\r\n\r\n}\r\n\r\nclass LeadRecord {\r\n\r\n    \/**\r\n     * @var int\r\n     *\/\r\n    public $Id;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $Email;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $ForeignSysPersonId;\r\n\r\n    \/**\r\n     * @var string\r\n     *     NOTE: ForeignSysType should follow the following restrictions\r\n     *     You can have one of the following value\r\n     *     CUSTOM\r\n     *     SFDC\r\n     *     NETSUITE\r\n     *\/\r\n    public $ForeignSysType;\r\n\r\n    \/**\r\n     * @var (object)ArrayOfAttribute\r\n     *\/\r\n    public $leadAttributeList;\r\n\r\n}\r\n\r\nclass LeadStatus {\r\n\r\n    \/**\r\n     * @var (object)LeadKey\r\n     *\/\r\n    public $leadKey;\r\n\r\n    \/**\r\n     * @var boolean\r\n     *\/\r\n    public $status;\r\n\r\n}\r\n\r\nclass ListKey {\r\n\r\n    \/**\r\n     * @var string\r\n     *     NOTE: keyType should follow the following restrictions\r\n     *     You can have one of the following value\r\n     *     MKTOLISTNAME\r\n     *     MKTOSALESUSERID\r\n     *     SFDCLEADOWNERID\r\n     *\/\r\n    public $keyType;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $keyValue;\r\n\r\n}\r\n\r\nclass ResultGetCampaignsForSource {\r\n\r\n    \/**\r\n     * @var int\r\n     *\/\r\n    public $returnCount;\r\n\r\n    \/**\r\n     * @var (object)ArrayOfCampaignRecord\r\n     *\/\r\n    public $campaignRecordList;\r\n\r\n}\r\n\r\nclass ResultGetLead {\r\n\r\n    \/**\r\n     * @var int\r\n     *\/\r\n    public $count;\r\n\r\n    \/**\r\n     * @var (object)ArrayOfLeadRecord\r\n     *\/\r\n    public $leadRecordList;\r\n\r\n}\r\n\r\nclass ResultGetLeadChanges {\r\n\r\n    \/**\r\n     * @var int\r\n     *\/\r\n    public $returnCount;\r\n\r\n    \/**\r\n     * @var int\r\n     *\/\r\n    public $remainingCount;\r\n\r\n    \/**\r\n     * @var (object)StreamPosition\r\n     *\/\r\n    public $newStartPosition;\r\n\r\n    \/**\r\n     * @var (object)ArrayOfLeadChangeRecord\r\n     *\/\r\n    public $leadChangeRecordList;\r\n\r\n}\r\n\r\nclass ResultGetMultipleLeads {\r\n\r\n    \/**\r\n     * @var int\r\n     *\/\r\n    public $returnCount;\r\n\r\n    \/**\r\n     * @var int\r\n     *\/\r\n    public $remainingCount;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $newStreamPosition;\r\n\r\n    \/**\r\n     * @var (object)ArrayOfLeadRecord\r\n     *\/\r\n    public $leadRecordList;\r\n\r\n}\r\n\r\nclass ResultListOperation {\r\n\r\n    \/**\r\n     * @var boolean\r\n     *\/\r\n    public $success;\r\n\r\n    \/**\r\n     * @var (object)ArrayOfLeadStatus\r\n     *\/\r\n    public $statusList;\r\n\r\n}\r\n\r\nclass ResultRequestCampaign {\r\n\r\n    \/**\r\n     * @var boolean\r\n     *\/\r\n    public $success;\r\n\r\n}\r\n\r\nclass ResultSyncLead {\r\n\r\n    \/**\r\n     * @var int\r\n     *\/\r\n    public $leadId;\r\n\r\n    \/**\r\n     * @var string\r\n     *     NOTE: syncStatus should follow the following restrictions\r\n     *     You can have one of the following value\r\n     *     CREATED\r\n     *     UPDATED\r\n     *     FAILED\r\n     *\/\r\n    public $syncStatus;\r\n\r\n    \/**\r\n     * @var (object)LeadRecord\r\n     *\/\r\n    public $leadRecord;\r\n\r\n}\r\n\r\nclass ResultSyncMultipleLeads {\r\n\r\n    \/**\r\n     * @var (object)ArrayOfSyncStatus\r\n     *\/\r\n    public $syncStatusList;\r\n\r\n}\r\n\r\nclass StreamPosition {\r\n\r\n    \/**\r\n     * @var dateTime\r\n     *\/\r\n    public $latestCreatedAt;\r\n\r\n    \/**\r\n     * @var dateTime\r\n     *\/\r\n    public $oldestCreatedAt;\r\n\r\n    \/**\r\n     * @var dateTime\r\n     *\/\r\n    public $activityCreatedAt;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $offset;\r\n\r\n}\r\n\r\nclass SyncStatus {\r\n\r\n    \/**\r\n     * @var int\r\n     *\/\r\n    public $leadId;\r\n\r\n    \/**\r\n     * @var string\r\n     *     NOTE: status should follow the following restrictions\r\n     *     You can have one of the following value\r\n     *     CREATED\r\n     *     UPDATED\r\n     *     UNCHANGED\r\n     *     FAILED\r\n     *\/\r\n    public $status;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $error;\r\n\r\n}\r\n\r\nclass VersionedItem {\r\n\r\n    \/**\r\n     * @var integer\r\n     *\/\r\n    public $id;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $name;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $type;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $description;\r\n\r\n    \/**\r\n     * @var dateTime\r\n     *\/\r\n    public $timestamp;\r\n\r\n}\r\n\r\nclass ArrayOfActivityRecord {\r\n\r\n    \/**\r\n     * @var array[0, unbounded] of (object)ActivityRecord\r\n     *\/\r\n    public $activityRecord;\r\n\r\n}\r\n\r\nclass ArrayOfActivityType {\r\n\r\n    \/**\r\n     * @var array[0, unbounded] of string\r\n     *     NOTE: activityType should follow the following restrictions\r\n     *     You can have one of the following value\r\n     *     VisitWebpage\r\n     *     FillOutForm\r\n     *     ClickLink\r\n     *     RegisterForEvent\r\n     *     AttendEvent\r\n     *     SendEmail\r\n     *     EmailDelivered\r\n     *     EmailBounced\r\n     *     UnsubscribeEmail\r\n     *     OpenEmail\r\n     *     ClickEmail\r\n     *     NewLead\r\n     *     ChangeDataValue\r\n     *     LeadAssigned\r\n     *     NewSFDCOpprtnty\r\n     *     Wait\r\n     *     RunSubflow\r\n     *     RemoveFromFlow\r\n     *     PushLeadToSales\r\n     *     CreateTask\r\n     *     ConvertLead\r\n     *     ChangeScore\r\n     *     ChangeOwner\r\n     *     AddToList\r\n     *     RemoveFromList\r\n     *     SFDCActivity\r\n     *     EmailBouncedSoft\r\n     *     PushLeadUpdatesToSales\r\n     *     DeleteLeadFromSales\r\n     *     SFDCActivityUpdated\r\n     *     SFDCMergeLeads\r\n     *     MergeLeads\r\n     *     ResolveConflicts\r\n     *     AssocWithOpprtntyInSales\r\n     *     DissocFromOpprtntyInSales\r\n     *     UpdateOpprtntyInSales\r\n     *     DeleteLead\r\n     *     SendAlert\r\n     *     SendSalesEmail\r\n     *     OpenSalesEmail\r\n     *     ClickSalesEmail\r\n     *     AddtoSFDCCampaign\r\n     *     RemoveFromSFDCCampaign\r\n     *     ChangeStatusInSFDCCampaign\r\n     *     ReceiveSalesEmail\r\n     *     InterestingMoment\r\n     *     RequestCampaign\r\n     *     SalesEmailBounced\r\n     *\/\r\n    public $activityType;\r\n\r\n}\r\n\r\nclass ArrayOfAttribute {\r\n\r\n    \/**\r\n     * @var array[0, unbounded] of (object)Attribute\r\n     *\/\r\n    public $attribute;\r\n\r\n}\r\n\r\nclass ArrayOfBase64Binary {\r\n\r\n    \/\/ You need to set only one from the following two vars\r\n\r\n    \/**\r\n     * @var array[0, unbounded] of Plain Binary\r\n     *\/\r\n    public $base64Binary;\r\n\r\n    \/**\r\n     * @var array[0, unbounded] of base64Binary\r\n     *\/\r\n    public $base64Binary_encoded;\r\n\r\n\r\n}\r\n\r\nclass ArrayOfCampaignRecord {\r\n\r\n    \/**\r\n     * @var array[0, unbounded] of (object)CampaignRecord\r\n     *\/\r\n    public $campaignRecord;\r\n\r\n}\r\n\r\nclass ArrayOfLeadChangeRecord {\r\n\r\n    \/**\r\n     * @var array[0, unbounded] of (object)LeadChangeRecord\r\n     *\/\r\n    public $leadChangeRecord;\r\n\r\n}\r\n\r\nclass ArrayOfLeadKey {\r\n\r\n    \/**\r\n     * @var array[0, unbounded] of (object)LeadKey\r\n     *\/\r\n    public $leadKey;\r\n\r\n}\r\n\r\nclass ArrayOfLeadRecord {\r\n\r\n    \/**\r\n     * @var array[0, unbounded] of (object)LeadRecord\r\n     *\/\r\n    public $leadRecord;\r\n\r\n}\r\n\r\nclass ArrayOfLeadStatus {\r\n\r\n    \/**\r\n     * @var array[0, unbounded] of (object)LeadStatus\r\n     *\/\r\n    public $leadStatus;\r\n\r\n}\r\n\r\nclass ArrayOfSyncStatus {\r\n\r\n    \/**\r\n     * @var array[0, unbounded] of (object)SyncStatus\r\n     *\/\r\n    public $syncStatus;\r\n\r\n}\r\n\r\nclass ArrayOfVersionedItem {\r\n\r\n    \/**\r\n     * @var array[0, unbounded] of (object)VersionedItem\r\n     *\/\r\n    public $versionedItem;\r\n\r\n}\r\n\r\nclass paramsGetCampaignsForSource {\r\n\r\n    \/**\r\n     * @var string\r\n     *     NOTE: source should follow the following restrictions\r\n     *     You can have one of the following value\r\n     *     MKTOWS\r\n     *     SALES\r\n     *\/\r\n    public $source;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $name;\r\n\r\n    \/**\r\n     * @var boolean\r\n     *\/\r\n    public $exactName;\r\n\r\n}\r\n\r\nclass paramsGetLead {\r\n\r\n    \/**\r\n     * @var (object)LeadKey\r\n     *\/\r\n    public $leadKey;\r\n\r\n}\r\n\r\nclass paramsGetLeadActivity {\r\n\r\n    \/**\r\n     * @var (object)LeadKey\r\n     *\/\r\n    public $leadKey;\r\n\r\n    \/**\r\n     * @var (object)ActivityTypeFilter\r\n     *\/\r\n    public $activityFilter;\r\n\r\n    \/**\r\n     * @var (object)StreamPosition\r\n     *\/\r\n    public $startPosition;\r\n\r\n    \/**\r\n     * @var int\r\n     *\/\r\n    public $batchSize;\r\n\r\n}\r\n\r\nclass paramsGetLeadChanges {\r\n\r\n    \/**\r\n     * @var (object)StreamPosition\r\n     *\/\r\n    public $startPosition;\r\n\r\n    \/**\r\n     * @var (object)ActivityTypeFilter\r\n     *\/\r\n    public $activityFilter;\r\n\r\n    \/**\r\n     * @var int\r\n     *\/\r\n    public $batchSize;\r\n\r\n}\r\n\r\nclass paramsGetMultipleLeads {\r\n\r\n    \/**\r\n     * @var dateTime\r\n     *\/\r\n    public $lastUpdatedAt;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $streamPosition;\r\n\r\n    \/**\r\n     * @var int\r\n     *\/\r\n    public $batchSize;\r\n\r\n}\r\n\r\nclass paramsListOperation {\r\n\r\n    \/**\r\n     * @var string\r\n     *     NOTE: listOperation should follow the following restrictions\r\n     *     You can have one of the following value\r\n     *     ADDTOLIST\r\n     *     ISMEMBEROFLIST\r\n     *     REMOVEFROMLIST\r\n     *\/\r\n    public $listOperation;\r\n\r\n    \/**\r\n     * @var (object)ListKey\r\n     *\/\r\n    public $listKey;\r\n\r\n    \/**\r\n     * @var (object)ArrayOfLeadKey\r\n     *\/\r\n    public $listMemberList;\r\n\r\n    \/**\r\n     * @var boolean\r\n     *\/\r\n    public $strict;\r\n\r\n}\r\n\r\nclass paramsRequestCampaign {\r\n\r\n    \/**\r\n     * @var string\r\n     *     NOTE: source should follow the following restrictions\r\n     *     You can have one of the following value\r\n     *     MKTOWS\r\n     *     SALES\r\n     *\/\r\n    public $source;\r\n\r\n    \/**\r\n     * @var int\r\n     *\/\r\n    public $campaignId;\r\n\r\n    \/**\r\n     * @var (object)ArrayOfLeadKey\r\n     *\/\r\n    public $leadList;\r\n\r\n}\r\n\r\nclass paramsSyncLead {\r\n\r\n    \/**\r\n     * @var (object)LeadRecord\r\n     *\/\r\n    public $leadRecord;\r\n\r\n    \/**\r\n     * @var boolean\r\n     *\/\r\n    public $returnLead;\r\n\r\n    \/**\r\n     * @var string\r\n     *\/\r\n    public $marketoCookie;\r\n\r\n}\r\n\r\nclass paramsSyncMultipleLeads {\r\n\r\n    \/**\r\n     * @var (object)ArrayOfLeadRecord\r\n     *\/\r\n    public $leadRecordList;\r\n\r\n    \/**\r\n     * @var boolean\r\n     *\/\r\n    public $dedupEnabled;\r\n\r\n}\r\n\r\nclass successGetCampaignsForSource {\r\n\r\n    \/**\r\n     * @var (object)ResultGetCampaignsForSource\r\n     *\/\r\n    public $result;\r\n\r\n}\r\n\r\nclass successGetLead {\r\n\r\n    \/**\r\n     * @var (object)ResultGetLead\r\n     *\/\r\n    public $result;\r\n\r\n}\r\n\r\nclass successGetLeadActivity {\r\n\r\n    \/**\r\n     * @var (object)LeadActivityList\r\n     *\/\r\n    public $leadActivityList;\r\n\r\n}\r\n\r\nclass successGetLeadChanges {\r\n\r\n    \/**\r\n     * @var (object)ResultGetLeadChanges\r\n     *\/\r\n    public $result;\r\n\r\n}\r\n\r\nclass successGetMultipleLeads {\r\n\r\n    \/**\r\n     * @var (object)ResultGetMultipleLeads\r\n     *\/\r\n    public $result;\r\n\r\n}\r\n\r\nclass successListOperation {\r\n\r\n    \/**\r\n     * @var (object)ResultListOperation\r\n     *\/\r\n    public $result;\r\n\r\n}\r\n\r\nclass successRequestCampaign {\r\n\r\n    \/**\r\n     * @var (object)ResultRequestCampaign\r\n     *\/\r\n    public $result;\r\n\r\n}\r\n\r\nclass successSyncLead {\r\n\r\n    \/**\r\n     * @var (object)ResultSyncLead\r\n     *\/\r\n    public $result;\r\n\r\n}\r\n\r\nclass successSyncMultipleLeads {\r\n\r\n    \/**\r\n     * @var (object)ResultSyncMultipleLeads\r\n     *\/\r\n    public $result;\r\n\r\n}\r\n\r\n\/\/ define the class map\r\nclass MktowsXmlSchema\r\n{\r\n\/\/ Do not change the indentation or line breaks below this comment.\r\n\/\/ For the curious, it helps with merging new changes from the WSDL code generator.\r\nstatic public\r\n$class_map = array(\r\n    &quot;ActivityRecord&quot; =&gt; &quot;ActivityRecord&quot;,\r\n    &quot;ActivityTypeFilter&quot; =&gt; &quot;ActivityTypeFilter&quot;,\r\n    &quot;Attribute&quot; =&gt; &quot;Attribute&quot;,\r\n    &quot;AuthenticationHeaderInfo&quot; =&gt; &quot;AuthenticationHeaderInfo&quot;,\r\n    &quot;CampaignRecord&quot; =&gt; &quot;CampaignRecord&quot;,\r\n    &quot;LeadActivityList&quot; =&gt; &quot;LeadActivityList&quot;,\r\n    &quot;LeadChangeRecord&quot; =&gt; &quot;LeadChangeRecord&quot;,\r\n    &quot;LeadKey&quot; =&gt; &quot;LeadKey&quot;,\r\n    &quot;LeadRecord&quot; =&gt; &quot;LeadRecord&quot;,\r\n    &quot;LeadStatus&quot; =&gt; &quot;LeadStatus&quot;,\r\n    &quot;ListKey&quot; =&gt; &quot;ListKey&quot;,\r\n    &quot;ResultGetCampaignsForSource&quot; =&gt; &quot;ResultGetCampaignsForSource&quot;,\r\n    &quot;ResultGetLead&quot; =&gt; &quot;ResultGetLead&quot;,\r\n    &quot;ResultGetLeadChanges&quot; =&gt; &quot;ResultGetLeadChanges&quot;,\r\n    &quot;ResultGetMultipleLeads&quot; =&gt; &quot;ResultGetMultipleLeads&quot;,\r\n    &quot;ResultListOperation&quot; =&gt; &quot;ResultListOperation&quot;,\r\n    &quot;ResultRequestCampaign&quot; =&gt; &quot;ResultRequestCampaign&quot;,\r\n    &quot;ResultSyncLead&quot; =&gt; &quot;ResultSyncLead&quot;,\r\n    &quot;ResultSyncMultipleLeads&quot; =&gt; &quot;ResultSyncMultipleLeads&quot;,\r\n    &quot;StreamPosition&quot; =&gt; &quot;StreamPosition&quot;,\r\n    &quot;SyncStatus&quot; =&gt; &quot;SyncStatus&quot;,\r\n    &quot;VersionedItem&quot; =&gt; &quot;VersionedItem&quot;,\r\n    &quot;ArrayOfActivityRecord&quot; =&gt; &quot;ArrayOfActivityRecord&quot;,\r\n    &quot;ArrayOfActivityType&quot; =&gt; &quot;ArrayOfActivityType&quot;,\r\n    &quot;ArrayOfAttribute&quot; =&gt; &quot;ArrayOfAttribute&quot;,\r\n    &quot;ArrayOfBase64Binary&quot; =&gt; &quot;ArrayOfBase64Binary&quot;,\r\n    &quot;ArrayOfCampaignRecord&quot; =&gt; &quot;ArrayOfCampaignRecord&quot;,\r\n    &quot;ArrayOfLeadChangeRecord&quot; =&gt; &quot;ArrayOfLeadChangeRecord&quot;,\r\n    &quot;ArrayOfLeadKey&quot; =&gt; &quot;ArrayOfLeadKey&quot;,\r\n    &quot;ArrayOfLeadRecord&quot; =&gt; &quot;ArrayOfLeadRecord&quot;,\r\n    &quot;ArrayOfLeadStatus&quot; =&gt; &quot;ArrayOfLeadStatus&quot;,\r\n    &quot;ArrayOfSyncStatus&quot; =&gt; &quot;ArrayOfSyncStatus&quot;,\r\n    &quot;ArrayOfVersionedItem&quot; =&gt; &quot;ArrayOfVersionedItem&quot;,\r\n    &quot;paramsGetCampaignsForSource&quot; =&gt; &quot;paramsGetCampaignsForSource&quot;,\r\n    &quot;paramsGetLead&quot; =&gt; &quot;paramsGetLead&quot;,\r\n    &quot;paramsGetLeadActivity&quot; =&gt; &quot;paramsGetLeadActivity&quot;,\r\n    &quot;paramsGetLeadChanges&quot; =&gt; &quot;paramsGetLeadChanges&quot;,\r\n    &quot;paramsGetMultipleLeads&quot; =&gt; &quot;paramsGetMultipleLeads&quot;,\r\n    &quot;paramsListOperation&quot; =&gt; &quot;paramsListOperation&quot;,\r\n    &quot;paramsRequestCampaign&quot; =&gt; &quot;paramsRequestCampaign&quot;,\r\n    &quot;paramsSyncLead&quot; =&gt; &quot;paramsSyncLead&quot;,\r\n    &quot;paramsSyncMultipleLeads&quot; =&gt; &quot;paramsSyncMultipleLeads&quot;,\r\n    &quot;successGetCampaignsForSource&quot; =&gt; &quot;successGetCampaignsForSource&quot;,\r\n    &quot;successGetLead&quot; =&gt; &quot;successGetLead&quot;,\r\n    &quot;successGetLeadActivity&quot; =&gt; &quot;successGetLeadActivity&quot;,\r\n    &quot;successGetLeadChanges&quot; =&gt; &quot;successGetLeadChanges&quot;,\r\n    &quot;successGetMultipleLeads&quot; =&gt; &quot;successGetMultipleLeads&quot;,\r\n    &quot;successListOperation&quot; =&gt; &quot;successListOperation&quot;,\r\n    &quot;successRequestCampaign&quot; =&gt; &quot;successRequestCampaign&quot;,\r\n    &quot;successSyncLead&quot; =&gt; &quot;successSyncLead&quot;,\r\n    &quot;successSyncMultipleLeads&quot; =&gt; &quot;successSyncMultipleLeads&quot;);\r\n}\r\n\r\n\r\n\/**\r\n * Client for Marketo SOAP API.\r\n *\r\n *\/\r\nclass MarketoAPI \r\n{\r\n  \/\/ Change this vale to true to enable debug output.\r\n  const DEBUG = false;\r\n  \r\n  const CLIENT_TZ = 'America\/Toronto';\r\n  const MKTOWS_NAMESPACE = 'http:\/\/www.marketo.com\/mktows\/';\r\n  \r\n  protected $accessKey;\r\n  protected $secretKey;\r\n  \r\n  \/**\r\n   * @var SoapClient\r\n   *\/\r\n  protected $soapClient;\r\n  \r\n  public function __construct($accessKey, $secretKey, $soapEndPoint)\r\n  {\r\n    $this-&gt;accessKey = $accessKey;\r\n    $this-&gt;secretKey = $secretKey;\r\n    \r\n    $options = array(&quot;connection_timeout&quot; =&gt; 20, &quot;location&quot; =&gt; $soapEndPoint);\r\n    if (self::DEBUG) {\r\n      $options[&quot;trace&quot;] = true;\r\n    }\r\n    \r\n    $wsdlUri = $soapEndPoint . '?WSDL';\r\n    \r\n    $this-&gt;soapClient = new SoapClient($wsdlUri, $options);\r\n  }\r\n  \r\n  private function _getAuthenticationHeader()\r\n  {\r\n    $dtzObj = new DateTimeZone(self::CLIENT_TZ);\r\n    $dtObj = new DateTime('now', $dtzObj);\r\n    $timestamp = $dtObj-&gt;format(DATE_W3C);\r\n    \/\/$timestamp = '2009-01-27T15:53';\r\n\r\n    $encryptString = $timestamp . $this-&gt;accessKey;\r\n\r\n    $signature = hash_hmac('sha1', $encryptString, $this-&gt;secretKey);\r\n    \/\/echo &quot;encrypt:   $encryptString\\n&quot;;\r\n    \/\/echo &quot;key:       {this-&gt;secretKey}\\n&quot;;\r\n    \/\/echo &quot;signature: $signature\\n&quot;;\r\n\r\n    $attrs = new stdClass();\r\n    $attrs-&gt;mktowsUserId  = $this-&gt;accessKey;\r\n    $attrs-&gt;requestSignature = $signature;\r\n    $attrs-&gt;requestTimestamp = $timestamp;\r\n\r\n    $soapHdr = new SoapHeader(self::MKTOWS_NAMESPACE, 'AuthenticationHeader', $attrs);\r\n    return $soapHdr;\r\n  }\r\n\r\n  public function getLead($keyType, $keyValue)\r\n  {\r\n    $retLead = null;\r\n    \r\n    $leadKey = new LeadKey();\r\n    $leadKey-&gt;keyType = $keyType;\r\n    $leadKey-&gt;keyValue = $keyValue;\r\n    \r\n    $params = new paramsGetLead();\r\n    $params-&gt;leadKey = $leadKey;\r\n    \r\n    $options = array();\r\n\r\n    $authHdr = $this-&gt;_getAuthenticationHeader();\r\n    \r\n    try {\r\n      $success = $this-&gt;soapClient-&gt;__soapCall('getLead', array($params), $options, $authHdr);\r\n      \r\n      if (self::DEBUG) {\r\n        $req = $this-&gt;soapClient-&gt;__getLastRequest();\r\n        echo &quot;RAW request:\\n$req\\n&quot;;\r\n        $resp = $this-&gt;soapClient-&gt;__getLastResponse();\r\n        echo &quot;RAW response:\\n$resp\\n&quot;;\r\n      }\r\n      \r\n      if (isset($success-&gt;result)) {\r\n        if ($success-&gt;result-&gt;count &gt; 1) {\r\n          \/\/ Is this okay?  If not, raise exception\r\n        }\r\n        if (isset($success-&gt;result-&gt;leadRecordList-&gt;leadRecord)) {\r\n          $leadRecList = $success-&gt;result-&gt;leadRecordList-&gt;leadRecord;\r\n          if (!is_array($leadRecList)) {\r\n             $leadRecList = array($leadRecList);\r\n             $count = count($leadRecList);\r\n             if ($count &gt; 0) {\r\n               $retLead = $leadRecList[$count-1];\r\n             }\r\n          }\r\n        }\r\n      }\r\n    }\r\n    catch (SoapFault $ex) {\r\n      $ok = false;\r\n      $errCode = 1;\r\n      $faultCode = null;\r\n      if (!empty($ex-&gt;detail-&gt;serviceException-&gt;code)) {\r\n        $errCode = $ex-&gt;detail-&gt;serviceException-&gt;code;\r\n      }\r\n      if (!empty($ex-&gt;faultCode)) {\r\n        $faultCode = $ex-&gt;faultCode;\r\n      }\r\n      switch ($errCode)\r\n      {\r\n        case mktWsError::ERR_LEAD_NOT_FOUND:\r\n          $ok = true;\r\n          $success = false;\r\n          break;\r\n        default:\r\n      }\r\n      if (!$ok) {\r\n        if ($faultCode != null) {\r\n          if (strpos($faultCode, 'Client')) {\r\n            \/\/ This is a client error.  Check the other codes and handle.\r\n          } else if (strpos($faultCode, 'Server')) {\r\n            \/\/ This is a server error.  Call Marketo support with details.\r\n          } else {\r\n            \/\/ W3C spec has changed :)\r\n            \/\/ But seriously, Call Marketo support with details.\r\n          }\r\n        } else {\r\n          \/\/ Not a good place to be.\r\n        }\r\n      }\r\n    }\r\n    catch (Exception $ex) {\r\n      $msg = $ex-&gt;getMessage();\r\n      $req = $this-&gt;soapClient-&gt;__getLastRequest();\r\n      echo &quot;Error occurred for request: $msg\\n$req\\n&quot;;\r\n      var_dump($ex);\r\n      exit(1);\r\n    }\r\n    \r\n    return $retLead;\r\n  }\r\n\r\n  public function syncLead($key, $attrs)\r\n  {\r\n    \/\/ Build array of Attribute objects\r\n    $attrArray = array();\r\n    foreach ($attrs as $attrName =&gt; $attrValue) {\r\n      $a = new Attribute();\r\n      $a-&gt;attrName = $attrName;\r\n      $a-&gt;attrValue = $attrValue;\r\n      $attrArray[] = $a;\r\n    }\r\n    \r\n    $aryOfAttr = new ArrayOfAttribute();\r\n    $aryOfAttr-&gt;attribute = $attrArray;\r\n    \r\n    \/\/ Build LeadRecord\r\n    $leadRec = new LeadRecord();\r\n    $leadRec-&gt;leadAttributeList = $aryOfAttr;\r\n\r\n    \/\/ Set the unique lead key.\r\n    if (is_numeric($key)) {\r\n      $leadRec-&gt;Id = $key;  \/\/ Marketo system ID.\r\n    } else {\r\n      $leadRec-&gt;Email = $key; \/\/ TODO - Add email format validation - should be SMTP email address.\r\n    }\r\n    \r\n    \/\/ Build API params\r\n    $params = new paramsSyncLead();\r\n    $params-&gt;leadRecord = $leadRec;\r\n\r\n    $params-&gt;returnLead = false;  \/\/ Don't return the full lead record - just the ID.\r\n    \r\n    $options = array();\r\n\r\n    $authHdr = $this-&gt;_getAuthenticationHeader();\r\n    \r\n    try {\r\n      $success = $this-&gt;soapClient-&gt;__soapCall('syncLead', array($params), $options, $authHdr);\r\n      $resp = $this-&gt;soapClient-&gt;__getLastResponse();\r\n      \r\n      if (self::DEBUG) {\r\n        $req = $this-&gt;soapClient-&gt;__getLastRequest();\r\n        echo &quot;RAW request:\\n$req\\n&quot;;\r\n        $resp = $this-&gt;soapClient-&gt;__getLastResponse();\r\n        echo &quot;RAW response:\\n$resp\\n&quot;;\r\n      }\r\n    }\r\n    catch (SoapFault $ex) {\r\n      $ok = false;\r\n      $errCode = 1;\r\n      $faultCode = null;\r\n      if (!empty($ex-&gt;detail-&gt;serviceException-&gt;code)) {\r\n        $errCode = $ex-&gt;detail-&gt;serviceException-&gt;code;\r\n      }\r\n      if (!empty($ex-&gt;faultCode)) {\r\n        $faultCode = $ex-&gt;faultCode;\r\n      }\r\n      switch ($errCode)\r\n      {\r\n        case mktWsError::ERR_LEAD_SYNC_FAILED:\r\n          \/\/ Retry once and handle error if retry fails.\r\n          break;\r\n        default:\r\n      }\r\n      if (!$ok) {\r\n        if ($faultCode != null) {\r\n          if (strpos($faultCode, 'Client')) {\r\n            \/\/ This is a client error.  Check the other codes and handle.\r\n          } else if (strpos($faultCode, 'Server')) {\r\n            \/\/ This is a server error.  Call Marketo support with details.\r\n          } else {\r\n            \/\/ W3C spec has changed :)\r\n            \/\/ But seriously, Call Marketo support with details.\r\n          }\r\n        } else {\r\n          \/\/ Not a good place to be.\r\n        }\r\n      }\r\n    }\r\n    catch (Exception $ex) {\r\n      $msg = $ex-&gt;getMessage();\r\n      $req = $this-&gt;soapClient-&gt;__getLastRequest();\r\n      echo &quot;Error occurred for request: $msg\\n$req\\n&quot;;\r\n      var_dump($ex);\r\n      exit(1);\r\n    }\r\n    \r\n    return $success;\r\n  }\r\n\r\n  public function getCampaignsForSource()\r\n  {\r\n    $retList = null;\r\n    \r\n    $params = new paramsGetCampaignsForSource();\r\n    $params-&gt;source = 'MKTOWS';  \/\/ We want campaigns configured for access through the SOAP API\r\n    \r\n    $authHdr = $this-&gt;_getAuthenticationHeader();\r\n\t$options = array();\r\n    \r\n    try {\r\n      $success = $this-&gt;soapClient-&gt;__soapCall('getCampaignsForSource', array($params), $options, $authHdr);\r\n      \r\n      if (self::DEBUG) {\r\n        $req = $this-&gt;soapClient-&gt;__getLastRequest();\r\n        echo &quot;RAW request:\\n$req\\n&quot;;\r\n        $resp = $this-&gt;soapClient-&gt;__getLastResponse();\r\n        echo &quot;RAW response:\\n$resp\\n&quot;;\r\n      }\r\n      \r\n      if (isset($success-&gt;result-&gt;returnCount) &amp;&amp; $success-&gt;result-&gt;returnCount &gt; 0) {\r\n        if (isset($success-&gt;result-&gt;campaignRecordList-&gt;campaignRecord)) {\r\n          $retList = array();\r\n          \/\/ campaignRecordList is ArrayOfCampaignRecord from WSDL\r\n          $campRecList = $success-&gt;result-&gt;campaignRecordList-&gt;campaignRecord;\r\n          \/\/ Force to array when one 1 item is returned (quirk of PHP SOAP)\r\n          if (!is_array($campRecList)) {\r\n            $campRecList = array($campRecList);\r\n          }\r\n          \/\/ $campRec is CampaignRecord from WSDL\r\n          foreach ($campRecList as $campRec) {\r\n            $retList[$campRec-&gt;name] = $campRec-&gt;id;\r\n          }\r\n        }\r\n      }\r\n    }\r\n    catch (SoapFault $ex) {\r\n      if (self::DEBUG) {\r\n        $req = $this-&gt;soapClient-&gt;__getLastRequest();\r\n        echo &quot;RAW request:\\n$req\\n&quot;;\r\n        $resp = $this-&gt;soapClient-&gt;__getLastResponse();\r\n        echo &quot;RAW response:\\n$resp\\n&quot;;\r\n      }\r\n      $ok = false;\r\n      $errCode = !empty($ex-&gt;detail-&gt;serviceException-&gt;code)? $ex-&gt;detail-&gt;serviceException-&gt;code : 1;\r\n      $faultCode = !empty($ex-&gt;faultCode) ? $ex-&gt;faultCode : null;\r\n      switch ($errCode)\r\n      {\r\n        case mktWsError::ERR_CAMP_NOT_FOUND:\r\n          \/\/ Handle error for campaign not found\r\n          break;\r\n        default:\r\n          \/\/ Handle other errors\r\n      }\r\n      if (!$ok) {\r\n        if ($faultCode != null) {\r\n          if (strpos($faultCode, 'Client')) {\r\n            \/\/ This is a client error.  Check the other codes and handle.\r\n          } else if (strpos($faultCode, 'Server')) {\r\n            \/\/ This is a server error.  Call Marketo support with details.\r\n          } else {\r\n            \/\/ W3C spec has changed :)\r\n            \/\/ But seriously, Call Marketo support with details.\r\n          }\r\n        } else {\r\n          \/\/ Not a good place to be.\r\n        }\r\n      }\r\n    }\r\n    catch (Exception $ex) {\r\n      $msg = $ex-&gt;getMessage();\r\n      $req = $this-&gt;soapClient-&gt;__getLastRequest();\r\n      echo &quot;Error occurred for request: $msg\\n$req\\n&quot;;\r\n      var_dump($ex);\r\n      exit(1);\r\n    }\r\n    \r\n    return $retList;\r\n  }\r\n  \r\n  public function requestCampaign($campId, $leadEmail)\r\n  {\r\n    $retStat = false;\r\n    \r\n    $leadKey = new LeadKey();\r\n    $leadKey-&gt;keyType = 'IDNUM';\r\n    $leadKey-&gt;keyValue = $leadEmail;\r\n    \r\n    $leadList = new ArrayOfLeadKey();\r\n    $leadList-&gt;leadKey = array($leadKey);\r\n    \r\n    $params = new paramsRequestCampaign();\r\n    $params-&gt;campaignId = $campId;\r\n    $params-&gt;leadList = $leadList;\r\n    $params-&gt;source = 'MKTOWS';\r\n\r\n    $authHdr = $this-&gt;_getAuthenticationHeader();\r\n    \r\n    try {\r\n      $success = $this-&gt;soapClient-&gt;__soapCall('requestCampaign', array($params), $options, $authHdr);\r\n      \r\n      if (self::DEBUG) {\r\n        $req = $this-&gt;soapClient-&gt;__getLastRequest();\r\n        echo &quot;RAW request:\\n$req\\n&quot;;\r\n        $resp = $this-&gt;soapClient-&gt;__getLastResponse();\r\n        echo &quot;RAW response:\\n$resp\\n&quot;;\r\n      }\r\n      \r\n      if (isset($success-&gt;result-&gt;success)) {\r\n        $retStat = $success-&gt;result-&gt;success;\r\n      }\r\n    }\r\n    catch (SoapFault $ex) {\r\n      $ok = false;\r\n      $errCode = !empty($ex-&gt;detail-&gt;serviceException-&gt;code)? $ex-&gt;detail-&gt;serviceException-&gt;code : 1;\r\n      $faultCode = !empty($ex-&gt;faultCode) ? $ex-&gt;faultCode : null;\r\n      switch ($errCode)\r\n      {\r\n        case mktWsError::ERR_LEAD_NOT_FOUND:\r\n          \/\/ Handle error for campaign not found\r\n          break;\r\n        default:\r\n          \/\/ Handle other errors\r\n      }\r\n      if (!$ok) {\r\n        if ($faultCode != null) {\r\n          if (strpos($faultCode, 'Client')) {\r\n            \/\/ This is a client error.  Check the other codes and handle.\r\n          } else if (strpos($faultCode, 'Server')) {\r\n            \/\/ This is a server error.  Call Marketo support with details.\r\n          } else {\r\n            \/\/ W3C spec has changed :)\r\n            \/\/ But seriously, Call Marketo support with details.\r\n          }\r\n        } else {\r\n          \/\/ Not a good place to be.\r\n        }\r\n      }\r\n    }\r\n    catch (Exception $ex) {\r\n      $msg = $ex-&gt;getMessage();\r\n      $req = $this-&gt;soapClient-&gt;__getLastRequest();\r\n      echo &quot;Error occurred for request: $msg\\n$req\\n&quot;;\r\n      var_dump($ex);\r\n      exit(1);\r\n    }\r\n    \r\n    return $retStat;\r\n  }\r\n  \r\n  \/**\r\n   * Enter description here...\r\n   *\r\n   * @param string $leadEmail       Lead email\r\n   * @param string $listName        Name of static list\r\n   * @param string $sinceTimestamp  Some valid PHP time string like 2009-12-25 01:00:00\r\n   * @param int    $lastId          ID of last activity \r\n   *\/\r\n  public function wasLeadAddedToListSince($leadId, $listName, $sinceTimestamp, $lastId)\r\n  {\r\n    $wasAdded = false;\r\n    $actRec = null;\r\n    \r\n    $leadKey = new LeadKey();\r\n    $leadKey-&gt;keyType = 'IDNUM';\r\n    $leadKey-&gt;keyValue = $leadId;\r\n    $params = new paramsGetLeadActivity();\r\n    $params-&gt;leadKey = $leadKey;\r\n\r\n    $actTypes = array();\r\n  \t$actTypes[] = 'AddToList';\r\n    $actArray = new ArrayOfActivityType();\r\n    $actArray-&gt;activityType = $actTypes;\r\n    $filter = new ActivityTypeFilter();\r\n    $filter-&gt;includeTypes = $actArray;\r\n    $params-&gt;activityFilter = $filter;\r\n    \r\n    $startPos = new StreamPosition();\r\n    $dtzObj = new DateTimeZone(self::CLIENT_TZ);  \/\/ Use the correct time zone !\r\n    $dtObj = new DateTime($sinceTimestamp, $dtzObj);\r\n    $startPos-&gt;oldestCreatedAt = $dtObj-&gt;format(DATE_W3C);\r\n    $params-&gt;startPosition = $startPos;\r\n\r\n    $params-&gt;batchSize = 100;\r\n\r\n    $doPage = true;\r\n    while($doPage) {\r\n      $authHdr = $this-&gt;_getAuthenticationHeader();\r\n    \r\n      try {\r\n        $success = $this-&gt;soapClient-&gt;__soapCall('getLeadActivity', array($params), $options, $authHdr);\r\n        \r\n        if (self::DEBUG) {\r\n          $req = $this-&gt;soapClient-&gt;__getLastRequest();\r\n          echo &quot;RAW request:\\n$req\\n&quot;;\r\n          $resp = $this-&gt;soapClient-&gt;__getLastResponse();\r\n          echo &quot;RAW response:\\n$resp\\n&quot;;\r\n        }\r\n        \r\n        if (isset($success-&gt;leadActivityList)) {\r\n          \/\/ leadActivityList is LeadActivityList in WSDL\r\n          $result = $success-&gt;leadActivityList;\r\n          if ($result-&gt;returnCount &gt; 0) {\r\n            \/\/ actRecList is ArrayOfActivityRecord from WSDL\r\n            $actRecList = $result-&gt;activityRecordList;\r\n            \/\/ Force to array when one 1 item is returned (quirk of PHP SOAP)\r\n            if (!is_array($actRecList)) {\r\n              $actRecList = array($actRecList);\r\n            }\r\n            foreach ($actRecList as $actRec) {\r\n              if ($actRec-&gt;id &gt; $lastId &amp;&amp; $actRec-&gt;mktgAssetName == $listName) {\r\n                $wasAdded = true;\r\n                break 2;\r\n              }\r\n            }\r\n            $newStartPos = $success-&gt;leadActivityList-&gt;newStartPosition;\r\n            $params-&gt;startPosition = $newStartPos;\r\n          }\r\n          else {\r\n            $doPage = false;\r\n          }\r\n        }\r\n      }\r\n      catch (SoapFault $ex) {\r\n        $doPage = false;\r\n        $ok = false;\r\n        $errCode = !empty($ex-&gt;detail-&gt;serviceException-&gt;code)? $ex-&gt;detail-&gt;serviceException-&gt;code : 1;\r\n        $faultCode = !empty($ex-&gt;faultCode) ? $ex-&gt;faultCode : null;\r\n        switch ($errCode)\r\n        {\r\n          case mktWsError::ERR_LEAD_NOT_FOUND:\r\n            \/\/ Handle error for lead not found\r\n            break;\r\n          default:\r\n            \/\/ Handle other errors\r\n        }\r\n        if (!$ok) {\r\n          if ($faultCode != null) {\r\n            if (strpos($faultCode, 'Client')) {\r\n              \/\/ This is a client error.  Check the other codes and handle.\r\n            } else if (strpos($faultCode, 'Server')) {\r\n              \/\/ This is a server error.  Call Marketo support with details.\r\n            } else {\r\n              \/\/ W3C spec has changed :)\r\n              \/\/ But seriously, Call Marketo support with details.\r\n            }\r\n          } else {\r\n            \/\/ Not a good place to be.\r\n          }\r\n        }\r\n        break;\r\n      }\r\n      catch (Exception $ex) {\r\n        $msg = $ex-&gt;getMessage();\r\n        $req = $this-&gt;soapClient-&gt;__getLastRequest();\r\n        echo &quot;Error occurred for request: $msg\\n$req\\n&quot;;\r\n        var_dump($ex);\r\n        exit(1);\r\n      }\r\n    }\r\n    \r\n    return array($wasAdded, $actRec);\r\n  }\r\n}\r\n\r\nclass mktWsError\r\n{\r\n  const ERR_SEVERE_INTERNAL_ERROR = 10001;\r\n  const ERR_INTERNAL_ERROR = 20011;\r\n  const ERR_REQUEST_NOT_UNDERSTOOD = 20012;\r\n  const ERR_ACCESS_DENIED = 20013;\r\n  const ERR_AUTH_FAILED = 20014;\r\n  const ERR_REQUEST_LIMIT_EXCEEDED = 20015;\r\n  const ERR_REQ_EXPIRED = 20016;\r\n  const ERR_INVALID_REQ = 20017;\r\n  const ERR_BAD_ENCODING = 20018;\r\n  const ERR_UNSUPPORTED_OP = 20019;\r\n  \r\n  const ERR_LEAD_KEY_REQ = 20101;\r\n  const ERR_LEAD_KEY_BAD = 20102;\r\n  const ERR_LEAD_NOT_FOUND = 20103;\r\n  const ERR_LEAD_DETAIL_REQ = 20104;\r\n  const ERR_LEAD_ATTRIB_BAD = 20105;\r\n  const ERR_LEAD_SYNC_FAILED = 20106;\r\n  const ERR_ACTIVITY_KEY_BAD = 20107;\r\n  const ERR_PARAMETER_REQ = 20109;\r\n  const ERR_PARAMETER_BAD = 20110;\r\n  const ERR_LIST_NOT_FOUND = 20111;\r\n  const ERR_CAMP_NOT_FOUND = 20113;\r\n  const ERR_BAD_PARAMETER = 20114;\r\n  const ERR_BAD_STREAM_POS = 20122;\r\n  const ERR_STREAM_AT_END = 20123;\r\n  \r\n}\r\n<\/pre>\n<p>Let me know how this works out for you.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is an update to my previous post, Submitting Leads to Marketo&#8217;s SOAP API using PHP. Recently, Marketo did an update to their SOAP PHP Client and a few things changed along the way. More specifically, what information you pass in to the sync lead function. I&#8217;ll quickly go through the code needed for the new change. You might want to read the previous post to get an idea of how it all works together.<\/p>\n","protected":false},"author":2,"featured_media":3565,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[152],"tags":[288,388,391,415,22,331],"_links":{"self":[{"href":"https:\/\/ahmeddirie.com\/blog\/wp-json\/wp\/v2\/posts\/3988"}],"collection":[{"href":"https:\/\/ahmeddirie.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ahmeddirie.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ahmeddirie.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ahmeddirie.com\/blog\/wp-json\/wp\/v2\/comments?post=3988"}],"version-history":[{"count":15,"href":"https:\/\/ahmeddirie.com\/blog\/wp-json\/wp\/v2\/posts\/3988\/revisions"}],"predecessor-version":[{"id":4293,"href":"https:\/\/ahmeddirie.com\/blog\/wp-json\/wp\/v2\/posts\/3988\/revisions\/4293"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/ahmeddirie.com\/blog\/wp-json\/wp\/v2\/media\/3565"}],"wp:attachment":[{"href":"https:\/\/ahmeddirie.com\/blog\/wp-json\/wp\/v2\/media?parent=3988"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ahmeddirie.com\/blog\/wp-json\/wp\/v2\/categories?post=3988"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ahmeddirie.com\/blog\/wp-json\/wp\/v2\/tags?post=3988"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}