1

I am trying to understand how the patch() function works in the new Fuel SDK. To update a subscriber's status:

require('ET_Client.php');
$myclient = new ET_Client();
$subscriber = new ET_Subscriber();
$subscriber->authStub = $myclient;
$subscriber->props = array("Status" => "Unsubscribed", "SubscriberKey" => "SDKSubscriber");
$results = $subscriber->patch();
print_r($results);

However, this method relies on identifying the subscriber by their subscriber key. The default setting for subscribers is to use their email address as their subscriber key. So how does one change the email address of a user?

Is there a best practice for this seemingly simple action? The Fuel SDK seems to be fairly opaque with simple stuff like this. The documentation is not all that enlightening.

Update:

The Email Address is the only thing that updates but the rest of the fields do not update. Here is my code:

function updateUser($idNum, $userEmail, $fullName, $firstName, $lastName){  //Update Method
    $myclient = new ET_Client();                    //required by the Fuel SDK
    $subscriber = new ET_Subscriber();              //Creates new subscriber object
    $subscriber->authStub = $myclient;          
    $subscriber->props = array("EmailAddress" => $userEmail, "ID" => $idNum, "FullName" => $fullName, "FirstName" => $firstName, "LastName" => $lastName);//$subscriber->props = array("Email Address" => $userEmail, "Full Name" => $fullName, "First Name" => $firstName, "Last Name" => $lastName, "ID" => $idNum);  //Prepares the properties to be set for the ID.  , "FullName" => $fullName, "FirstName" => $firstName, "LastName" => $lastName, , "FullName" => $fullName, "FirstName" => $firstName, "LastName" => $lastName
    $results = $subscriber->patch();

}
  • Are you asking how to update the subscribers status, or the subscribers email address? – Kelly J Andrews Jan 6 '15 at 15:25
  • How to update the email address. Or is there a best practice for updating in general. Basically, when passing variables into the patch() function, which is the one that identifies the subscriber and which is the one that is going to be changed? Is it always the first parameter that gets changed while the second parameter always identifies? – KempisCoder Jan 6 '15 at 15:25
1

When you are doing the patch() function, here is a sample packet of SOAP that's being created:

    <CreateRequest xmlns="http://exacttarget.com/wsdl/partnerAPI">
        <Options>
            <SaveOptions>
                <SaveOption>
                    <PropertyName>*</PropertyName>
                    <SaveAction>UpdateAdd</SaveAction>
                </SaveOption>
            </SaveOptions>
        </Options>
        <Objects xsi:type="Subscriber">
            <EmailAddress>help@example.com</EmailAddress>
            <Lists>
                <ID>123</ID>
            </Lists>
        </Objects>
    </CreateRequest>

The props array you are passing in is creating the properties in the Objects node.

There really isn't any order you need to pass them in, however, if you are not using SubscriberKey, you must use ID to reference the specific subscriber in the account.

This will allow you to update the email address

//using subscriber key
$subscriber->props = array("Email Address" => "newemail@gmail.com", "SubscriberKey" => "UniqueID");

//using subscriber id
$subscriber->props = array("Email Address" => "newemail@gmail.com", "ID" => "subscriberid");

Given the subscriber attributes First Name and Last Name you would patch those by adding them to the array.

$subscriber->props = array("Email Address" => "newemail@gmail.com", "ID" => "subscriberid", "First Name" => "New First Name", "Last Name" => "New Last Name");
  • How do you get the subscriber ID? Is it retrieved using the ET_get class? How do you access the ID number? PHP keeps telling me that it is neither an array, nor JavaScript and it doesn't look like XML. I just watched your Fuel SDK video on youtube for adding a subscriber so I'm sure with the sugar methods this should be fairly simple. (Great video btw) I just can't seem to access that data in the ET_Get class. Or should I just be using subscriber? What I'm trying to do is retrieve a user based on his old email, update the email and store the updated data back in Exact Target. – KempisCoder Jan 27 '15 at 17:00
  • 1
    Make a new question and post what you are doing – Kelly J Andrews Jan 27 '15 at 17:04
  • I believe some of the information in this question is inaccurate. I have been playing with this code for nearly a month and "SubscriberID" hasn't worked for me. Instead, the code requires "ID". Also, "Email Address" has not produced any result for me. Instead, "EmailAddress" has worked. Could you please explain how you get Full Name, First Name, and Last Name? – KempisCoder Feb 11 '15 at 21:51
  • 1
    Yes but neither "First Name" or "FirstName" bring about the desired change. Same goes for "Last Name" and "Full Name" And in the docs on that page, they make no mention of the Full Name, First Name and Last Name. – KempisCoder Feb 12 '15 at 20:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.