Advertisement
Guest User

Untitled

a guest
Oct 6th, 2014
265
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.95 KB | None | 0 0
  1. public function syncLead($key, $attrs)
  2.     {
  3.         // Build array of Attribute objects
  4.         $attrArray = array();
  5.         foreach ($attrs as $attrName => $attrValue) {
  6.             $a = new Attribute();
  7.             $a->attrName = $attrName;
  8.             $a->attrValue = $attrValue;
  9.             $attrArray[] = $a;
  10.         }
  11.        
  12.         $aryOfAttr = new ArrayOfAttribute();
  13.         $aryOfAttr->attribute = $attrArray;
  14.        
  15.         // Build LeadRecord
  16.         $leadRec = new LeadRecord();
  17.         $leadRec->leadAttributeList = $aryOfAttr;
  18.        
  19.         // Set the unique lead key.
  20.         if (is_numeric($key)) {
  21.             $leadRec->Id = $key; // Marketo system ID.
  22.         } else {
  23.             $leadRec->Email = $key; // TODO - Add email format validation - should be SMTP email address.
  24.         }
  25.        
  26.         // Build API params
  27.         $params = new paramsSyncLead();
  28.         $params->leadRecord = $leadRec;
  29.        
  30.         $params->returnLead = false; // Don't return the full lead record - just the ID.
  31.        
  32.         $options = array();
  33.        
  34.         $authHdr = $this->_getAuthenticationHeader();
  35.        
  36.         try {
  37.             $success = $this->connection->__soapCall('syncLead', array(
  38.                 $params
  39.             ), $options, $authHdr);
  40.             $resp = $this->connection->__getLastResponse();
  41.         } catch (SoapFault $ex) {
  42.             // error_log(print_r($ex, true));
  43.             $ok = false;
  44.             $errCode = 1;
  45.             $faultCode = null;
  46.             if (! empty($ex->detail->serviceException->code)) {
  47.                 $errCode = $ex->detail->serviceException->code;
  48.             }
  49.             if (! empty($ex->faultCode)) {
  50.                 $faultCode = $ex->faultCode;
  51.             }
  52.             switch ($errCode) {
  53.                 case mktWsError::ERR_LEAD_SYNC_FAILED:
  54.                     // Retry once and handle error if retry fails.
  55.                     break;
  56.                 default:
  57.             }
  58.             if (! $ok) {
  59.                 if ($faultCode != null) {
  60.                     if (strpos($faultCode, 'Client')) {
  61.                         // This is a client error. Check the other codes and handle.
  62.                     } else
  63.                         if (strpos($faultCode, 'Server')) {
  64.                             // This is a server error. Call Marketo support with details.
  65.                         } else {
  66.                             // W3C spec has changed :)
  67.                             // But seriously, Call Marketo support with details.
  68.                         }
  69.                 } else {
  70.                     // Not a good place to be.
  71.                 }
  72.             }
  73.         } catch (Exception $ex) {
  74.             $msg = $ex->getMessage();
  75.             $req = $this->connection->__getLastRequest();
  76.             echo "Error occurred for request: $msg\n$req\n";
  77.             var_dump($ex);
  78.             exit(1);
  79.         }
  80.        
  81.         return $success;
  82.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement