Accepts an array of MObjects to be created or updated, up to a maximum to 100 per call, and returns the outcome (status) of the operation (CREATED, UPDATED, FAILED, UNCHANGED, SKIPPED) and the Marketo IDs of the MObject(s). The API can be called in one of three operation modes:
- INSERT – Only insert new objects, skip existing objects
- UPDATE – Only update existing objects, skip new objects.
- For the Program MObject, the API can only be called in the UPDATE mode to add new period cost information or add/update tags/channel for existing programs. (tags/channels must already be defined, i.e. One cannot create new tags/channels through the API)
- UPSERT – Insert new objects and update existing objects
The UPDATE and UPSERT operations use the ID as the key. In a single API call some updates may succeed and some may fail. An error message will be returned for each failure
Request
Field Name |
Required/Optional |
Description |
---|---|---|
mObjectList->mObject->type | Required | Can be one of:
|
mObjectList->mObject->id | Required | Id of the MObject. You may specify up to 100 MObjects per call. |
mObjectList->mObject->typeAttribList->typeAttrib->attrType | Required | Cost (only used while updating the Program MObject)
Can be one of:
|
mObjectList->mObject->typeAttribList->typeAttrib->attrList->attrib->name | Required | For Program MObject, the following attributes can be passed as name-value pairs:
For Cost:
For Tag/Channel:
For Opportunity MObject, all the fields from the output of the describeMObject can be passed as name-value pairs. The below list are all optional fields and the standard set of attributes. You may have additional fields on the Opportunity MObject that were created through a support request.
For OpportunityPersonRole MObject, you can supply all the fields from the output of describeMObject as name-value pairs. The standard set of attributes on OpportunityPersonRole MObject are listed here:
|
mObjAssociationList->mObjAssociation->mObjType | Optional | Used to update Opportunity/OpportunityPersonRole MObjects using the id or external key of an associated object. Associated objects can be one of:
|
mObjAssociationList->mObjAssociation->id | Optional | The id of the associated object (Lead/Company/Opportunity) |
mObjAssociationList->mObjAssociation->externalKey | Optional | A custom attribute of the associated object |
Request XML
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"?> <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>40e6d89bd2f7f0daaddaf150ce7a7ca49788ffe7</requestSignature> <requestTimestamp>2013-08-05T14:22:45-07:00</requestTimestamp> </ns1:AuthenticationHeader> </SOAP-ENV:Header> <SOAP-ENV:Body> <ns1:paramsSyncMObjects> <mObjectList> <mObject> <type>Program</type> <id>1970</id> <typeAttribList> <typeAttrib> <attrType>Cost</attrType> <attrList> <attrib> <name>Month</name> <value>2013-06</value> </attrib> <attrib> <name>Amount</name> <value>2000</value> </attrib> <attrib> <name>Id</name> <value>153</value> </attrib> </attrList> </typeAttrib> </typeAttribList> </mObject> </mObjectList> <operation>UPDATE</operation> </ns1:paramsSyncMObjects> </SOAP-ENV:Body> </SOAP-ENV:Envelope> |
Response XML
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
<?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:Body> <ns1:successSyncMObjects> <result> <mObjStatusList> <mObjStatus> <id>1970</id> <status>UPDATED</status> </mObjStatus> </mObjStatusList> </result> </ns1:successSyncMObjects> </SOAP-ENV:Body> </SOAP-ENV:Envelope> |
Sample Code – PHP
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 128 129 130 131 132 133 134 135 136 137 138 139 |
<?php $debug = true; $marketoSoapEndPoint = ""; // CHANGE ME $marketoUserId = ""; // CHANGE ME $marketoSecretKey = ""; // CHANGE ME $marketoNameSpace = "http://www.marketo.com/mktows/"; // Create Signature $dtzObj = new DateTimeZone("America/Los_Angeles"); $dtObj = new DateTime('now', $dtzObj); $timeStamp = $dtObj->format(DATE_W3C); $encryptString = $timeStamp . $marketoUserId; $signature = hash_hmac('sha1', $encryptString, $marketoSecretKey); // Create SOAP Header $attrs = new stdClass(); $attrs->mktowsUserId = $marketoUserId; $attrs->requestSignature = $signature; $attrs->requestTimestamp = $timeStamp; $authHdr = new SoapHeader($marketoNameSpace, 'AuthenticationHeader', $attrs); $options = array("connection_timeout" => 15, "location" => $marketoSoapEndPoint); if ($debug) { $options["trace"] = 1; } // Create Request //////////////////////////////// $params = prepareUpdateProgramRequest(); // -or- //$params = prepareCreateOpptyRequest(); // -or- //$params= prepareCreateOpptyPersonRoleRequest(); //////////////////////////////// $soapClient = new SoapClient($marketoSoapEndPoint ."?WSDL", $options); try { $leads = $soapClient->__soapCall('syncMObjects', array($params), $options, $authHdr); } catch(Exception $ex) { var_dump($ex); } if ($debug) { print "RAW request:\n" .$soapClient->__getLastRequest() ."\n"; print "RAW response:\n" .$soapClient->__getLastResponse() ."\n"; } function prepareUpdateProgramRequest() { $params = new stdClass(); $mObj = new stdClass(); $mObj->type = 'Program'; $mObj->id="1970"; $attrib1 = new stdClass(); $attrib1->name="Month"; $attrib1->value="2013-06"; $attrib2 = new stdClass(); $attrib2->name="Amount"; $attrib2->value="2000"; $attrib3 = new stdClass(); $attrib3->name="Id"; $attrib3->value="153"; $attribList = array ($attrib1, $attrib2, $attrib3); $costAttrib = new stdClass(); $costAttrib->attrType="Cost"; $costAttrib->attrList = $attribList; $mObj->typeAttribList= array($costAttrib); $params->mObjectList = array($mObj); $params->operation="UPDATE"; return $params; } function prepareCreateOpptyRequest() { $params = new stdClass(); $mObj = new stdClass(); $mObj->type = 'Opportunity'; $attrib1 = new stdClass(); $attrib1->name="Name"; $attrib1->value="Q1 2014"; $attrib2 = new stdClass(); $attrib2->name="Amount"; $attrib2->value="2000"; $attrib3 = new stdClass(); $attrib3->name="Probability"; $attrib3->value="80%"; $attribs = array ($attrib1, $attrib2, $attrib3); $attribList = new stdClass(); $attribList->attrib = $attribs; $mObj->attribList = $attribList; $params->mObjectList = array($mObj); $params->operation="INSERT"; return $params; } function prepareCreateOpptyPersonRoleRequest() { $params = new stdClass(); $mObj = new stdClass(); $mObj->type = 'OpportunityPersonRole'; $attrib1 = new stdClass(); $attrib1->name="OpportunityId"; $attrib1->value="64"; $attrib2 = new stdClass(); $attrib2->name="PersonId"; $attrib2->value="19"; $attrib3 = new stdClass(); $attrib3->name="Role"; $attrib3->value="Influencer/Champion"; $attribs = array ($attrib1, $attrib2, $attrib3); $attribList = new stdClass(); $attribList->attrib = $attribs; $mObj->attribList = $attribList; $params->mObjectList = array($mObj); $params->operation="INSERT"; return $params; } ?> |
Sample Code – Java
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 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 |
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.Marshaller; public class SyncMObjects { 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 //////////////////////////////// ParamsSyncMObjects request = prepareUpdateProgramRequest(); // -or- //ParamsSyncMObjects request = prepareCreateOpptyRequest(); // -or- //ParamsSyncMObjects request = prepareCreateOpptyPersonRoleRequest(); //////////////////////////////// SuccessSyncMObjects result = port.syncMObjects(request, header); JAXBContext context = JAXBContext.newInstance(SuccessSyncMObjects.class); Marshaller m = context.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(result, System.out); } catch (Exception e) { e.printStackTrace(); } } private static ParamsSyncMObjects prepareUpdateProgramRequest() { ParamsSyncMObjects request = new ParamsSyncMObjects(); request.setOperation(SyncOperationEnum.UPDATE); MObject mobj = new MObject(); mobj.setType("Program"); mobj.setId(1970); TypeAttrib typeAttrib = new TypeAttrib(); typeAttrib.setAttrType("Cost"); Attrib attrib = new Attrib(); attrib.setName("Month"); attrib.setValue("2013-06"); Attrib attrib2 = new Attrib(); attrib2.setName("Amount"); attrib2.setValue("2000"); Attrib attrib3 = new Attrib(); attrib3.setName("Id"); attrib3.setValue("153"); ArrayOfAttrib attribList = new ArrayOfAttrib(); attribList.getAttribs().add(attrib); attribList.getAttribs().add(attrib2); attribList.getAttribs().add(attrib3); typeAttrib.setAttrList(attribList); ArrayOfTypeAttrib typeAttribList = new ArrayOfTypeAttrib(); typeAttribList.getTypeAttribs().add(typeAttrib); mobj.setTypeAttribList(typeAttribList); ArrayOfMObject objList = new ArrayOfMObject(); objList.getMObjects().add(mobj); request.setMObjectList(objList); return request; } private static ParamsSyncMObjects prepareCreateOpptyRequest() { ParamsSyncMObjects request = new ParamsSyncMObjects(); request.setOperation(SyncOperationEnum.INSERT); MObject mobj = new MObject(); mobj.setType("Opportunity"); Attrib attrib = new Attrib(); attrib.setName("Name"); attrib.setValue("Q1 2014"); Attrib attrib2 = new Attrib(); attrib2.setName("Amount"); attrib2.setValue("2000"); Attrib attrib3 = new Attrib(); attrib3.setName("Probability"); attrib3.setValue("80%"); ArrayOfAttrib attribList = new ArrayOfAttrib(); attribList.getAttribs().add(attrib); attribList.getAttribs().add(attrib2); attribList.getAttribs().add(attrib3); mobj.setAttribList(attribList); ArrayOfMObject objList = new ArrayOfMObject(); objList.getMObjects().add(mobj); request.setMObjectList(objList); return request; } private static ParamsSyncMObjects prepareCreateOpptyPersonRoleRequest() { ParamsSyncMObjects request = new ParamsSyncMObjects(); request.setOperation(SyncOperationEnum.INSERT); MObject mobj = new MObject(); mobj.setType("OpportunityPersonRole"); Attrib attrib = new Attrib(); attrib.setName("OpportunityId"); attrib.setValue("64"); // Id of the opportunity created earlier Attrib attrib2 = new Attrib(); attrib2.setName("PersonId"); attrib2.setValue("19"); Attrib attrib3 = new Attrib(); attrib3.setName("Role"); attrib3.setValue("Influencer/Champion"); ArrayOfAttrib attribList = new ArrayOfAttrib(); attribList.getAttribs().add(attrib); attribList.getAttribs().add(attrib2); attribList.getAttribs().add(attrib3); mobj.setAttribList(attribList); ArrayOfMObject objList = new ArrayOfMObject(); objList.getMObjects().add(mobj); request.setMObjectList(objList); return request; } } |
Sample Code – Ruby
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 |
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 = { :m_object_list => { :m_object => { :type => "Program", :id => "1970", :type_attrib_list => { :type_attrib => { :attr_type => "Cost", :attr_list => { :attrib => { :name => "Month", :value => "2013-06" }, :attrib! => { :name => "Amount", :value => "2000" }, :attrib! => { :name => "Id", :value => "153" } } } } } }, :operation => "UPDATE" } response = client.call(:sync_m_objects, message: request) puts response |