0

I'm getting the devil trying to update subscriber attributes in multiple lists where the list is part of a subaccount. I don't know the proper terminology for this, but our account has several different list "groups," accessed in the SOAP API as "Clients." In the admin we log in with a master account and then we "impersonate" sub-users. I've seen it described as "business units?" I have a script that works fine when updating attributes in a single list, or even in multiple lists within a single client/BU, but the Create request refuses to generate multiple Client tags. If I set up the Client object as an array, the result is an empty Client tag.

Here's an example of the code I have:

$object = array();

try {

    $request = new ExactTarget_UpdateRequest();
    $opts = new ExactTarget_UpdateOptions();

    // define subscriber object
    $sub = new ExactTarget_Subscriber(); 
    $sub->EmailAddress = $email;
    $sub->SubscriberKey = $email;
    // establish a list of subscriber objects by Client->ID
    $sub->Lists = array();
    $sub->Client = array();

    // loop thru lists to which subscriber belongs
    for( $i = 0; $i < count( $listArray ); $i++ ){
        // create client ID object(s)
        $cl = new ExactTarget_ClientID();
        $cl->ID = $this->retrieveListInfo( $listArray[$i], 1 );  // retrieveListInfo() returns the clientID for the given list
        $cl->IDSpecified = true;
        $sub->Client[] = $cl; 

        $list = new ExactTarget_SubscriberList();
        // set ListSubscriber Status -- active or unsubscribed, based on arg1
        $list->Status = "Active";
        $list->StatusSpecified = true;
        $list->ID = $listArray[$i]; 
        $list->IDSpecified = true;
        $sub->Lists[] = $list;

        // assign values from User Reg DB to Attribute Objects
        $sub->Attributes[$i]        = new ExactTarget_Attribute();  // set up attribute
        $sub->Attributes[$i]->Name  = $key; // string
        $sub->Attributes[$i]->Value = $value; // string
    }

    $so = new ExactTarget_SaveOption();
    $so->PropertyName = "*";
    $so->SaveAction = ExactTarget_SaveAction::UpdateAdd;
    $soe = new SoapVar( $so, SOAP_ENC_OBJECT, 'SaveOption', "http://exacttarget.com/wsdl/partnerAPI" );
    $opts->SaveOptions = array( $soe ); 

    $object[] = new SoapVar( $sub, SOAP_ENC_OBJECT, 'Subscriber', "http://exacttarget.com/wsdl/partnerAPI" );

    $request->Options = $opts;
    $request->Objects = $object;
    $results = $this->client->Create( $request );

} catch ( SoapFault $e ) {
    $this->logRequest( "err", $e );
}

The resulting object looks fine. Client IDs are all created properly. The XML, however, strips ALL client IDs and creates a blank tag:

    <?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://exacttarget.com/wsdl/partnerAPI" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
   <SOAP-ENV:Body>
      <ns1:CreateRequest>
         <ns1:Options>
            <ns1:SaveOptions>
               <ns1:SaveOption>
                  <ns1:PropertyName>*</ns1:PropertyName>
                  <ns1:SaveAction>UpdateAdd</ns1:SaveAction>
               </ns1:SaveOption>
            </ns1:SaveOptions>
         </ns1:Options>
         <ns1:Objects xsi:type="ns1:Subscriber">
            <ns1:Client />
            <ns1:EmailAddress>email1@example.com</ns1:EmailAddress>
            <ns1:Attributes>
               <ns1:Name>Last Active</ns1:Name>
               <ns1:Value>05/11/2014</ns1:Value>
            </ns1:Attributes>
            <ns1:Attributes>
               <ns1:Name>Last Active</ns1:Name>
               <ns1:Value>05/11/2014</ns1:Value>
            </ns1:Attributes>
            <ns1:SubscriberKey>email1@example.com</ns1:SubscriberKey>
            <ns1:Lists>
               <ns1:ID>170080</ns1:ID>
               <ns1:Status>Active</ns1:Status>
            </ns1:Lists>
            <ns1:Lists>
               <ns1:ID>1274529</ns1:ID>
               <ns1:Status>Active</ns1:Status>
            </ns1:Lists>
         </ns1:Objects>
      </ns1:CreateRequest>
   </SOAP-ENV:Body>
</SOAP-ENV:Envelope>

Any pointers are greatly appreciated.

0

not sure if the cause of your problems is the fact that you are using UpdateRequest along with the UpdateOptions, while you call Create method. Can you try correcting these and confirm the results?

3
  • Thanks for the reply. I've actually stripped out some of the code in the interest of keeping the page from being overwhelming, but this is actually part of an asynchronous request, which I based on the "Request" example on this page: help.exacttarget.com/en/technical_library/web_service_guide/… What changes would you suggest? – Jamie Doris May 13 '14 at 16:02
  • I've replaced UpdateRequest with CreateRequest and UpdateOptions with CreateOptions, and while the XML is now being created properly (Client tags are included as part of the array/object), the result fails. It (the web service) seems to treat Client as a single variable, and only reads the last one in the array. – Jamie Doris May 13 '14 at 18:22
  • Found another ET example which suggests I can get the desired result by grouping my lists and clients into separate objects: help.exacttarget.com/en-US/technical_library/web_service_guide/… (see the section "Sample SOAP Envelope - Add a Single Subscriber to Multiple Lists Contained in Multiple Business Units" The shows how the XML should look, but how should my PHP snippet change to make the XML structure break down that way? – Jamie Doris May 14 '14 at 15:13
0

Eureka. The solution is twofold:

  1. instantiate the subscriber INside the loop
  2. Use foreach($this as $that) instead of for($i=0;$i This is something of a mystery but I'm done wondering at this point.

Code:

$returnVal = 0; 
$subscriber = array();
$object = array();

try {

    foreach( $listArray as $thislist ) {

        $i = 0;

        // define subscriber object
        $sub = new ExactTarget_Subscriber(); 
        $sub->EmailAddress = $email;
        $sub->SubscriberKey = $email;
        // establish a list of subscriber objects by Client->ID
        $sub->Lists = array();

        // assign values from User Reg DB to Attribute Objects
        $sub->Attributes[$i]        = new ExactTarget_Attribute();  // set up attribute
        $sub->Attributes[$i]->Name  = $key; // string
        $sub->Attributes[$i]->Value = $value; // string

        // create client ID object(s)
        $cl = new ExactTarget_ClientID();
        $cl->ID = $this->retrieveListInfo( $thislist, 1 );
        $cl->IDSpecified = true;
        $sub->Client = $cl; 

        $list = new ExactTarget_SubscriberList();
        // set ListSubscriber Status -- active or unsubscribed, based on arg1
        $list->Status = "Active";
        $list->StatusSpecified = true;
        $list->ID = $thislist;
        $list->IDSpecified = true;
        $sub->Lists[] = $list;

        $subscriber[] = $sub;

        $i++;
    }

    $so = new ExactTarget_SaveOption();
    $so->PropertyName = "*";
    $so->SaveAction = ExactTarget_SaveAction::UpdateAdd;
    $soe = new SoapVar( $so, SOAP_ENC_OBJECT, 'SaveOption', "http://exacttarget.com/wsdl/partnerAPI" );

    $opts = new ExactTarget_CreateOptions();
    $opts->RequestType = ExactTarget_RequestType::Asynchronous;
    $opts->QueuePriority = "High";
    $opts->ConversationID = $conversationID;
    $opts->CallsInConversation = $callsInConversation;
    $opts->SequenceCode = $sequenceCode;
    $opts->SendResponseTo = array();

    $ar = new ExactTarget_AsyncResponse();
    $ar->ConversationID = $conversationID;  
    $ar->RespondWhen = ExactTarget_RespondWhen::Always;  
    $ar->ResponseType = ExactTarget_AsyncResponseType::HTTPPost;  
    $ar->ResponseAddress = "http://ourserver.com/etResponse.php";  
    $ar->IncludeResults = true;  
    $ar->IncludeObjects = true;  

    $opts->SendResponseTo[] = $ar;

    $opts->SaveOptions = array( $soe ); 

    foreach( $subscriber as $currentsub ) {
        $object[] = new SoapVar( $currentsub, SOAP_ENC_OBJECT, 'Subscriber', "http://exacttarget.com/wsdl/partnerAPI" );
    }

    $request = new ExactTarget_CreateRequest();
    $request->Options = $opts;
    $request->Objects = $object;
    $results = $this->client->Create( $request );


} catch ( SoapFault $e ) {
    $this->logRequest( "err", $e );
}

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.