When synchronizing contact and lead records between systems like a proprietary CRM or data warehouse, it is a common requirement to associate a lead record with a unique system identifier. In Marketo you can create or update a lead record through a syncMultipleLeads API call using your unique system identifier. To accomplish this, you would store your unique system identifier (primary key) as a foreign key in Marketo. The name of this field in Marketo to store a foreign key is foreignSysPersonId.
Here are three important things to note:
- foreignSysPersonId is not visible in Marketo’s UI. So it is a best practice to also populate a custom attribute field with this value.
- foreignSysPersonId is unique to a lead, but a lead can have more than one foreignSysPersonId.
- foreignSysPersonId cannot be updated or deleted, but can be reassigned to another record.
We’ll show how to make a call to the syncMultipleLeads API to write a foreignSysPersonId value to two existing lead records in Marketo.
How to Write foreignSysPersonId Using syncMultipleLeads API
You can insert a new lead record and specify the foreignSysPersonId. You can also add it to an existing lead by specifying both Marketo ID and the foreignSysPersonId. We’ll walk you through the latter case.
Request XML for syncMultipleLeads SOAP API Call
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://www.marketo.com/mktows/"> <SOAP-ENV:Header> <ns1:AuthenticationHeader> <mktowsUserId>demo17_1_809934544BFABAE58E5D27</mktowsUserId> <requestSignature>b5e21953ae9f1b263e644da5eccce9ff33802513</requestSignature> <requestTimestamp>2013-08-01T18:22:30-07:00</requestTimestamp> </ns1:AuthenticationHeader> </SOAP-ENV:Header> <SOAP-ENV:Body> <ns1:paramsSyncMultipleLeads> <leadRecordList> <leadRecord> <leadId>1090240</leadId> <foreignSysPersonId>1224191</foreignSysPersonId> <leadAttributeList> <attribute> <attrName>Company</attrName> <attrValue>Marketo1000</attrValue> </attribute> <attribute> <attrName>Phone</attrName> <attrValue>650-555-1000</attrValue> </attribute> </leadAttributeList> </leadRecord> <leadRecord> <leadId>1090239</leadId> <foreignSysPersonId>1224192</foreignSysPersonId> <leadAttributeList> <attribute> <attrName>Company</attrName> <attrValue>Marketo1001</attrValue> </attribute> <attribute> <attrName>Phone</attrName> <attrValue>650-555-1001</attrValue> </attribute> </leadAttributeList> </leadRecord> </leadRecordList> <dedupEnabled>true</dedupEnabled> </ns1:paramsSyncMultipleLeads> </SOAP-ENV:Body> </SOAP-ENV:Envelope> |
Response XML for syncMultipleLeads SOAP API Call
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 |
<?xml version="1.0" encoding="UTF-8"?> <SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:ns1="http://www.marketo.com/mktows/"> <SOAP-ENV:Body> <ns1:successSyncMultipleLeads> <result> <syncStatusList> <syncStatus> <leadId>1090240</leadId> <status>UPDATED</status> <error xsi:nil="true" /> </syncStatus> <syncStatus> <leadId>1090239</leadId> <status>UPDATED</status> <error xsi:nil="true" /> </syncStatus> </syncStatusList> </result> </ns1:successSyncMultipleLeads> </SOAP-ENV:Body> </SOAP-ENV:Envelope> |
See below a sample Ruby program that will output the Request XML above.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 |
require 'savon' # Use version 2.0 Savon gem require 'date' mktowsUserId = "" # CHANGE ME marketoSecretKey = "" # CHANGE ME marketoSoapEndPoint = "" # CHANGE ME marketoNameSpace = "http://www.marketo.com/mktows/" #Create Signature Timestamp = DateTime.now requestTimestamp = Timestamp.to_s encryptString = requestTimestamp + mktowsUserId digest = OpenSSL::Digest.new('sha1') hashedsignature = OpenSSL::HMAC.hexdigest(digest, marketoSecretKey, encryptString) requestSignature = hashedsignature.to_s #Create SOAP Header headers = { 'ns1:AuthenticationHeader' => { "mktowsUserId" => mktowsUserId, "requestSignature" => requestSignature, "requestTimestamp" => requestTimestamp } } client = Savon.client(wsdl: 'http://app.marketo.com/soap/mktows/2_3?WSDL', soap_header: headers, endpoint: marketoSoapEndPoint, open_timeout: 90, read_timeout: 90, namespace_identifier: :ns1, env_namespace: 'SOAP-ENV') #Create Request request = { :lead_record_list => { :lead_record => { :lead_id => "1090240", :foreign_sys_person_id => "1224191", :lead_attribute_list => { :attribute => { :attr_name => "Company", :attr_value => "Marketo1000" }, :attribute! => { :attr_name => "Phone", :attr_value => "650-555-1000" } } }, :lead_record! => { :lead_id => "1090239", :foreign_sys_person_id => "1224192", :lead_attribute_list => { :attribute => { :attr_name => "Company", :attr_value => "Marketo1001" }, :attribute! => { :attr_name => "Phone", :attr_value => "650-555-1001" } } } }, :dedup_enabled => "True" } response = client.call(:sync_multiple_leads, message: request) puts response |
* This article contains code used to implement custom integrations. Due to its customized nature, The Marketo Technical Support team is unable to troubleshoot custom work. Please do not attempt to implement the following code sample without appropriate technical experience, or access to an experienced developer.