[SalesForce] The Triggered Send is not completely configured or in a new status

I am trying to create/retrieve a triggered send via the PHP FuelSDK. I am using the following code:

public static function POST_test() {
    $tsName = 'tsWelcomeS1_t1';
    $tsDescription = 'Welcome Series One Triggered Send';
    $emailId = 51776;
    $tsCustomerKey = str_replace('.', '', $tsName . '_' . microtime(true));
    $toEmail = 'obscured@email.com';
    ExactTargetEmail::sendTriggeredEmail($tsName, $tsDescription, $tsCustomerKey, $emailId, $toEmail)));
}

public static function sendTriggeredEmail($tsName, $tsDescription, $tsCustomerKey, $emailId, $toEmail) {

    // Check to see if the triggered send already exists
    $triggeredsend = new ET_TriggeredSend();
    $triggeredsend->authStub = self::getClient();
    $triggeredsend->filter = ['Property' => 'CustomerKey', 'SimpleOperator' => 'equals', 'Value' => $tsName];
    $tsResults = $triggeredsend->get();

    if ( ! isset($tsResults->results[0])) {

        // The triggered send does not exist, create it
        $triggeredsend = new ET_TriggeredSend();
        $triggeredsend->authStub = self::getClient();
        $triggeredsend->props = [];
        $triggeredsend->props["Name"] = $tsName;
        $triggeredsend->props["CustomerKey"] = $tsName;
        $triggeredsend->props["Description"] = $tsDescription;
        $triggeredsend->props["Email"] = ["ID" => $emailId];
        $triggeredsend->props["SendClassification"] = ["CustomerKey" => self::$sendClassification];
        $triggeredsend->post();
    }

    // OK, we have the Triggered Send, let's send it
    $triggeredsend = new ET_TriggeredSend();
    $triggeredsend->authStub = self::getClient();
    $triggeredsend->props = ["CustomerKey" => $tsName];
    $triggeredsend->subscribers = [["EmailAddress"=>$toEmail, "SubscriberKey" => $toEmail.'23']];
    $results = $triggeredsend->send();
    echo "<pre>";die(var_dump($results, $triggeredsend));
}

public static function getClient() {
    if (is_null(self::$client)) {
        self::$client = new ET_Client(false, false, null);
    }
    return self::$client;
}

Note: I use self::$sendClassification and self::getClient() to send regular emails without fail.

However, when I send this I get the following soap feedback:

Retrieval of the triggered send:

<?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <soap:Header>
            <wsa:Action>RetrieveResponse</wsa:Action>
            <wsa:MessageID>urn:uuid:e418f967-7410-4939-b4d0-14be8290f019</wsa:MessageID>
            <wsa:RelatesTo>urn:uuid:104bcd13-9e33-495e-82a8-84a7cb6aecc0</wsa:RelatesTo>
            <wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
            <wsse:Security>
                <wsu:Timestamp wsu:Id="Timestamp-f9de43ee-4b4a-469e-a6b8-3c1e49675c05">
                    <wsu:Created>2016-01-25T14:44:31Z</wsu:Created>
                    <wsu:Expires>2016-01-25T14:49:31Z</wsu:Expires>
                </wsu:Timestamp>
            </wsse:Security>
        </soap:Header>
        <soap:Body>
            <RetrieveResponseMsg xmlns="http://exacttarget.com/wsdl/partnerAPI">
                <OverallStatus>OK</OverallStatus>
                <RequestID>b26d0624-6088-489d-a3d0-652cb5efea78</RequestID>
                <Results xsi:type="TriggeredSendDefinition">
                    <Client>
                        <ID>7216882</ID>
                    </Client>
                    <PartnerKey />
                    <PartnerProperties>
                        <Name>TestEmailAddr</Name>
                        <Value />
                    </PartnerProperties>
                    <CreatedDate>2016-01-23T11:31:00</CreatedDate>
                    <ModifiedDate>2016-01-23T11:31:00</ModifiedDate>
                    <ObjectID>b3bf7311-f7c1-e511-a39c-8cdcd4aff7c9</ObjectID>
                    <CustomerKey>tsWelcomeS1_t1</CustomerKey>
                    <IsPlatformObject>false</IsPlatformObject>
                    <Name>tsWelcomeS1_t1</Name>
                    <Description>Welcome Series One Triggered Send</Description>
                    <Keyword />
                    <CategoryID>1222</CategoryID>
                    <SendClassification>
                        <PartnerKey xsi:nil="true" />
                        <ObjectID>f81dec6d-9b37-e511-89ed-8cdcd4a8b025</ObjectID>
                        <CustomerKey>WEB_CLASS</CustomerKey>
                    </SendClassification>
                    <FromName>Client Name</FromName>
                    <FromAddress>obscuredclient@email.com</FromAddress>
                    <SuppressTracking>false</SuppressTracking>
                    <TriggeredSendType>Continuous</TriggeredSendType>
                    <TriggeredSendStatus>New</TriggeredSendStatus>
                    <Email>
                        <PartnerKey xsi:nil="true" />
                        <ID>51776</ID>
                        <ObjectID xsi:nil="true" />
                    </Email>
                    <AutoAddSubscribers>false</AutoAddSubscribers>
                    <AutoUpdateSubscribers>false</AutoUpdateSubscribers>
                    <BatchInterval>0</BatchInterval>
                    <BccEmail />
                    <EmailSubject>Email Subject!</EmailSubject>
                    <DynamicEmailSubject>Email Subject!</DynamicEmailSubject>
                    <IsMultipart>false</IsMultipart>
                    <IsWrapped>false</IsWrapped>
                    <AllowedSlots>0</AllowedSlots>
                    <NewSlotTrigger>0</NewSlotTrigger>
                </Results>
            </RetrieveResponseMsg>
        </soap:Body>
    </soap:Envelope>

Triggered send Send request:

    <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:Objects xsi:type="ns1:TriggeredSend">
                    <ns1:TriggeredSendDefinition>
                        <ns1:CustomerKey>tsWelcomeS1_t1</ns1:CustomerKey>
                    </ns1:TriggeredSendDefinition>
                    <ns1:Subscribers>
                        <ns1:EmailAddress>obscured@email.com</ns1:EmailAddress>
                        <ns1:SubscriberKey>obscured@email.com23</ns1:SubscriberKey>
                    </ns1:Subscribers>
                </ns1:Objects>
            </ns1:CreateRequest>
        </SOAP-ENV:Body>
    </SOAP-ENV:Envelope>

Triggered send Send response:

<?xml version="1.0" encoding="utf-8"?>
    <soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:wsa="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns:wsse="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd" xmlns:wsu="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <soap:Header>
            <wsa:Action>CreateResponse</wsa:Action>
            <wsa:MessageID>urn:uuid:b475db28-cae1-4856-8fb3-9f2fb480d39a</wsa:MessageID>
            <wsa:RelatesTo>urn:uuid:dda852fd-1649-450b-8e97-991d711b23ea</wsa:RelatesTo>
            <wsa:To>http://schemas.xmlsoap.org/ws/2004/08/addressing/role/anonymous</wsa:To>
            <wsse:Security>
                <wsu:Timestamp wsu:Id="Timestamp-2e7aaa01-dada-4f43-86ba-b493fbf3a124">
                    <wsu:Created>2016-01-25T14:47:28Z</wsu:Created>
                    <wsu:Expires>2016-01-25T14:52:28Z</wsu:Expires>
                </wsu:Timestamp>
            </wsse:Security>
        </soap:Header>
        <soap:Body>
            <CreateResponse xmlns="http://exacttarget.com/wsdl/partnerAPI">
                <Results xsi:type="TriggeredSendCreateResult">
                    <StatusCode>Error</StatusCode>
                    <StatusMessage>The Triggered Send is not completely configured or in a new status.  Please check Triggered Send Definition configuration.</StatusMessage>
                    <OrdinalID>0</OrdinalID>
                    <ErrorCode>18002</ErrorCode>
                    <NewID>0</NewID>
                </Results>
                <RequestID>6764f369-dccb-46bf-b9ad-b29dcf02a23a</RequestID>
                <OverallStatus>Error</OverallStatus>
            </CreateResponse>
        </soap:Body>
    </soap:Envelope>

Again, I'm able to create and retrieve the triggered send object, but when I go to send it I receive the following error: The Triggered Send is not completely configured or in a new status. Please check Triggered Send Definition configuration.

I have followed the documentation as well as I can. Any help would be wonderful.

Thanks.

Best Answer

For Triggered Send emails, I would recommend against creating a new TriggeredSend for each email that is sent. A TriggeredSend should be created once to represent the campaign or specific type of email being sent (example one for password reset, then maybe a different one for receipts) then the Send function on it should be called in order to trigger individual emails.

Typically the number of TriggeredSend definitions is fairly small so they will be configured in the Marketing Cloud UI, then referenced in code using the externalKey/CustomerKey value.

After a TriggeredSend is created, it has to be started prior to being used to send emails (this can also be done in the UI):

print_r("Start a TriggeredSend by setting to Active \n");
$patchTrig = new ET_TriggeredSend();
$patchTrig->authStub = $myclient;
$patchTrig->props = array('CustomerKey' => 'TEXTEXT', 'TriggeredSendStatus' => 'Active', 'RefreshContent'=>'true' );
$patchResult = $patchTrig->patch();
print_r('Patch Status: '.($patchResult->status ? 'true' : 'false')."\n");
print 'Code: '.$patchResult->code."\n";
print 'Message: '.$patchResult->message."\n";
print 'Result Count: '.count($patchResult->results)."\n";
print 'Results: '."\n";
print_r($patchResult->results);
print "\n---------------\n";

More example at: https://github.com/salesforce-marketingcloud/FuelSDK-PHP/blob/Dot9/objsamples/sample-triggeredsend.php

Related Topic