Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function syncLead($key, $attrs)
- {
- // Build array of Attribute objects
- $attrArray = array();
- foreach ($attrs as $attrName => $attrValue) {
- $a = new Attribute();
- $a->attrName = $attrName;
- $a->attrValue = $attrValue;
- $attrArray[] = $a;
- }
- $aryOfAttr = new ArrayOfAttribute();
- $aryOfAttr->attribute = $attrArray;
- // Build LeadRecord
- $leadRec = new LeadRecord();
- $leadRec->leadAttributeList = $aryOfAttr;
- // Set the unique lead key.
- if (is_numeric($key)) {
- $leadRec->Id = $key; // Marketo system ID.
- } else {
- $leadRec->Email = $key; // TODO - Add email format validation - should be SMTP email address.
- }
- // Build API params
- $params = new paramsSyncLead();
- $params->leadRecord = $leadRec;
- $params->returnLead = false; // Don't return the full lead record - just the ID.
- $options = array();
- $authHdr = $this->_getAuthenticationHeader();
- try {
- $success = $this->connection->__soapCall('syncLead', array(
- $params
- ), $options, $authHdr);
- $resp = $this->connection->__getLastResponse();
- } catch (SoapFault $ex) {
- // error_log(print_r($ex, true));
- $ok = false;
- $errCode = 1;
- $faultCode = null;
- if (! empty($ex->detail->serviceException->code)) {
- $errCode = $ex->detail->serviceException->code;
- }
- if (! empty($ex->faultCode)) {
- $faultCode = $ex->faultCode;
- }
- switch ($errCode) {
- case mktWsError::ERR_LEAD_SYNC_FAILED:
- // Retry once and handle error if retry fails.
- break;
- default:
- }
- if (! $ok) {
- if ($faultCode != null) {
- if (strpos($faultCode, 'Client')) {
- // This is a client error. Check the other codes and handle.
- } else
- if (strpos($faultCode, 'Server')) {
- // This is a server error. Call Marketo support with details.
- } else {
- // W3C spec has changed :)
- // But seriously, Call Marketo support with details.
- }
- } else {
- // Not a good place to be.
- }
- }
- } catch (Exception $ex) {
- $msg = $ex->getMessage();
- $req = $this->connection->__getLastRequest();
- echo "Error occurred for request: $msg\n$req\n";
- var_dump($ex);
- exit(1);
- }
- return $success;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement