I've been trying to find some information as in how to add a certain email to a suppression list in Marketing Cloud via Apex, but at the end of the day, I haven't found any information I could really understand.

I've seen the SOAP envelopes in the Marketing Cloud API docs, but I don't really know how to work with those envelopes or to be honest how to actually make the callout since I've only developed integrations using REST APIs.

If you guys could provide me some insight into how to connect to the Mkt Cloud API as well as use the envelopes provided by the docs, it'd be great! :)

Thanks in advance!

  • developer.salesforce.com/docs/… this is the api reference. you can use the rest api if you want, but you don't have the same features in the rest and soap api
    – Torsen
    Commented Dec 11, 2017 at 14:55
  • 1
    @Torsen hey :) I figured some time ago that I can can authenticate using the auth.exacttargetapis.com/v1/requestToken endpoint. The problem is I don't really understand how envelopes are supposed to be used. I'm trying to use the SOAP API. Commented Dec 11, 2017 at 15:20
  • Are you just interested in how to implement SOAP Calls in Apex?
    – Patlatus
    Commented Dec 11, 2017 at 15:21

1 Answer 1


So first of all you need to perform login action to retrieve fuel OAuth token.

Request format is following due to the documentation

POST https://auth.exacttargetapis.com/v1/requestToken
Content-Type: application/json
    "clientId": "YOUR_CLIENT_ID",
    "clientSecret": "YOUR_CLIENT_SECRET"

Response is following:

200 OK
    "accessToken": "YOUR_ACCESS_TOKEN"
    "expiresIn": 3600

To perform such callouts, you need some Apex class with the following method

private static String makeSimpleJSONPostCall(String endPoint, String soapBody){
    Http h = new Http();
    HttpRequest r = new HttpRequest();
    HttpResponse res = h.send(r);
    return r.getBody();

Now you can perform get OAuth token request using the following form

private static String MARKETING_CLOUD_AUTH_URL = 'https://auth.exacttargetapis.com/v1/reaquestToken';
private static String ACCESS_TOKEN = 'accessToken';
private static String getMarketingCloudOAuthToken(String clientId, String clientSecret){
    String responseBody = makeSimpleJSONPostCall(
        JSON.serialize( new Map<String, String>{
            'clientId' => clientId,
            'clientSecret' => clientSecret
        } )
    return ((Map<String, String>) JSON.deserialize(responseBody, Map<String, String>.class)).get( ACCESS_TOKEN ); 

The method above assumes successful authorization. You might consider case when res.getStatusCode() != 200, in such case method getMarketingCloudOAuthToken might throw an exception.

Next, you need to send SOAP Envelope example from the document you provided

<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
      <Security xmlns="https://www.marketingcloud.com/">
      <UpdateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">
         <Objects xsi:type="Subscriber">
            <PartnerKey xsi:nil="true"/>
            <ObjectID xsi:nil="true"/>
            <EmailAddress>[email protected]</EmailAddress>
               <PartnerKey xsi:nil="true"/>
               <ObjectID xsi:nil="true"/>

You just need to perform HTTPCallout from Apex like this

private static String makeHTTPXMLPost(String endPoint, String soapBody){
    Http h = new Http();
    HttpRequest r = new HttpRequest();
    HttpResponse s = h.send(r);
    return s.getBody();

You can use makeHTTPXMLPost method in the following format

private static String performMCAction(String accessToken, String email, String listId, String status, String action){
    String soapEnvelopeTemplate = '    <Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">'+
    '       <Header>'+
    '          <Security xmlns="https://www.marketingcloud.com/">'+
    '             <fueloauth>{0}</fueloauth>'+
    '          </Security>'+
    '       </Header>'+
    '       <Body>'+
    '          <UpdateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">'+
    '             <Objects xsi:type="Subscriber">'+
    '                <PartnerKey xsi:nil="true"/>'+
    '                <ObjectID xsi:nil="true"/>'+
    '                <EmailAddress>{1}</EmailAddress>'+
    '                <Lists>'+
    '                   <PartnerKey xsi:nil="true"/>'+
    '                   <ObjectID xsi:nil="true"/>'+
    '                   <ID>{2}</ID>'+
    '                   <Status>{3}</Status>'+
    '                   <Action>{4}</Action>'+
    '                </Lists>'+
    '             </Objects>'+
    '          </UpdateRequest>'+
    '       </Body>'+
    '    </Envelope>';
    String body = String.format(template, new String[]{accessToken, email, listId, status, action});
    return makeHTTPXMLPost( 'https://auth.exacttargetapis.com/' , body );

I hope this would help.

Important point: to make Apex HTTP Callout work, you need to add marketing cloud URL to remote site settings. You can do this following this link:


for production and developer edition instances or this link


for sandboxes and after you follow this link click save to add marketing cloud URL to remote site settings.

  • Comments are not for extended discussion; this conversation has been moved to chat.
    – Adrian Larson
    Commented Aug 1, 2018 at 16:05

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .