0

I am using this Marketing Cloud API SOAP request. I have succeeded at a few other SOAP requests but on this one, I don't seem to understand where to put the parameters and their values.

The input to the request should be the SubscriberKey of the subscriber and I would like to update the status of the subscriber from "Active" to "Unsubscribed" or vice versa.

Could anyone explain where the parameters should go?

Here is the sample SOAP envelope used in the documentation page in the above link:

<?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:MessageID>urn:uuid:7e0cca04-57bd-4481-864c-6ea8039d2ea0</a:MessageID>
        <a:ReplyTo>
            <a:Address>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</a:Address>
        </a:ReplyTo>
        <a:To s:mustUnderstand="1">https://YOUR_SUBDOMAIN.soap.marketingcloudapis.com/Service.asmx</a:To>
        <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
            <o:UsernameToken u:Id="uuid-b82c6428-caa1-49fc-986b-dc613c990c49-1">
                <o:Username>
                    <!-- Removed-->
                </o:Username>
                <o:Password>
                    <!-- Removed-->
                </o:Password>
            </o:UsernameToken>
        </o:Security>
    </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">
            <Options>
                <SaveOptions>
                    <SaveOption>
                        <PropertyName>*</PropertyName>
                        <SaveAction>UpdateAdd</SaveAction>
                    </SaveOption>
                </SaveOptions>
            </Options>
            <Objects xsi:type="Subscriber">
                <ObjectID xsi:nil="true">
                </ObjectID>
                <EmailAddress>[email protected]</EmailAddress>
                <Lists>
                    <ID>123</ID>
                    <ObjectID xsi:nil="true">
                    </ObjectID>
                </Lists>
            </Objects>
        </CreateRequest>
    </s:Body>
</s:Envelope>

2 Answers 2

4

You should be using something like below:

<?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">{{access_token}}</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>00Q2X00001xxxxxx</SubscriberKey>
                <Lists>
                    <ID>21</ID>
                    <Status>Unsubscribed</Status>
                    <Action>Update</Action>
                </Lists>
            </Objects>
        </UpdateRequest>
    </s:Body>
</s:Envelope>

You can see that I have used a FueloAuth rather than the username/password.

I have tried to update a subscriber using the CreateRequest without sucess. I think that it makes sense since we are trying to update an existing subscriber and not create a new one.

Just replace the Status value with either Unsubscribed or Active and that should work fine.

Also, there is no need for the Options parameters, but according to Gregory, it's preferrable to add it. Here is his comment: Create utilizing the SaveOptions will do Add/Update. As displayed in the example and what @Disasterkid has. It is not necessary to use, but is preferrable on times when you are unsure if the Subscriber exists yet or if he needs to be created first

To answer your question in the comments, you need to use the Update SoapAction in the header.

3
  • Great! Let me test it out and come back. Yes, I also use the auth token instead of user/pass. So should I use the SoapAction of "Create" in the header? Commented Jan 14, 2020 at 14:53
  • 1
    Create utilizing the SaveOptions will do Add/Update. As displayed in the example and what @Disasterkid has. It is not necessary to use, but is preferrable on times when you are unsure if the Subscriber exists yet or if he needs to be created first. Commented Jan 14, 2020 at 14:54
  • @Disasterkid, I've updated my answer to include that as well. Thanks Gregory for the explanation, I've added it to the answer.. Commented Jan 14, 2020 at 15:07
2

Below is a good reference for each aspect of the SOAP Subscriber object create/update options.

<CreateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">
  <Options>
    <SaveOptions>
      <SaveOption>
        <PropertyName>*</PropertyName>
        <SaveAction>UpdateAdd</SaveAction>
      </SaveOption>
    </SaveOptions>
  </Options>
  <Objects xsi:type="Subscriber">
    <SubscriberKey>{{mySubkey}}</SubscriberKey>
    <EmailAddress>{{myEmailAddress}}</EmailAddress>
    <Attributes>
      <Name>First Name</Name>
      <Value>Gregory</Value>
    </Attributes>
    <Lists>
      <ID>{{myListID}}</ID>
      <Action>Update</Action>
      <Status>Active</Status>
    </Lists>
  </Objects>
</CreateRequest>

The above would be inserted inside of the SOAP <Body> section. Now to break it apart:

Create to Upsert - make the 'Create' Request turn into Add/Update

  <Options>
    <SaveOptions>
      <SaveOption>
        <PropertyName>*</PropertyName>
        <SaveAction>UpdateAdd</SaveAction>
      </SaveOption>
    </SaveOptions>
  </Options>

By inserting this inside of your create request, you can change it to add/update instead of the default Add.

Subscriber Object Info - defines which subscriber you want to create/update

<Objects xsi:type="Subscriber">
  <SubscriberKey>[email protected]</SubscriberKey>
  <EmailAddress>[email protected]</EmailAddress>
</Objects>

The info you use here does not include the Attributes (First Name, Last Name, etc.), it is only info like EmailAddress, SubscriberKey, etc. that uniquely identifies the Subscriber.

Attributes - the associated attributes of the subscriber

<Attributes>
  <Name>First Name</Name>
  <Value>Gregory</Value>
</Attributes>

This would add in the Attributes via a Name/Value pairing. Essentially the Name would be the name of the attribute (e.g. First Name, Last Name, etc.) and Value is the value you want for that subscriber for that Attribute. (e.g. Greg, Gifford, etc.).

Lists and Status - Associated Lists (add/update/remove) and current Status

<Lists>
  <ID>{{myListID}}</ID>
  <Action>Update</Action>
  <Status>Active</Status>
</Lists>

This will allow you to list all of the IDs of the lists you want this subscriber attached to, and then you can use Action and Status to appropriately update their current status on that list.

Hope this helps explain how the properties in Subscriber Object work.

2
  • Thank you for your clear descriptions. I had to choose Rachid's answer only because it was earlier. Commented Jan 15, 2020 at 8:57
  • 1
    @Disasterkid - yeah by five minutes... grumble grumble Just kidding! Rachids answer is great and if my answer helps someone learn something new or solve an issue, that is more important to me than any points or badges here. Commented Jan 15, 2020 at 15:43

You must log in to answer this question.

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