2017-08-27 64 views
1

我可以使用html表單和附加的腳本(PHP + Rest API)創建一個新的Marketo銷售線索。它主要起作用,線索出現在Marketo。Marketo REST API - 智能營銷活動

問題是,我的Marketo設置需要將新潛在客戶添加到特定的「智能營銷活動」中。

在Marketo's Rest API documentation上,我找到了一個端點用於將引導添加到列表中,但不添加到Campaign中。你遇到過這個問題嗎?

class UpsertLeads{ 
    //these are the CIN Marketo credentials 
    public $host = "####";//CHANGE ME 
    public $clientId = "####";//CHANGE ME 
    public $clientSecret = "####";//CHANGE ME 
    public $input; //an array of lead records as objects 
    public $lookupField; //field used for deduplication 
    public $action; //operation type, createOnly, updateOnly, createOrUpdate, createDuplicate 

    public function postData(){ 
     $url = $this->host . "/rest/v1/leads.json?access_token=" . $this->getToken(); 
     $ch = curl_init($url); 
     $requestBody = $this->bodyBuilder(); 
     //commenting out 
     //dont need to output this stuff in production 
     //print_r($requestBody); 
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 
     curl_setopt($ch, CURLOPT_HTTPHEADER, array('accept: application/json','Content-Type: 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; 
    } 

    private function bodyBuilder(){ 
     $body = new stdClass(); 
     if (isset($this->action)){ 
      $body->action = $this->action; 
     } 
     if (isset($this->lookupField)){ 
      $body->lookupField = $this->lookupField; 
     } 
     $body->input = $this->input; 
     $json = json_encode($body); 
     return $json; 
    } 

    private static function csvString($fields){ 
     $csvString = ""; 
     $i = 0; 
     foreach($fields as $field){ 
      if ($i > 0){ 
       $csvString = $csvString . "," . $field; 
      }elseif ($i === 0){ 
       $csvString = $field; 
      } 
     } 
     return $csvString; 
    } 
} 

回答

0

這是不可能直接把你的新的導致智能運動通過API。
但是,如您所記錄的那樣,您可以將它們推送到列表,這是成功的一半。從那裏,你需要做的唯一事情就是配置智能活動有問題,從列表中挑選潛在客戶。

您可以通過設置Added to List觸發做到這一點智能運動智能列表選項卡上,並將其指向您的列表。附上截圖。

這樣,新的潛在客戶將立即添加到智能清單

'Added to List' trigger of Smart Campaign