1 Reply Latest reply on Sep 17, 2015 6:57 AM by 1aba43763b6959dcdae9e506215d1b8c74619a9d

    SyncLead-Creates lead instead of updating lead

      I am using the SOAP api for .net and following the example code to update a lead.  When I step through the code I see that I am carrying the right Marketo Lead ID just before the call to SyncLead however it creates a new lead every time.  I am using the Marketo Lead ID instead of the email to update the contact.

       

      private static string SyncLead(int MarketoContactID, ref Marketo_WS_2_0.ResultSyncLead rs, string userID, string EncryptionKey, Marketo_WS_2_0.Attribute[] attribList)

              {

                  Marketo_WS_2_0.SuccessSyncLead response = new Marketo_WS_2_0.SuccessSyncLead();

                  string results = "";

                  string requestTimeStamp = ConvertDateToW3CTime(DateTime.Now);

                  string stringToEncrypt = requestTimeStamp + userID;

                  string message;

                  key = EncryptionKey;

                  message = stringToEncrypt;

                  System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();

                  byte[] keyByte = encoding.GetBytes(key);

                  HMACSHA1 hmacsha1 = new HMACSHA1(keyByte);

                  byte[] messageBytes = encoding.GetBytes(message);

                  byte[] hashmessage = hmacsha1.ComputeHash(messageBytes);

                  string header = ByteToString(hashmessage);

                  Marketo_WS_2_0.MktowsContextHeaderInfo ws_context = new Marketo_WS_2_0.MktowsContextHeaderInfo();

                  ws_context = null;

                  Marketo_WS_2_0.AuthenticationHeaderInfo ws_header = new Marketo_WS_2_0.AuthenticationHeaderInfo();

                  ws_header.mktowsUserId = userID;

                  ws_header.requestSignature = header.ToLower();

                  ws_header.requestTimestamp = requestTimeStamp;

                  Marketo_WS_2_0.ParamsSyncLead ws_lead = new Marketo_WS_2_0.ParamsSyncLead();

                  Marketo_WS_2_0.LeadRecord LeadRec = new Marketo_WS_2_0.LeadRecord();

                  LeadRec.Id = MarketoContactID;

                  LeadRec.leadAttributeList = attribList;

                  ws_lead.leadRecord = LeadRec;

                  try

                  {

                      MktowsPortClient Client = new MktowsPortClient();

                      response = Client.syncLead(ws_header, ws_context, ws_lead);

                      results = "";

                      rs = response.result;

                  }

                  catch (Exception e)

                  {

                      results = e.Message;

                      rs = null;

                  }

                 return results;

              }