PHP API Triggered Send

General Tech Bugs & Fixes 2 years ago

0 2 0 0 0 tuteeHUB earn credit +10 pts

5 Star Rating 1 Rating

Posted on 16 Aug 2022, this text provides information on Bugs & Fixes related to General Tech. Please note that while accuracy is prioritized, the data presented might not be entirely correct or up-to-date. This information is offered for general knowledge and informational purposes only, and should not be considered as a substitute for professional advice.

Take Quiz To Earn Credits!

Turn Your Knowledge into Earnings.

tuteehub_quiz

Answers (2)

Post Answer
profilepic.png
manpreet Tuteehub forum best answer Best Answer 2 years ago

 

I am trying to create a triggered send using the API with PHP.

The soap call is registering, however, i don't believe the function is registering correctly. I have a Triggered Send Definition already set up in the account and a DE associated with it.

verification if statement is :

if (preg_match("/^([a-z]+[\w-]*\.?)+@([\w-]+\.)+[a-z]{2,4}$/i", $_POST['email'])) {

    date_default_timezone_set('UTC');
    $dateTime = new DateTime ();
    $setDateVal = date('n/j/Y',strtotime('now'));

    $email = $_POST['email'];
    $zip =  $_POST['zip'];

    include('exacttarget_soap_client.php');
    $wsdl = 'https://webservice.s4.exacttarget.com/etframework.wsdl';
        try {
            /* Create the Soap Client */
            $client = new ExactTargetSoapClient($wsdl, array('trace' => 1));

            /* Set username and password
             * 
             *  here */
            $client->username = '************';
            $client->password = '************';

            $subscriber = new ExactTarget_Subscriber();
            $subscriber->EmailAddress = $email;
            $subscriber->SubscriberKey = $email;

            // This section is needed if you are adding a subscriber to a Lock and Publish account using an enterprise API user

            $cl = new ExactTarget_APIObject();
            $cl->ID = **********;
            $cl->CustomerKey = '**********';
            $subscriber->Client = $cl;

            //% ExactTarget_Subscriber               
            $attribute1 = new ExactTarget_Attribute();
            $attribute1->Name = "POSTALCODE";
            $attribute1->Value = $zip;

            //% ExactTarget_Subscriber  
            $attribute3 = new ExactTarget_Attribute();
            $attribute3->Name = "DATE";
            $attribute3->Value = $setDateVal;

            //% ExactTarget_Subscriber 
            $attribute4 = new ExactTarget_Attribute();
            $attribute4->Name = "OPTIN";
            $attribute4->Value = "Y";

            $subscriber->Attributes = array($attribute1, $attribute2, $attribute3, $attribute4);

            // This is the section needed to define it as an "Upsert"
            $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_UpdateOptions();
            $opts->SaveOptions = array($soe);

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

            $request = new ExactTarget_CreateRequest();
            $request->Options = $opts;
            $request->Objects = array($object);


            $results = $client->Create($request);

            print_r($results);

        } catch (SoapFault $e) {

            print_r($e->faultstring);

        }
}

Am I using the correct code? Is there a TriggeredSend Shell available for PHP, and if so - where do i define subscriber/DE attributes?

profilepic.png
manpreet 2 years ago

Take a look at this example of TriggeredSend for the PHP Fuel SDK? This explains how you can set the subscribers while sending a triggered send.


0 views   0 shares

No matter what stage you're at in your education or career, TuteeHub will help you reach the next level that you're aiming for. Simply,Choose a subject/topic and get started in self-paced practice sessions to improve your knowledge and scores.