1

I'm using the php API starter kit at https://developer.salesforce.com/docs/atlas.en-us.mc-apis.meta/mc-apis/api_starter_kits.htm , and I am using a variation on the exact_target_create_subscriber.php sample code in the path "PHP APIstarterKit-V1/PHP/01 Subscriber/01 Create Subscriber/exact_create_subscriber.php".

The script works on our dev environment, and similar code had been working on our production environment until recently, but now the same code that works on our dev environment, receives a "An invalid security token was provided" exception when it tries to connect to Exact Target.

Here is a copy of the code (with username and password omitted:

<?php 
require('../../00 Includes/exacttarget_soap_client.php');
$wsdl = 'https://webservice.s6.exacttarget.com/etframework.wsdl';

try {
    /* Create the Soap Client */
    $client = new ExactTargetSoapClient($wsdl, array('trace'=>1));
     /* Set username and password for the account here */
    $client->username = 'OMITTED_FOR_SECURITY_REASONS';
    $client->password = 'OMITTED_FOR_SECURITY_REASONS';

    /*% ExactTarget_Subscriber */   
    $subscriber = new ExactTarget_Subscriber();
    $subscriber->SubscriberKey = "232424"; // optional depending on account configuration
    $subscriber->EmailAddress = "testy+2017-01-23-001@exacttarget.com"; // required

    /*% Create a profile attribute for the subscriber */    
    $attribute1 = new ExactTarget_Attribute();
    $attribute1->Name = "FirstName";
    $attribute1->Value = "Sally";

    /*% Create a profile attribute for the subscriber */
    $attribute2 = new ExactTarget_Attribute();
    $attribute2->Name = "YearOfBirth";
    $attribute2->Value = "1976";

    /*% Create a profile attribute for the subscriber */
    $attribute3 = new ExactTarget_Attribute();
    $attribute3->Name = "Family ID";
    $attribute3->Value = "1234";

    /* Attach the profile attributes to the subcscriber */
    $subscriber->Attributes[] = $attribute1;
    $subscriber->Attributes[] = $attribute2;
    $subscriber->Attributes[] = $attribute3;

    /* Create the subscriber */
    $object = new SoapVar($subscriber, SOAP_ENC_OBJECT, 'Subscriber', "http://exacttarget.com/wsdl/partnerAPI");
    $request = new ExactTarget_CreateRequest();
    $request->Options = NULL;
    $request->Objects = array($object);
    $results = $client->Create($request);

    /* Output the results */
    var_dump($results);

    } catch (SoapFault $e) {
        var_dump($e);
     }
?>

We have been testing SSL upgrades to TLS 1.2, and I wouldn't rule out the possibility that our web host has upgraded or changed openSSL or some other aspect of the LAMP stack that is causing this issue, but I don't have any indication that this is the issue. Here is the error code:

  object(SoapFault)#9 (10) {
  ["message":protected]=>
    string(38) "An invalid security token was provided"
  ["string":"Exception":private]=>
  string(0) ""
  ["code":protected]=>
  int(0)
  ["file":protected]=>
  string(107) "/home/fbitn/public_html/PHP APIstarterKit-V1/01 Subscriber/01 Create Subscriber/exact_create_subscriber.php"
  ["line":protected]=>
  int(44)
  ["trace":"Exception":private]=>
  array(2) {
    [0]=>
    array(6) {
      ["file"]=>
      string(107) "/home/fbitn/public_html/PHP APIstarterKit-V1/01 Subscriber/01 Create Subscriber/exact_create_subscriber.php"
      ["line"]=>
      int(44)
      ["function"]=>
      string(6) "__call"
      ["class"]=>
      string(10) "SoapClient"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(2) {
        [0]=>
        string(6) "Create"
        [1]=>
        array(1) {
          [0]=>
          object(ExactTarget_CreateRequest)#7 (2) {
            ["Options"]=>
            NULL
            ["Objects"]=>
            array(1) {
              [0]=>
              object(SoapVar)#6 (4) {
                ["enc_type"]=>
                int(301)
                ["enc_value"]=>
                object(ExactTarget_Subscriber)#2 (15) {
                  ["EmailAddress"]=>
                  string(38) "tmorgan+2017-01-23-001@exacttarget.com"
                  ["Attributes"]=>
                  array(3) {
                    [0]=>
                    object(ExactTarget_Attribute)#3 (3) {
                      ["Name"]=>
                      string(9) "FirstName"
                      ["Value"]=>
                      string(5) "Sally"
                      ["Compression"]=>
                      NULL
                    }
                    [1]=>
                    object(ExactTarget_Attribute)#4 (3) {
                      ["Name"]=>
                      string(11) "YearOfBirth"
                      ["Value"]=>
                      string(4) "1976"
                      ["Compression"]=>
                      NULL
                    }
                    [2]=>
                    object(ExactTarget_Attribute)#5 (3) {
                      ["Name"]=>
                      string(9) "Family ID"
                      ["Value"]=>
                      string(4) "1234"
                      ["Compression"]=>
                      NULL
                    }
                  }
                  ["SubscriberKey"]=>
                  string(6) "232424"
                  ["UnsubscribedDate"]=>
                  NULL
                  ["Status"]=>
                  NULL
                  ["PartnerType"]=>
                  NULL
                  ["EmailTypePreference"]=>
                  NULL
                  ["Lists"]=>
                  NULL
                  ["GlobalUnsubscribeCategory"]=>
                  NULL
                  ["SubscriberTypeDefinition"]=>
                  NULL
                  ["Addresses"]=>
                  NULL
                  ["PrimarySMSAddress"]=>
                  NULL
                  ["PrimarySMSPublicationStatus"]=>
                  NULL
                  ["PrimaryEmailAddress"]=>
                  NULL
                  ["Locale"]=>
                  NULL
                }
                ["enc_stype"]=>
                string(10) "Subscriber"
                ["enc_ns"]=>
                string(38) "http://exacttarget.com/wsdl/partnerAPI"
              }
            }
          }
        }
      }
    }
    [1]=>
    array(6) {
      ["file"]=>
      string(107) "/home/fbitn/public_html/PHP APIstarterKit-V1/01 Subscriber/01 Create Subscriber/exact_create_subscriber.php"
      ["line"]=>
      int(44)
      ["function"]=>
      string(6) "Create"
      ["class"]=>
      string(21) "ExactTargetSoapClient"
      ["type"]=>
      string(2) "->"
      ["args"]=>
      array(1) {
        [0]=>
        object(ExactTarget_CreateRequest)#7 (2) {
          ["Options"]=>
          NULL
          ["Objects"]=>
          array(1) {
            [0]=>
            object(SoapVar)#6 (4) {
              ["enc_type"]=>
              int(301)
              ["enc_value"]=>
              object(ExactTarget_Subscriber)#2 (15) {
                ["EmailAddress"]=>
                string(38) "tmorgan+2017-01-23-001@exacttarget.com"
                ["Attributes"]=>
                array(3) {
                  [0]=>
                  object(ExactTarget_Attribute)#3 (3) {
                    ["Name"]=>
                    string(9) "FirstName"
                    ["Value"]=>
                    string(5) "Sally"
                    ["Compression"]=>
                    NULL
                  }
                  [1]=>
                  object(ExactTarget_Attribute)#4 (3) {
                    ["Name"]=>
                    string(11) "YearOfBirth"
                    ["Value"]=>
                    string(4) "1976"
                    ["Compression"]=>
                    NULL
                  }
                  [2]=>
                  object(ExactTarget_Attribute)#5 (3) {
                    ["Name"]=>
                    string(9) "Family ID"
                    ["Value"]=>
                    string(4) "1234"
                    ["Compression"]=>
                    NULL
                  }
                }
                ["SubscriberKey"]=>
                string(6) "232424"
                ["UnsubscribedDate"]=>
                NULL
                ["Status"]=>
                NULL
                ["PartnerType"]=>
                NULL
                ["EmailTypePreference"]=>
                NULL
                ["Lists"]=>
                NULL
                ["GlobalUnsubscribeCategory"]=>
                NULL
                ["SubscriberTypeDefinition"]=>
                NULL
                ["Addresses"]=>
                NULL
                ["PrimarySMSAddress"]=>
                NULL
                ["PrimarySMSPublicationStatus"]=>
                NULL
                ["PrimaryEmailAddress"]=>
                NULL
                ["Locale"]=>
                NULL
              }
              ["enc_stype"]=>
              string(10) "Subscriber"
              ["enc_ns"]=>
              string(38) "http://exacttarget.com/wsdl/partnerAPI"
            }
          }
        }
      }
    }
  }
  ["previous":"Exception":private]=>
  NULL
  ["faultstring"]=>
  string(38) "An invalid security token was provided"
  ["faultcode"]=>
  string(23) "q0:InvalidSecurityToken"
  ["faultactor"]=>
  string(50) "https://webservice.s6.exacttarget.com/Service.asmx"
}
1

This is the same issue as invalid security token . The solution was either:

  1. Change the time on your server.
  2. If using the Exact Target php SOAP API, and unable to change the time on your server, you will need to edit helpers/soap-wsse.php , specifically, the addUserToken function. The line that says:

    $createdate = gmdate("Y-m-d\TH:i:s").'Z';

Will need to be changed to something like the following:

$fake_date = strtotime("-60 minutes");
$createdate = gmdate("Y-m-d\TH:i:s", $fake_date).'Z';

Of course, it would be cleaner to change the function declaration to include $timeoffset as an optional parameter, and then make relevant changes in the calling function, but this is the simplest working example of the fix.

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.