我正在尝试使用Marketo的API发送电子邮件。我正在关注this教程并收到一条我无法理解的错误:{"requestId":"0000000000","success":false,"errors":[{"code":"711","message":"Invalid folder type for email"}]}
这是什么意思?我已经创建了一个文件夹,然后在这个文件夹中,我创建了一个程序,然后在这个程序中我创建了这个电子邮件。没有程序我就无法创建一个电子邮件 - 据我所知 - 所以我有点迷失。
由于
编辑:添加我的请求:
我正在用php构建我的请求:
<?php
$email = new CreateEmail();
$email->name = "MyEmailName";
$email->folder = new stdClass();
$email->folder->id = 3211;
$email->folder->type = "Folder";
$email->template = 0003;
$email->subject = "This email was created with an api call";
print_r($email->postData());
class CreateEmail{
private $host = "mydetails";
private $clientId = "mydetails";
private $clientSecret = "mydetails";
public $name;//name of new email, required - NOCEmai
public $folder;//json object with two members, id and type(Folder or Program), required
public $template;//id of parent template
public $description;//optional description of new
public $subject;//subject line of new email
public $fromName;//from name of new email
public $fromEmail;//from email of new email
public $replyEmail;//reply to address of new email
public $operational;//boolean operational status of email
public function postData(){
$url = $this->host . "/rest/asset/v1/emails.json?access_token=" . $this->getToken();
$ch = curl_init($url);
$requestBody = $this->bodyBuilder();
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;
}
private function bodyBuilder(){
$requestBody = "&name=" . $this->name . "&folder=" . json_encode($this->folder) . "&template=" . $this->template;
if (isset($this->description)){
$requestBody .= "&description=" . $this->description;
}
if (isset($this->subject)){
$requestBody .= "&subject=" . $this->subject;
}
if (isset($this->fromName)){
$requestBody .= "&fromName=" . $this->fromName;
}
if (isset($this->fromEmail)){
$requestBody .= "&fromEmail=" . $this->fromEmail;
}
if (isset($this->replyEmail)){
$requestBody .= "&replyEmail" . $this->replyEmail;
}
if (isset($this->operational)){
$requestBody .= "&operational=" . $this->operational;
}
return $requestBody;
}
}