How to replace tokens on email campain using REST API in PHP ? -


i have email campaign on marketo send emails using php. on email template have token like, {{my.emailbody:default=body}} replace the token custom email content php code,

this code,

$sample = new sendsampleemail(); $sample->id = 11111; $sample->emailaddress = "myemail@example.com"; print_r($sample->postdata());  class sendsampleemail{   private $host = "https://aaa-aaa-121.mktorest.com";   private $clientid = "dxxxxxxxxxxxxxxxxxxxxx1";   private $clientsecret = "sxxxxxxxxxxxxxxxxxxxxxxxxxxxxe";   public $id; //id of  delete   public $emailaddress;//email address send   public $textonly;//boolean option send text version   public $leadid;// id of lead impersonate    public function postdata(){     $url = $this->host . "/rest/asset/v1/email/" . $this->id . "/sendsample.json?access_token=" . $this->gettoken();     $requestbody  = "&emailaddress=" . $this->emailaddress;     if (isset($this->textonly)){       $requestbody .= "&textonly=" . $this->textonly;     }     if (isset($this->leadid)){       $requestbody .= "&leadid=" . $this->leadid;     }     //print_r($requestbody);      $ch = curl_init($url);     curl_setopt($ch,  curlopt_returntransfer, 1);     curl_setopt($ch, curlopt_httpheader, array('accept: application/json'));     curl_setopt($ch, curlopt_post, 1);     curl_setopt($ch, curlopt_postfields, $requestbody);     curl_getinfo($ch);     $response = curl_exec($ch);     return $response;   }    private function gettoken(){     $ch = curl_init($this->host . "/identity/oauth/token?grant_type=client_credentials&client_id=" . $this->clientid . "&client_secret=" . $this->clientsecret);     curl_setopt($ch,  curlopt_returntransfer, 1);     curl_setopt($ch, curlopt_httpheader, array('accept: application/json',));     $response = json_decode(curl_exec($ch));     curl_close($ch);     $token = $response->access_token;     return $token;   }  } 

using code can trigger emails, how can replace token value {{my.emailbody:default=body}} ?

i have same problem tried used assets tokens rest api: http://developers.marketo.com/rest-api/assets/tokens/ modify token's values, endpoint cannot make work. please let me know if make work.

however, used soap api solve issue:

you create batch campaign marketo inside marketo program contains token want modify , email want send using token.

the soap api schedule campaign run (you can set current time immediate run), , can set value tokens:

public function schedule_campaign($program_name,$campaign_name,$token_name,$token_value) {     $params = new stdclass();     $params->programname = $program_name;     $params->campaignname = $campaign_name;     $dtzobj = new datetimezone("america/new_york");     $dtobj = new datetime('now', $dtzobj);     $params->campaignrunat = $dtobj->format(date_w3c);      $token = new stdclass();     $token->name = "{{my.".$token_name."}}";     $token->value = $token_value;      $params->programtokenlist = array("attrib" => $token);     $params = array("paramsschedulecampaign" => $params);      $soapclient = new soapclient(marketo_soap_endpoint ."?wsdl", self::$auth_options);     try      {         $response = $soapclient->__soapcall('schedulecampaign', $params,  self::$auth_options, self::$auth_header);         return true;     }     catch(exception $ex) {         return false;     } } 

update: i've found way update/replace tokens using rest api:

public function create_token($folder_id,$name,$content,$folder_type = 'program')     {         $folder_id = intval($folder_id);         $endpoint = 'rest/asset/v1/folder/'.$folder_id.'/tokens';         $url = $this->url . $endpoint . ".json?access_token=" . self::$token."&foldertype=".$folder_type."&name=".$name."&type=".  urlencode('rich text')."&value=".urlencode($content);          $ch = curl_init($url);         curl_setopt($ch, curlopt_returntransfer, 1);         curl_setopt($ch, curlopt_httpheader, array('content-type: x-www-form-urlencoded'));         curl_setopt($ch, curlopt_post, 1);         $response = curl_exec($ch);         curl_close($ch);         return json_decode($response);     } 

Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -