Package com.avoka.component.marketo
Class MarketoClient
- java.lang.Object
-
- com.avoka.component.marketo.MarketoClient
-
public class MarketoClient extends Object
Provides a Marketo SOAP Web Service API Client.syncLead Example
This Groovy Delivery Process service example created or updates the visitors Marketo LeadRecord using the submitted form data.
import com.avoka.component.marketo.MarketoClient import com.avoka.component.xml.XmlDoc def xmlDoc = new XmlDoc(submissionXml); def email = xmlDoc.getText('//Name/Email') def attrs = [:] attrs["FirstName"] = xmlDoc.getText('//Name/Firstname') attrs["LastName"] = xmlDoc.getText('//Name/Surname') attrs["Company"] = xmlDoc.getText('//Name/OrganisationName') attrs["Phone"] = xmlDoc.getText('//Name/ContactPhoneNo') attrs["Country"] = xmlDoc.getText('//Name/Location/Country') attrs["State"] = xmlDoc.getText('//Name/Location/State') attrs["LeadSource"] = "X-Avoka SFF Web Trial" def url = "https://752-trz-736.mktoapi.com/soap/mktows/1_6?wsdl" def accessKey = "tvota1_4335999551B0A84F0161F5" def secretKey = "51513245184488185511BB00AA885501001167F70671" // Create Marketo WS Client def marketoClient = new MarketoClient(url, accessKey, secretKey) // Get Marketo Vistor Cookie def trackingCookie = marketoClient.getCookieValue(submission.getRequestCookie()) // Create Lead Record def leadRecord = marketoClient.syncLead(email, attrs, trackingCookie)
getLead Example
This Groovy Form Prefill service example looks up the users Marketo LeadRecord using a Marketo tracking cookie. If the LeadRecord is found the form is prefilled with the users lead record attributes.
import com.avoka.component.marketo.MarketoClient import com.avoka.component.xml.XmlDoc def url = "https://752-trz-736.mktoapi.com/soap/mktows/1_6?wsdl" def accessKey = "tvota1_4335999551B0A84F0161F5" def secretKey = "51513245184488185511BB00AA885501001167F70671" // Create Marketo WS Client def marketoClient = new MarketoClient(url, accessKey, secretKey) // Get Marketo Vistor Cookie def requestCookie = request.getHeader("Cookie") def cookieValue = marketoClient.getCookieValue(requestCookie) if (cookieValue != null) { // Lookup Marketo Lead Record def leadRecord = marketoClient.getLead(cookieValue) if (leadRecord != null) { def attrs = leadRecord.attributes def xmlDoc = new XmlDoc(schemaSeed) xmlDoc.setText('/AvokaSmartForm/YourDetails/Name/Email', leadRecord.email) xmlDoc.setText('/AvokaSmartForm/YourDetails/Name/Firstname', attrs["FirstName"]) xmlDoc.setText('/AvokaSmartForm/YourDetails/Name/Surname', attrs["LastName"]) xmlDoc.setText('/AvokaSmartForm/YourDetails/Name/OrganisationName', attrs["Company"]) xmlDoc.setText('/AvokaSmartForm/YourDetails/Name/ContactPhoneNo', attrs["Phone"]) xmlDoc.setText('/AvokaSmartForm/YourDetails/Name/Location/Country', attrs["Country"]) } } return null
- Since:
- 3.6.0
- See Also:
LeadRecord
-
-
Constructor Summary
Constructors Constructor Description MarketoClient(String url, String accessKey, String encryptionKey)
Create a Marketo Web Service client based on the SOAP endpoint URL, access key (UserID) and encryption key.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected String
calculateHMAC(String data, String key)
Calculate HMAC signature.protected LeadRecord
createLeadRecord(Element element)
Create a LeadRecord from the given 'leadRecord' XML response element.String
getCookieValue(String cookieHeader)
Return the Marketo Cookie value from the given cookie request header.LeadRecord
getLead(String cookie)
Return the LeadRecord specified by the given Marketo cookie (_mkto_trk).protected String
getProperty(String propName)
Load property from the service class specific property file.protected Map<String,Object>
getSoapModel()
Create a base SOAP model with authorization parameters calculated and include.LeadRecord
syncLead(String email, Map<String,String> attributes, String cookie)
Create or update a LeadRecord with the given email, attributes and Marketo cookie (_mkto_trk).
-
-
-
Constructor Detail
-
MarketoClient
public MarketoClient(String url, String accessKey, String encryptionKey) throws MalformedURLException
Create a Marketo Web Service client based on the SOAP endpoint URL, access key (UserID) and encryption key.Example
def url = "https://752-trz-736.mktoapi.com/soap/mktows/1_6?wsdl" def accessKey = "tvota1_4335999551B0A84F0161F5" def secretKey = "51513245184488185511BB00AA885501001167F70671" // Create Marketo WS Client def marketoClient = new MarketoClient(url, accessKey, secretKey)
- Parameters:
url
- the SOAP endpoint URLaccessKey
- the user access key (UserID)encryptionKey
- the encryption key- Throws:
MalformedURLException
- if the URL is not valid
-
-
Method Detail
-
getCookieValue
public String getCookieValue(String cookieHeader)
Return the Marketo Cookie value from the given cookie request header.- Parameters:
cookieHeader
- the request cookie header- Returns:
- the cookie value if found or null otherwise
-
getLead
public LeadRecord getLead(String cookie) throws IOException
Return the LeadRecord specified by the given Marketo cookie (_mkto_trk).- Parameters:
cookie
- the Marketo cookie value- Returns:
- the LeadRecord
- Throws:
IOException
- if an error occurs
-
syncLead
public LeadRecord syncLead(String email, Map<String,String> attributes, String cookie) throws IOException
Create or update a LeadRecord with the given email, attributes and Marketo cookie (_mkto_trk).- Parameters:
email
- the lead emailattributes
- the lead attributescookie
- the Marketo cookie value- Returns:
- the LeadRecord
- Throws:
IOException
- if an error occurs
-
getProperty
protected String getProperty(String propName)
Load property from the service class specific property file.- Parameters:
propName
- the classpath property name to load- Returns:
- the property value
-
getSoapModel
protected Map<String,Object> getSoapModel()
Create a base SOAP model with authorization parameters calculated and include.- Returns:
- a base SOAP model with authorization parameters calculated and include.
-
calculateHMAC
protected String calculateHMAC(String data, String key) throws NoSuchAlgorithmException, InvalidKeyException
Calculate HMAC signature.- Parameters:
data
- Input data to be signed.key
- Secret signing key.- Returns:
- HMAC (RFC 2104) signature converted to HEX.
- Throws:
NoSuchAlgorithmException
InvalidKeyException
-
createLeadRecord
protected LeadRecord createLeadRecord(Element element)
Create a LeadRecord from the given 'leadRecord' XML response element.- Parameters:
element
- the 'leadRecord' XML response element- Returns:
- the LeadRecord
-
-