Skip to main content

SFMC API snippets

Insert DE without Primary Key via SOAP API
POST /Service.asmx HTTP/1.1
Host: {{et_subdomain}}.soap.marketingcloudapis.com
Content-Type: text/xml
Content-Length: 2283

<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<a:Action s:mustUnderstand="1">Create</a:Action>
<a:To s:mustUnderstand="1">https://{{et_subdomain}}.soap.marketingcloudapis.com/Service.asmx</a:To>
<fueloauth xmlns="http://exacttarget.com">{{dne_etAccessToken}}</fueloauth>
</s:Header>
<s:Body xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<CreateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">
<Objects xsi:type="DataExtensionObject">
<PartnerKey xsi:nil="true" />
<ObjectID xsi:nil="true" />
<CustomerKey>_Your-DE-CusotomerKey_</CustomerKey>
<Properties>
<Property>
<Name>EmpEmail</Name>
<Value>vishalkumarcv@yopmail.com</Value>
</Property>
<Property>
<Name>EmpName</Name>
<Value>SFMCninja</Value>
</Property>
<Property>
<Name>Level</Name>
<Value>Gold</Value>
</Property>
<Property>
<Name>FormSubmitted</Name>
<Value>False</Value>
</Property>

</Properties>
</Objects>
</CreateRequest>
</s:Body>
</s:Envelope>
Soap API for Unsub Log Event
POST /Service.asmx HTTP/1.1
Host: xxxxx.soap.marketingcloudapis.com
Content-Type: text/xml
Content-Length: 1711

<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<a:Action s:mustUnderstand="1">Update</a:Action>
<a:To s:mustUnderstand="1">https://{{et_subdomain}}.soap.marketingcloudapis.com/Service.asmx</a:To>
<fueloauth xmlns="http://exacttarget.com">{{access_token}}</fueloauth>
</s:Header>
<s:Body
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<ExecuteRequestMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
<Requests>
<Name>LogUnsubEvent</Name>
<Parameters>
<Name>SubscriberKey</Name>
<Value>TestSubKey01</Value>
</Parameters>
<Parameters>
<Name>EmailAddress</Name>
<Value>vishalkumarcv@yopmail.com</Value>
</Parameters>
</Requests>
</ExecuteRequestMsg>
</s:Body>
</s:Envelope>
Retrieve Subscriber details via SOAP API
POST /Service.asmx HTTP/1.1
Host: {{et_subdomain}}.soap.marketingcloudapis.com
Content-Type: text/xml
Content-Length: 2011

<?xml version="1.0" encoding="UTF-8"?>
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
<s:Header>
<a:Action s:mustUnderstand="1">Update</a:Action>
<a:To s:mustUnderstand="1">https://{{et_subdomain}}.soap.marketingcloudapis.com/Service.asmx</a:To>
<fueloauth xmlns="http://exacttarget.com">{{dne_etAccessToken}}</fueloauth>
</s:Header>
<s:Body
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<RetrieveRequestMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
<RetrieveRequest>
<ObjectType>Subscriber</ObjectType>
<Properties>CreatedDate</Properties>
<Properties>Client.ID</Properties>
<Properties>EmailAddress</Properties>
<Properties>SubscriberKey</Properties>
<Properties>Status</Properties>
<Properties>UnsubscribedDate</Properties>
<Properties>EmailTypePreference</Properties>
<Filter xsi:type="SimpleFilterPart">
<Property>SubscriberKey</Property>
<SimpleOperator>equals</SimpleOperator>
<Value>vishalkumarcv@yopmail.com</Value>
</Filter>
</RetrieveRequest>
</RetrieveRequestMsg>
</s:Body>
</s:Envelope>
REST API to retrieve rows from DE using Key
GET /data/v1/customobjectdata/key/_YourDataExtensionKey_/rowset/ HTTP/1.1
Host: {{et_subdomain}}.rest.marketingcloudapis.com
Authorization: Bearer {{dne_etAccessToken}}