SOLVED

Re: SyncLead-Creates lead instead of updating lead

Go to solution
Anonymous
Not applicable

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;

        }

Tags (3)
1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Re: SyncLead-Creates lead instead of updating lead

This was the missing setting:

LeadRec.IdSpecified = true;

Works now!

View solution in original post

1 REPLY 1
Anonymous
Not applicable

Re: SyncLead-Creates lead instead of updating lead

This was the missing setting:

LeadRec.IdSpecified = true;

Works now!