Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save matheswarwan/b18612b451c65cf2903b39cc52fb1aa9 to your computer and use it in GitHub Desktop.
Save matheswarwan/b18612b451c65cf2903b39cc52fb1aa9 to your computer and use it in GitHub Desktop.
SFMC SOAP Requests to update Send Email Activity in Automation Studio

Step 1: Auth token generation

Description: Generate Auth token using v2 endpoint.

  • API Type: REST

  • Endpoint: https://{tse}.auth.marketingcloudapis.com/v2/token

  • Method: POST

  • Headers:

    • Content-Type: application/json
  • Path Parameter:

    • client_id:
    • client_secret:
    • account_id:
  • Request Body:

{
  "grant_type": "client_credentials",
  "client_id": {{client_id}},
  "client_secret": {{client_secret}},
  "account_id": {{account_id}}
}

Step 2: (Optional) Get EmailSendDefinition ObjectID

Description: Fetch ObjectID of the EmailSendDefinition (Send Email Activity)

  • API Type: SOAP

  • Endpoint: https://{tse}.soap.marketingcloudapis.com/Service.asmx

  • Method: POST

  • Headers:

    • SOAPAction: Retrieve
    • Content-Type: text/xml
  • Parameters:

    • fueloauth: access_token from Auth request
  • Request Body:

<?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>
      <fueloauth xmlns="http://exacttarget.com">${"Auth"."response"."body"."access_token"}</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>EmailSendDefinition</ObjectType>
            <Properties>Name</Properties>
            <Properties>EmailSubject</Properties>
            <Properties>Description</Properties>
            <Properties>CreatedDate</Properties>
            <Properties>ModifiedDate</Properties>
            <Properties>CustomerKey</Properties>
            <Properties>CategoryID</Properties>
            <Properties>SendClassification.CustomerKey</Properties>
            <Properties>SenderProfile.CustomerKey</Properties>
            <Properties>SenderProfile.FromName</Properties>
            <Properties>SenderProfile.FromAddress</Properties>
            <Properties>DeliveryProfile.CustomerKey</Properties>
            <Properties>DeliveryProfile.SourceAddressType</Properties>
            <Properties>DeliveryProfile.PrivateIP</Properties>
            <Properties>DeliveryProfile.DomainType</Properties>
            <Properties>DeliveryProfile.PrivateDomain</Properties>
            <Properties>DeliveryProfile.HeaderSalutationSource</Properties>
            <Properties>DeliveryProfile.FooterSalutationSource</Properties>  
            <Properties>SuppressTracking</Properties>
            <Properties>IsSendLogging</Properties>
            <Properties>Email.ID</Properties>
            <Properties>CCEmail</Properties>
            <Properties>BccEmail</Properties>
            <Properties>AutoBccEmail</Properties>
            <Properties>TestEmailAddr</Properties>
            <Properties>EmailSubject</Properties>
            <Properties>DynamicEmailSubject</Properties>
            <Properties>IsMultipart</Properties>
            <Properties>IsWrapped</Properties>
            <Properties>SendLimit</Properties>
            <Properties>SendWindowOpen</Properties>
            <Properties>DeduplicateByEmail</Properties>
            <Properties>ExclusionFilter</Properties>
            <Properties>Additional</Properties>
            <Properties>SendDefinitionList</Properties>
            <Properties>IsPlatformObject</Properties>
            <Properties>SendWindowClose</Properties>
         </RetrieveRequest>
      </RetrieveRequestMsg>
  </s:Body>
</s:Envelope>
  • Response Example:
<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <env:Header xmlns:env="http://www.w3.org/2003/05/soap-envelope">
        <wsa:Action>RetrieveResponse</wsa:Action>
        <wsa:MessageID>urn:uuid:6dabaa86-adf8-4c4d-9681-910bbe382a0f</wsa:MessageID>
        <wsa:RelatesTo>urn:uuid:0635a696-3625-4939-9cf1-b2a01025ce68</wsa:RelatesTo>
        <wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
        <wsse:Security>
            <wsu:Timestamp wsu:Id="Timestamp-9b991704-d2a7-4b07-8b06-e5310eae8a3c">
                <wsu:Created>2025-01-30T08:41:28Z</wsu:Created>
                <wsu:Expires>2025-01-30T08:46:28Z</wsu:Expires>
            </wsu:Timestamp>
        </wsse:Security>
    </env:Header>
    <soap:Body>
        <RetrieveResponseMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
            <OverallStatus>OK</OverallStatus>
            <RequestID>0bc2634e-8553-4129-babd-1e88eecfe66e</RequestID>
            <Results xsi:type="EmailSendDefinition">
                <PartnerKey xsi:nil="true"/>
                <CreatedDate>2025-01-27T15:53:43.477</CreatedDate>
                <ModifiedDate>2025-01-30T02:34:12.73</ModifiedDate>
                <ObjectID xsi:nil="true"/>
                <CustomerKey>13763</CustomerKey>
                <IsPlatformObject>false</IsPlatformObject>
                <Name>DE_Api_Email</Name>
                <Description>Updated from Soap object - 2</Description>
                <CategoryID>8407</CategoryID>
                <SendClassification>
                    <PartnerKey xsi:nil="true"/>
                    <ObjectID xsi:nil="true"/>
                    <CustomerKey>Default Commercial</CustomerKey>
                </SendClassification>
                <SenderProfile>
                    <PartnerKey xsi:nil="true"/>
                    <ObjectID xsi:nil="true"/>
                    <CustomerKey>126</CustomerKey>
                    <FromName>Bell</FromName>
                    <FromAddress>[email protected]</FromAddress>
                </SenderProfile>
                <DeliveryProfile>
                    <PartnerKey xsi:nil="true"/>
                    <ObjectID xsi:nil="true"/>
                    <CustomerKey>Default</CustomerKey>
                    <SourceAddressType>DefaultPrivateIPAddress</SourceAddressType>
                    <DomainType>DefaultDomain</DomainType>
                    <HeaderSalutationSource>Default</HeaderSalutationSource>
                    <FooterSalutationSource>Default</FooterSalutationSource>
                </DeliveryProfile>
                <SuppressTracking>false</SuppressTracking>
                <IsSendLogging>true</IsSendLogging>
                <SendDefinitionList>
                    <PartnerKey xsi:nil="true"/>
                    <ObjectID>5cd608f7-e4de-ef11-ba7c-f40343d06148</ObjectID>
                    <List>
                        <PartnerKey xsi:nil="true"/>
                        <ID>80</ID>
                        <ObjectID xsi:nil="true"/>
                    </List>
                    <SendDefinitionListType>SourceList</SendDefinitionListType>
                    <CustomObjectID>3d84ef68-e3de-ef11-ba7c-f40343d06148</CustomObjectID>
                    <DataSourceTypeID>CustomObject</DataSourceTypeID>
                    <IsTestObject>false</IsTestObject>
                    <SalesForceObjectID/>
                    <Name/>
                </SendDefinitionList>
                <Email>
                    <PartnerKey xsi:nil="true"/>
                    <ID>30916</ID>
                    <ObjectID xsi:nil="true"/>
                </Email>
                <BccEmail/>
                <AutoBccEmail/>
                <TestEmailAddr/>
                <EmailSubject>DE_Api_Email</EmailSubject>
                <DynamicEmailSubject>DE_Api_Email</DynamicEmailSubject>
                <IsMultipart>true</IsMultipart>
                <IsWrapped>true</IsWrapped>
                <DeduplicateByEmail>true</DeduplicateByEmail>
                <ExclusionFilter/>
                <Additional/>
                <CCEmail/>
            </Results>
        </RetrieveResponseMsg>
    </soap:Body>
</soap:Envelope>

Step 3: Update Email & Data Extension of Send Email Activity

Description: Update Email & Data Extension of Send Email Activity

  • API Type: SOAP

  • Endpoint: https://{tse}.soap.marketingcloudapis.com/Service.asmx

  • Method: POST

  • Headers:

    • SOAPAction: Update
    • Content-Type: text/xml
  • Parameters:

    • fueloauth: access_token from Auth request
    • objectId : This is the identifying parameter and the definition mentioned will be updated
    • updatedDescription : (recommendation) Update the description with datetime stamp
    • emailId : Email ID from content builder - this is different from Customer Key / Asset ID. Todo: Get the API to fetch the emailId for a given email name
    • dataExtensionId : Data Extension ID - different from External Key. Todo: Get the API to fetch this id
  • Request Body:

<?xml version="1.0" encoding="utf-8"?>
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <soapenv:Header>
      <fueloauth xmlns="http://exacttarget.com">${"Bell"."0 - Auth"."response"."body"."access_token"}</fueloauth>
   </soapenv:Header>
   <soapenv:Body>
    <UpdateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">
         <Options>
            <SaveOptions>
               <SaveOption>
                  <PropertyName>*</PropertyName>
                  <SaveAction>UpdateOnly</SaveAction>
               </SaveOption>
            </SaveOptions>
         </Options>
         <Objects xsi:type="EmailSendDefinition">
            <PartnerKey xsi:nil="true"/>
            <ObjectID>{objectId}</ObjectID>
            <Description>{updatedDescription}</Description>
            <Email>
                <PartnerKey xsi:nil="true"/>
                <ID>{emailId}</ID>
                <ObjectID xsi:nil="true"/>
            </Email>
            <SendDefinitionList>
                <PartnerKey xsi:nil="true"/>
                <CustomObjectID>{dataExtensionId}</CustomObjectID>
                <DataSourceTypeID>CustomObject</DataSourceTypeID>
            </SendDefinitionList>
         </Objects>
      </UpdateRequest>
   </soapenv:Body>
</soapenv:Envelope>
  • Response Example:
<?xml version="1.0" encoding="utf-8" ?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <soap:Header>
        <wsa:Action>UpdateResponse</wsa:Action>
        <wsa:MessageID>urn:uuid:44a8297a-319f-400e-af53-b685a7bca0cc</wsa:MessageID>
        <wsa:RelatesTo>urn:uuid:7988f598-8518-46f1-8603-a4dbdc666315</wsa:RelatesTo>
        <wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
        <wsse:Security>
            <wsu:Timestamp wsu:Id="Timestamp-5d55085d-42b5-44b8-a631-cac407142145">
                <wsu:Created>2025-01-30T08:51:06Z</wsu:Created>
                <wsu:Expires>2025-01-30T08:56:06Z</wsu:Expires>
            </wsu:Timestamp>
        </wsse:Security>
    </soap:Header>
    <soap:Body>
        <UpdateResponse xmlns="http://exacttarget.com/wsdl/partnerAPI">
            <Results>
                <StatusCode>OK</StatusCode>
                <StatusMessage>EmailSendDefinition updated</StatusMessage>
                <OrdinalID>0</OrdinalID>
                <Object xsi:type="EmailSendDefinition">
                    <PartnerKey xsi:nil="true"/>
                    <ObjectID>6044e328-f9dc-ef11-ba7c-f40343d06148</ObjectID>
                    <Description>Updated from Soap object - 2</Description>
                    <SendDefinitionList>
                        <PartnerKey xsi:nil="true"/>
                        <ObjectID xsi:nil="true"/>
                        <CustomObjectID>3d84ef68-e3de-ef11-ba7c-f40343d06148</CustomObjectID>
                        <DataSourceTypeID>CustomObject</DataSourceTypeID>
                    </SendDefinitionList>
                    <Email>
                        <PartnerKey xsi:nil="true"/>
                        <ID>30916</ID>
                        <ObjectID xsi:nil="true"/>
                        <Subject>DE_Api_Email</Subject>
                    </Email>
                    <EmailSubject>DE_Api_Email</EmailSubject>
                </Object>
            </Results>
            <RequestID>721add47-551e-438b-b1e0-0f2cea8581a9</RequestID>
            <OverallStatus>OK</OverallStatus>
        </UpdateResponse>
    </soap:Body>
</soap:Envelope>
  • Notes:
    • Check if StatusCode & OverallStatus is OK,
    • If Error, store the details / handle
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment