0

So far I have succeeded at updating a contact's email address using the REST API and this method.

The JSON body of my request looks like this:

    {
        "contactKey": "[MY_CONTACT_KEY]",
        "attributeSets": [{
            "name": "Email Addresses",
                "items": [{
                    "values": [{
                        "name": "Email Address",
                        "value": "[NEW_EMAIL_ADDRESS]"
                    },
                    {
                        "name": "HTML Enabled",
                        "value": "true"
                    }]
                }]
        }]
    }

I haven't had any luck with SOAP so far. But I've seen REST requests that are currently not documented but working. E.g. In this question, the updated answer by Adam Spriggs has a method that is not found anywhere else.

What I would like to do is something similar to the method above, but instead I would like to update the subscriber's Status e.g. from "Active" to "Unsubscribed" and if so, update the Unsubscribe Date and Unsubscribe Reason in the All Subscribers list as well. I know that the above code is a method from Contact Builder but I am wondering if there is a workaround.

UPDATE:

Following Gotonington's post about how to run REST and SOAP calls, I came all the way through Auth Token and successfully received it using REST. Then I used Postman to run the same SOAP request mentioned in the post. I set up my environment variables according to our Marketing Cloud. But I get the following XML response:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html xmlns="http://www.w3.org/1999/xhtml">
    
    <head>
        <title>Error</title>
        <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1" />
        <meta name="CODE_LANGUAGE" content="C#" />
        <meta name="vs_defaultClientScript" content="JavaScript" />
        <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5" />
    </head>
    
    <body style="margin: 0px; padding: 0px; font-family: Arial;">
        <table style="height:100%; width:100%;" border="0" cellpadding="5" cellspacing="0">
            <tr style="height:10%; background-color:#808080">
                <td>
                    <div style="color:#ffffff; font-size: 16px;">An error has occurred and has been logged by our system.
                        <br />
                            Thank you. </div>
                </td>
            </tr>
            <tr valign="top">
                <td>
                    <div id="errorTxt">&nbsp;</div>
                </td>
            </tr>
        </table>
    </body>
    
    </html>

UPDATE 2: Raw log of SOAP request and response

I have replaced the sensitive values with XXXs. Even though the request is of type POST, It appears as GET in the log, for some reason. Actually, when I run this request, I get two logs in the Postman console: One POST containing the request URL and GET which contains the following,

Request:

 GET /Services.asmx HTTP/1.1 Content-Type: text/xml SoapAction: Retrieve User-Agent: PostmanRuntime/7.21.0 Accept: */* Cache-Control: no-cache Postman-Token: XXXXXXXXXXXXXXXX Accept-Encoding: gzip, deflate Referer:
        [MY_SOAP_ENDPOINT] Connection: keep-alive
        <?xml version="1.0" encoding="UTF-8"?>
        <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
          <soapenv:Header>
            <fueloauth>XXXXXXXXXXXXXXXXXXXX</fueloauth>
          </soapenv:Header>
          <soapenv:Body>
            <RetrieveRequestMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
              <RetrieveRequest>
                <ObjectType>Subscriber</ObjectType>
                <Properties>SubscriberKey</Properties>
                <Properties>EmailAddress</Properties>
                <Properties>Status</Properties>
                <Filter xmlns:q1="http://exacttarget.com/wsdl/partnerAPI" xsi:type="q1:SimpleFilterPart">
                  <q1:Property>SubscriberKey</q1:Property>
                  <q1:SimpleOperator>equals</q1:SimpleOperator>
                  <q1:Value>XXXXXXXXXXXXXXXX</q1:Value>
                </Filter>
              </RetrieveRequest>
            </RetrieveRequestMsg>
          </soapenv:Body>
        </soapenv:Envelope>
    

Response:

HTTP/1.1 200 OK Cache-Control: private,no-store Pragma: no-cache Content-Type: text/html; charset=utf-8 Server: Microsoft-IIS/10.0 X-AspNet-Version: 4.0.30319 X-Powered-By: ASP.NET Strict-Transport-Security: max-age=7776000; includeSubDomains
        X-XSS-Protection: 1; mode=block X-Content-Type-Options: nosniff Referrer-Policy: strict-origin-when-cross-origin X-Frame-Options: DENY Date: Wed, 08 Jan 2020 15:34:46 GMT Connection: close Content-Length: 932
        <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN" >
        <html xmlns="http://www.w3.org/1999/xhtml">
          <head>
            <title>Error</title>
            <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1"/>
            <meta name="CODE_LANGUAGE" content="C#"/>
            <meta name="vs_defaultClientScript" content="JavaScript"/>
            <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5"/>
          </head>
          <body style="margin: 0px; padding: 0px; font-family: Arial;">
            <table style="height:100%; width:100%;" border="0" cellpadding="5" cellspacing="0">
              <tr style="height:10%; background-color:#808080">
                <td>
                  <div style="color:#ffffff; font-size: 16px;">An error has occurred and has been logged by our system.
                    <br/>
                    Thank you.
                  </div>
                </td>
              </tr>
              <tr valign="top">
                <td>
                  <div id="errorTxt">&nbsp;</div>
                </td>
              </tr>
            </table>
          </body>
        </html>

UPDATE 3:

Snapshot of the request headers

enter image description here

UPDATE 4:

The first POST request. Apparently, Postman redirects some POST requests using GET and that was a source of confusion. My first SOAP request with the verb POST returns a 302 response code as described in the link.

enter image description here

9
  • if you can share the code you used - specifically around the header, method and endpoint - I should be able to better assist in debugging it. Jan 8, 2020 at 15:13
  • @Gortonington sure I will update the question with the data I get in the Postman console. Jan 8, 2020 at 15:23
  • @Gortonington Please check out the UPDATE 2 part of the question. Jan 8, 2020 at 15:46
  • The issue is definitely the GET. It needs to be a POST or it will error the return. I am not sure why it is doing both a GET and a POST for you, but the GET method is the reason that the error is being returned. Jan 8, 2020 at 16:08
  • I realized Postman redirects requests with the response code of 302 using a GET request and that is why I get two requests in my console. Please take a look at UPDATE 4. I have no idea why the initial POST fails. Jan 9, 2020 at 12:11

1 Answer 1

3

Currently there is no way to change Email Subscription status via REST (at least that I have been able to find).

But there is a way via the Subscriber Object in SOAP. Eliot has a great example written up here

Sample Envelope taken from his answer:

POST {{soapEndpoint}}
Content-Type: text/xml

<?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">{{soapEndpoint}}</a:To>
        <fueloauth xmlns="http://exacttarget.com">{{accessToken}}</fueloauth>
    </s:Header>
    <s:Body
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
        <UpdateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">
            <Objects xsi:type="Subscriber">
                <SubscriberKey>{{insertSubscriberKey}}</SubscriberKey>
                <Lists>
                    <ID>{{ListID}}</ID>
                    <Status>Active</Status>
                    <Action>Update</Action>
                </Lists>
            </Objects>
        </UpdateRequest>
    </s:Body>
</s:Envelope>

I do not believe you can make any changes to the UnsubscribeDate or UnsubscribeReason(except via LogUnsubEvent) fields though, but once it is resubscribed, I believe these two fields are emptied.

11
  • I will give SOAP a try again. Unfortunately, I haven't been able to make a connection yet with Postman. Do you use the Auth Token or User/Pass? Still not sure what should and should not go to the header. If you found a thorough example please let me know. And by the way, why should there be REST methods that are documented? Somebody on Reddit told me about them! Dec 19, 2019 at 7:06
  • 2
    I believe Gregory wrote an entire step by step amazing article explaining this. Check it out here : gortonington.com/… Dec 19, 2019 at 8:32
  • @RachidMamai This looks very promising and is new. I will try it out and come back to you. Jan 8, 2020 at 9:16
  • I followed your post on your blog on how to run the SOAP call you explained. I go all the way through the access token and that part seems to work well. It's in the final bit where I run the SOAP request using the auth token (I use the same envelope you provided but I use a SubscriberKey value from our own Marketing Cloud). In response, I get an XML with the message "An error has occurred and has been logged by our system." I will update my question with the XML code if it helps. Thanks for your how-to, but any idea why I cannot my subscriber data? Jan 8, 2020 at 14:54
  • @Disasterkid - Did you make sure to include the SoapAction header? Have you verified that you have the /Service.asmx on your soap endpoint? Not just the returned subdomain? Jan 8, 2020 at 15:09

You must log in to answer this question.

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