5

I'm using SoapClient, trying to produce something for this specification:

<?xml version="1.0" encoding="utf-8"?>
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Header>
    <WSUser xmlns="http://webservices.listrak.com/v31/">
      <UserName>string</UserName>
      <Password>string</Password>
    </WSUser>
  </soap:Header>
  <soap:Body>
    <SetContact xmlns="http://webservices.listrak.com/v31/">
      <WSContact>
        <EmailAddress>string</EmailAddress>
        <ListID>int</ListID>
        <ContactProfileAttribute>
          <AttributeID>int</AttributeID>
          <Value>string</Value>
        </ContactProfileAttribute>
        <ContactProfileAttribute>
          <AttributeID>int</AttributeID>
          <Value>string</Value>
        </ContactProfileAttribute>
      </WSContact>
      <ProfileUpdateType>NotDefined or Update or Append or Overwrite</ProfileUpdateType>
      <ExternalEventIDs>string</ExternalEventIDs>
      <OverrideUnsubscribe>boolean</OverrideUnsubscribe>
    </SetContact>
  </soap:Body>
</soap:Envelope>

I've researched a bunch, including the below, and thought I had an answer. However, it's not working. This is what i'm doing:

foreach ($attributes as $key => $value) {
            $obj = array('AttributeID' => $key, 'Value' => $value);
            $attrs[] = $obj;
    }
    $final_attrs = array('ContactProfileAttribute' => $attrs);

    $params = array(
                    'WSContact' => array(
                                    'EmailAddress' => $email,
                                    'ListID' => $listId,
                                    array('ContactProfileAttribute' => $attrs)
                                    ),
                                    'ProfileUpdateType' => 'Overwrite',
                                    'ExternalEventIDs' => "",
                                    'OverrideUnsubscribe' => TRUE,

    );

    try {

            $rest = $soapClient->SetContact($params);
...

when I print out the array, I get this:

Array
(
    [WSContact] => Array
        (
        [EmailAddress] => [email protected]
        [ListID] => 26444
        [0] => Array
            (
                [ContactProfileAttribute] =&gt; Array
                    (
                        [0] => Array
                            (
                                [AttributeID] => 1548948
                                [Value] => 1
                            )

                        [1] => Array
                            (
                                [AttributeID] => 1548953
                                [Value] => John
                            )

                        [2] => Array
                            (
                                [AttributeID] => 1548954
                                [Value] => Doe
                            )

                        [3] => Array
                            (
                                [AttributeID] => 1550052
                                [Value] => 1
                            )

                    )

            )

    )

[ProfileUpdateType] => Overwrite
[ExternalEventIDs] => 
[OverrideUnsubscribe] => 1
)

However, this ends up not producing the expected result, instead:

Request = <?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://www.w3.org/2003/05/soap-envelope" xmlns:ns1="http://webservices.listrak.com/v31/">
    <env:Header>
        <ns1:WSUser>
            <ns1:UserName>user</ns1:UserName>
            <ns1:Password>pw</ns1:Password>
        </ns1:WSUser>
    </env:Header>
    <env:Body>
        <ns1:SetContact>
            <ns1:WSContact>
                <ns1:EmailAddress>[email protected]</ns1:EmailAddress>
                <ns1:ListID>26444</ns1:ListID>
            </ns1:WSContact>
            <ns1:ProfileUpdateType>Overwrite</ns1:ProfileUpdateType>
            <ns1:ExternalEventIDs></ns1:ExternalEventIDs>
            <ns1:OverrideUnsubscribe>true</ns1:OverrideUnsubscribe>
        </ns1:SetContact>
    </env:Body>
</env:Envelope>

(Notice: no ContactProfileAttribute)

Reference:

1 Answer 1

3

The ContactProfileAttribute element is one level too deep. Try:

$params = array(
    'WSContact' => array(
        'EmailAddress' => $email,
        'ListID' => $listId,
        'ContactProfileAttribute' => $attrs
    ),
    'ProfileUpdateType' => 'Overwrite',
    'ExternalEventIDs' => "",
    'OverrideUnsubscribe' => TRUE,
);
Sign up to request clarification or add additional context in comments.

1 Comment

That solution is not working in my case : it does not pass the WSDL validation and rise an error saying that some field is missing in "ContactProfileAttribute".

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.