Retrieve an Email

Marketing Cloud Engagement has a new model for storing, finding, managing, creating, sharing, and distributing all content-related objects. Access the objects created with the new Content Builder tools using the REST API. Your existing SOAP API integrations only function with the Classic tools.

This page contains information about retrieving an email message via the SOAP API.

Why Retrieve an Email 

You can retrieve an email message for use in an email send or to update the information contained within the email.

How to Retrieve anEmail 

Use the sample code below as a model to construct your own API code.

Sample .NET Code 

1//Retrieve Email named "Sample"
2        //Local variables
3        SoapClient client = new SoapClient();
4        APIObject[] Results;
5        String requestID;
6        String status;
7        // Instantiate the retrieve request
8        RetrieveRequest rr = new RetrieveRequest();
9        rr.ObjectType = "Email";//required
10        // Setting up a simple filter
11        SimpleFilterPart sf = new SimpleFilterPart();
12        sf.SimpleOperator = SimpleOperators.equals;
13        sf.Property = "Name";
14        sf.Value = new String[] { "Sample" };
15        //Add Filter
16        rr.Filter = sf;
17        rr.Properties = new string[] { "ID", "Name" };//required
18        status = client.Retrieve(rr, out requestID, out Results);
19        Email email = (Email)Results[0];

Sample Java Code (Axis 1.4) 

1public Email testGetEmailById() throws RemoteException {
2Soap stub = init();
3RetrieveRequest retrieveRequest = new RetrieveRequest();
4retrieveRequest.setObjectType("Email");
5String[] stringArray = {"ID", "Name"};
6retrieveRequest.setProperties(stringArray);
7SimpleFilterPart filter = new SimpleFilterPart();
8filter.setProperty("Name");
9filter.setSimpleOperator(SimpleOperators.equals);
10java.util.List filterValues = new ArrayList();
11filterValues.add(new String("Sample"));
12filter.setValue((String[]) filterValues.toArray(new String[filterValues.size()]));
13retrieveRequest.setFilter(filter);
14RetrieveRequestMsg retrieveRequestMsg = new RetrieveRequestMsg(retrieveRequest);
15RetrieveResponseMsg retrieveResponseMsg = stub.retrieve(retrieveRequestMsg);
16System.out.println("[overall status message] " + retrieveResponseMsg.getOverallStatus());
17Email email = (Email) retrieveResponseMsg.getResults(0);
18return email;
19}

Sample Python Code 

1import logging
2from suds.client import Client
3from suds.wsse import *
4errors = 0
5import logging as log
6
7### we setup the service logging
8LOG_FILENAME = '/Users/username/Documents/Logs/request-log.txt'
9### we setup a debugging logging
10log.basicConfig(filename=LOG_FILENAME,level=log.debug)
11#https://fedorahosted.org/suds/wiki/Documentation (Suds documentation and ws-security details)
12def PrintAsHTML(url):
13try:
14    client = Client(url)
15    email = client.factory.create('Email')
16    print client
17    prop = ['ID','Name']
18    rr = client.factory.create('RetrieveRequest')
19    rr.Properties=prop
20    rr.ObjectType='Email'
21    sec = Security()
22    token= UsernameToken('username','password')
23    sec.tokens.append(token)
24    client.set_options(wsse=sec)
25    resp = client.service.Retrieve(rr)
26
27    out_str ='Response ::: '
28    print resp.OverallStatus
29
30    print out_str
31    #Prints Client.last_received---> SOAP response
32    print client.last_received()
33    sent= client.last_sent()
34    print 'Soap Request ::: '
35    log.debug('Done')
36    print sent
37except Exception, e:
38    print e
39try:
40PrintAsHTML('https://YOUR_SUBDOMAIN.soap.marketingcloudapis.com/etframework.wsdl')
41except Exception, e:
42print e

Sample SOAP Request 

1<Envelope xmlns="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
2<Header>
3    <fueloauth>YOUR_ACCESS_TOKEN</fueloauth>
4</Header>
5<Body>
6    <RetrieveRequestMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
7        <RetrieveRequest>
8            <ObjectType>Email</ObjectType>
9            <Properties>ID</Properties>
10            <Properties>Name</Properties>
11            <Properties>Subject</Properties>
12            <Properties>Status</Properties>
13            <Properties>PartnerKey</Properties>
14            <Properties>CreatedDate</Properties>
15            <Properties>Folder</Properties>
16            <Properties>CategoryID</Properties>
17            <Properties>EmailType</Properties>
18            <Filter xsi:type="SimpleFilterPart">
19                <Property>ID</Property>
20                <SimpleOperator>equals</SimpleOperator>
21                <Value>3096663</Value>
22            </Filter>
23        </RetrieveRequest>
24    </RetrieveRequestMsg>
25</Body>
26</Envelope>

Sample SOAP Response 

1<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">
2<soap:Header>
3    <wsa:Action>RetrieveResponse</wsa:Action>
4    <wsa:MessageID>urn:uuid:e6973425-e466-4c0c-909f-fb7ecff76cb5</wsa:MessageID>
5    <wsa:RelatesTo>urn:uuid:079cf30b-4337-47d0-bca3-52d45ddb15bd</wsa:RelatesTo>
6    <wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
7    <wsse:Security>
8        <wsu:Timestamp wsu:Id="Timestamp-6bd4770a-d7ab-4358-8831-94191d8469e6">
9            <wsu:Created>2017-02-21T13:47:25Z</wsu:Created>
10            <wsu:Expires>2017-02-21T13:52:25Z</wsu:Expires>
11        </wsu:Timestamp>
12    </wsse:Security>
13</soap:Header>
14<soap:Body>
15    <RetrieveResponseMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
16        <OverallStatus>OK</OverallStatus>
17        <RequestID>94531ae9-7448-4e2b-aff0-a37c881a56f7</RequestID>
18        <Results xsi:type="Email">
19            <PartnerKey/>
20            <CreatedDate>2009-07-01T08:45:34.71</CreatedDate>
21            <ID>3096663</ID>
22            <ObjectID xsi:nil="true"/>
23            <Name>Example Test</Name>
24            <Folder>my emails</Folder>
25            <CategoryID>578613</CategoryID>
26            <Subject>Example Subject</Subject>
27            <Status>New</Status>
28            <EmailType>Normal</EmailType>
29        </Results>
30    </RetrieveResponseMsg>
31</soap:Body>
32</soap:Envelope>

Related Items 

REST API