Marketo REST API - 智能广告系列
Marketo REST API - Smart Campaign
我可以使用 html 表单和附加脚本 (PHP + Rest API) 创建新的 Marketo 潜在客户。它主要有效,潜在客户出现在 Marketo 中。
问题是,我的 Marketo 设置需要将新线索添加到特定 "Smart Campaign"。
在 Marketo's Rest API documentation 上,我找到了一个用于将潜在客户添加到列表的端点,但不是用于添加到广告系列的端点。你 运行 遇到过这个问题吗?
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;
}
}
无法通过 API.
将您的新潜在客户直接放入 智能营销活动
但是,正如您所指出的那样,您可以将它们推送到 List,这已经成功了一半。从那里开始,您唯一需要做的就是配置有问题的 Smart Campaign 以从您填充的 List 中获取线索。
您可以在 智能广告系列 的 智能列表 选项卡上设置 Added to List
触发器和指向它到您的 List。附上截图。
这样,新潜在客户也会立即添加到智能列表。
我可以使用 html 表单和附加脚本 (PHP + Rest API) 创建新的 Marketo 潜在客户。它主要有效,潜在客户出现在 Marketo 中。
问题是,我的 Marketo 设置需要将新线索添加到特定 "Smart Campaign"。
在 Marketo's Rest API documentation 上,我找到了一个用于将潜在客户添加到列表的端点,但不是用于添加到广告系列的端点。你 运行 遇到过这个问题吗?
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;
}
}
无法通过 API.
将您的新潜在客户直接放入 智能营销活动
但是,正如您所指出的那样,您可以将它们推送到 List,这已经成功了一半。从那里开始,您唯一需要做的就是配置有问题的 Smart Campaign 以从您填充的 List 中获取线索。
您可以在 智能广告系列 的 智能列表 选项卡上设置 Added to List
触发器和指向它到您的 List。附上截图。
这样,新潜在客户也会立即添加到智能列表。