I'm trying to send an email using the API, following this tutorial. I've got all the details ok, but I'm having an issue where I get response code 711, message: Invalid folder type for email. I'm not sure what this means as I'm using a folder - as described in the tutorial - and an email template (although I have a program inside the folder, but I'm told that I can't create an email without a program).
Any ideas of what am I missing?
Thanks!
screenshot?
The error codes are not well documented, so you can try asking Support, though I've rarely received a clear response on any error code.
711 | Incompatible Folder Type | The specified folder was not of the correct type to fulfill the request |
Can you show us your request and a screenshot of where you're trying to do this in Marketo - which exact folder you are using?
For those who have asked, here's the screenshot
I'm referring to the NOCTest folder and NOCEmail email. Here's the response:
Here's my code:
<?php
$email = new CreateEmail();
$email->name = "NOCEmail";
$email->folder = new stdClass();
$email->folder->id = 1176;
$email->folder->type = "Folder";
$email->template = 1007;
$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;
// print_r($response->access_token);
// return 'd10bb0bc-e849-4e09-9104-daf496177d31:lon';
}
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;
}
}
It looks like you're targeting the Marketing Folder as the parent for the new email. Folders aren't valid parents for Emails in Marketing activities. You need to create it as a local asset of one of your programs by setting your folder id to the id of the program, and the type to "Program".
I don't know php but I believe you can't refer to the folder when the email is actually in a program. You need to refer to the program name and number with the type of Program instead of type of Folder. Programs, although they aren't folders in the UI, also have folder numbers (which may differ from their program number in the UI), and you can query those through the API. I'm pretty sure that will fix your issue.