There are scenarios where proprietary systems are used to update customer and prospect information. The Marketing team would like to have those updates reflected back in Marketo so they have the most accurate system of record to use in their marketing campaigns. Using the below approach you can setup periodic uploads to Marketo to keep your Marketo contact information updated with the data modified in that proprietary system.
The diagram below shows the API calls that are made on a set periodic timer.
As the periodic timer is triggered the client logic will first retrieve updated contacts from the proprietary system. How this is done will differ from system to system using either APIs or data exports from the proprietary system. We’ll detail the Marketo APIs that are executed once the updated contact information is retrieved.
SOAP Request for syncMultipleLeads:
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 |
<?xml version="1.0" encoding="UTF-8"?> <ns2:paramsSyncMultipleLeads xmlns:ns2="http://www.marketo.com/mktows/"> <leadRecordList> <leadRecord> <Email>henry@superstar.com</Email> <ns2:leadAttributeList> <attribute> <attrName>FirstName</attrName> <attrValue>Henry</attrValue> </attribute> <attribute> <attrName>LastName</attrName> <attrValue>Adams</attrValue> </attribute> <attribute> <attrName>Title</attrName> <attrValue>Director of Demand Generation</attrValue> </attribute> </ns2:leadAttributeList> </leadRecord> <leadRecord> <Email>ssmith@gmail.com</Email> <ns2:leadAttributeList> <attribute> <attrName>FirstName</attrName> <attrValue>Suzie</attrValue> </attribute> <attribute> <attrName>LastName</attrName> <attrValue>Smith</attrValue> </attribute> <attribute> <attrName>Title</attrName> <attrValue>VP Marketing</attrValue> </attribute> </ns2:leadAttributeList> </leadRecord> </leadRecordList> <dedupEnabled>true</dedupEnabled> </ns2:paramsSyncMultipleLeads> |
SOAP Response from the syncMultilpeLeads:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 |
<?xml version="1.0" encoding="UTF-8"?> <ns2:successSyncMultipleLeads xmlns:ns2="http://www.marketo.com/mktows/"> <result> <syncStatusList> <syncStatus> <leadId>1094593</leadId> <status>UPDATED</status> <error xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" /> </syncStatus> <syncStatus> <leadId>1094594</leadId> <status>UPDATED</status> <error xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:nil="true" /> </syncStatus> </syncStatusList> </result> </ns2:successSyncMultipleLeads> |
syncMultipleLeads will perform an UPSERT operation. If a contact within Marketo already exists based on the email address submitted, the attributes will be updated. If a contact does not exist it will be created. The response from syncMultipleLeads will return the status for each of the contacts submitted.
The <attrName/> values within the <leadAttributeList/> must match the SOAP API Name defined for that Marketo subscription. You can discover the SOAP API Names within the field management section within Marketo admin panel by exporting the field names.
The field names will be exported into an excel file as seen below.
See the below sample Java program that executes the scenario described 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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 |
import com.marketo.mktows.*; import java.net.URL; import javax.xml.namespace.QName; import java.text.DateFormat; import java.text.SimpleDateFormat; import java.util.Date; import javax.crypto.Mac; import javax.crypto.spec.SecretKeySpec; import org.apache.commons.codec.binary.Hex; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.Marshaller; import java.util.*; public class SyncMultipleLeadsExample { public static void main(String[] args) { try { URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL"); String marketoUserId = "CHANGE ME"; String marketoSecretKey = "CHANGE ME"; QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService"); MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName); MktowsPort port = service.getMktowsApiSoapPort(); // Create Signature DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ"); String text = df.format(new Date()); String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22); String encryptString = requestTimestamp + marketoUserId ; SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1"); Mac mac = Mac.getInstance("HmacSHA1"); mac.init(secretKey); byte[] rawHmac = mac.doFinal(encryptString.getBytes()); char[] hexChars = Hex.encodeHex(rawHmac); String signature = new String(hexChars); // Set Authentication Header AuthenticationHeader header = new AuthenticationHeader(); header.setMktowsUserId(marketoUserId); header.setRequestTimestamp(requestTimestamp); header.setRequestSignature(signature); // Create Request ParamsSyncMultipleLeads request = new ParamsSyncMultipleLeads(); ObjectFactory objectFactory = new ObjectFactory(); JAXBElement dedup = objectFactory.createParamsSyncMultipleLeadsDedupEnabled(true); request.setDedupEnabled(dedup); // The list of contacts defined here would be retrieved from the proprietary system Contact contact = new Contact("Henry","Adams","henry@superstar.com", "Director of Demand Generation"); Contact contact2 = new Contact("Suzie","Smith","ssmith@gmail.com", "VP Marketing"); ArrayList updatedContacts = new ArrayList(); updatedContacts.add(contact); updatedContacts.add(contact2); ArrayOfLeadRecord arrayOfLeadRecords = new ArrayOfLeadRecord(); Iterator it = updatedContacts.iterator(); while(it.hasNext()) { Contact c = it.next(); LeadRecord leadRec = new LeadRecord(); JAXBElement email = objectFactory.createLeadRecordEmail(c.email); leadRec.setEmail(email); Attribute attr1 = new Attribute(); attr1.setAttrName("FirstName"); attr1.setAttrValue(c.fname); Attribute attr2 = new Attribute(); attr2.setAttrName("LastName"); attr2.setAttrValue(c.lname); Attribute attr3 = new Attribute(); attr3.setAttrName("Title"); attr3.setAttrValue(c.title); ArrayOfAttribute aoa = new ArrayOfAttribute(); aoa.getAttributes().add(attr1); aoa.getAttributes().add(attr2); aoa.getAttributes().add(attr3); QName qname = new QName("http://www.marketo.com/mktows/", "leadAttributeList"); JAXBElement attrList = new JAXBElement(qname, ArrayOfAttribute.class, aoa); leadRec.setLeadAttributeList(attrList); arrayOfLeadRecords.getLeadRecords().add(leadRec); } request.setLeadRecordList(arrayOfLeadRecords); JAXBContext context = JAXBContext.newInstance(SuccessSyncMultipleLeads.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(request, System.out); SuccessSyncMultipleLeads result = port.syncMultipleLeads(request, header); m.marshal(result, System.out); } catch(Exception e) { e.printStackTrace(); } } public static class Contact { public String fname, lname, email, title; public Contact(String fname, String lname, String email, String title) { this.fname = fname; this.lname = lname; this.email = email; this.title = title; } } } |
* 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.