api-library icon indicating copy to clipboard operation
api-library copied to clipboard

$emailApi->send - Send email to Segment

Open morettic2015 opened this issue 7 years ago • 4 comments

As i see there's and issue with the REST API. The endpoint to send email to segments does not exist. 👎

Followed documentation to implement it as explained at: https://developer.mautic.org/#send-email-to-segment

Using api i can send email to a contact. But endpoint to send email to segment attached to email does not exist. Take a look at the dump from email API connection.... Endpoints called bcRegexEndpoints array size is (1) Mautic version is v2.13.1

object(Mautic\Api\Emails)#5866 (11) {

  ["endpoint":protected]=>
  string(6) "emails"

  ["listName":protected]=>
  string(6) "emails"

  ["itemName":protected]=>
  string(5) "email"

  ["bcRegexEndpoints":protected]=>
  **array(1) {
    ["emails/(.*?)/contact/(.*?)/send"]=>
    string(25) "emails/$1/send/contact/$2"
  }**

  ["searchCommands":protected]=>
  array(7) {
    [0]=>
    string(3) "ids"
    [1]=>
    string(12) "is:published"
    [2]=>
    string(14) "is:unpublished"
    [3]=>
    string(7) "is:mine"
    [4]=>
    string(16) "is:uncategorized"
    [5]=>
    string(8) "category"
    [6]=>
    string(4) "lang"
  }

  ["bcTesting"]=>
  bool(false)

  ["endpointsSupported":protected]=>
  array(0) {
  }

  ["bcAttempt":protected]=>
  bool(false)

  ["baseUrl":protected]=>
  string(44) "https://ads.experienciasdigitais.com.br/api/"

  ["auth":"Mautic\Api\Api":private]=>
  object(Mautic\Auth\BasicAuth)#5865 (6) {
    ["password":"Mautic\Auth\BasicAuth":private]=>
    string(12) "XXXXXXXXXX"
    ["userName":"Mautic\Auth\BasicAuth":private]=>
    string(4) "yyyyy"
    ["_debug":protected]=>
    bool(false)
    ["_httpResponseHeaders":protected]=>
    NULL
    ["_httpResponseInfo":protected]=>
    NULL
    ["_curlTimeout":protected]=>
    NULL
  }
  ["logger":"Mautic\Api\Api":private]=>
  NULL
}

When i call the endpoint the following error occurs:

array(2) {
  ["errors"]=>
  array(1) {
    [0]=>
    array(3) {
      ["code"]=>
      int(404)
      ["message"]=>
      string(19) "Item was not found."
      ["details"]=>
      array(0) {
      }
    }
  }
  ["error"]=>
  array(3) {
    ["message"]=>
    string(115) "Item was not found. (`error` is deprecated as of 2.6.0 and will be removed in 3.0. Use the `errors` array instead.)"
    ["code"]=>
    int(404)
    ["details"]=>
    array(0) {
    }
  }
}

Email id is fine does exists on Mautic. So. Any idea?

Attached below source code.

code


Want to back this issue? Post a bounty on it! We accept bounties via Bountysource.

morettic2015 avatar Jun 24 '18 23:06 morettic2015

@escopecz any ideia?

morettic2015 avatar Jun 29 '18 07:06 morettic2015

Make sure that the email exist and is not unpublished.

escopecz avatar Jun 29 '18 12:06 escopecz

The problem remains. Take a look same problem another instance. Integration was working until 2.13 version. Now seems like send a segment email is not working anymore.

Here is a sample of the same problem in another instance of Mautic on 2.14 version. (fresh)

Array to create email data

` $data = array(

        'title' => $titulo,

        'name' => $name,

        'fromName' => $fromName,

        'subject' => $subject,

        'customHtml' => $customHtml,

        'description' => $description,

        'plainText' => $plainText,

        'emailType' => 'list',

        'lists' => array($list),

        'replyToAddress' => '[email protected]',

        'isPublished' => 1

    );`

Code for sending email: `

    $con = LeadController::connectMautic();

    $emailApi = $con->api->newApi("emails", $con->auth, MAUTIC_INSTANCE_API);

    var_dump($emailApi);

    $email = $emailApi->send($emailID);

    var_dump($email);
   // die;

    return $email;

`

Execution log

EMAIL ID==190== object(Mautic\Api\Emails)#139 (11) { ["endpoint":protected]=> string(6) "emails" ["listName":protected]=> string(6) "emails" ["itemName":protected]=> string(5) "email" ["bcRegexEndpoints":protected]=> array(1) { ["emails/(.*?)/contact/(.*?)/send"]=> string(25) "emails/$1/send/contact/$2" } ["searchCommands":protected]=> array(7) { [0]=> string(3) "ids" [1]=> string(12) "is:published" [2]=> string(14) "is:unpublished" [3]=> string(7) "is:mine" [4]=> string(16) "is:uncategorized" [5]=> string(8) "category" [6]=> string(4) "lang" } ["bcTesting"]=> bool(false) ["endpointsSupported":protected]=> array(0) { } ["bcAttempt":protected]=> bool(false) ["baseUrl":protected]=> string(37) "https://inbound.citywatch.com.br/api/" ["auth":"Mautic\Api\Api":private]=> object(Mautic\Auth\BasicAuth)#138 (6) { ["password":"Mautic\Auth\BasicAuth":private]=> string(8) "leadmobi" ["userName":"Mautic\Auth\BasicAuth":private]=> string(8) "leadmobi" ["_debug":protected]=> bool(false) ["_httpResponseHeaders":protected]=> NULL ["_httpResponseInfo":protected]=> NULL ["_curlTimeout":protected]=> NULL } ["logger":"Mautic\Api\Api":private]=> NULL } array(2) { ["errors"]=> array(1) { [0]=> array(3) { ["code"]=> int(404) ["message"]=> string(19) "Item was not found." ["details"]=> array(0) { } } } ["error"]=> array(3) { ["message"]=> string(115) "Item was not found. (erroris deprecated as of 2.6.0 and will be removed in 3.0. Use theerrors array instead.)" ["code"]=> int(404) ["details"]=> array(0) { } } }

As you can see email is published and id EMAIL ID190 was generated.

GitHub Logo Format: !

morettic2015 avatar Aug 02 '18 20:08 morettic2015

@morettic2015 on v2.15 it's work fine for me. I use this code :

$api = new MauticApi();
        //Create email
        $emailApi = $api->newApi("emails", $auth, $apiUrl);
        $data = array(
            'name'          => 'Name of email',
            'subject'       => 'Subject of email',
            'isPublished'   => 1,
            'language'      => 'fr',
            'customHtml'    => $emailHtml,
            'plainText'     => $emailText,
            'emailType'     => 'list',
            'template'      => 'mautic_code_mode',
            'lists'         => array(158)   //ID of your list
        );
        $email = $emailApi->create($data);
        //Send email
        $email = $emailApi->send($email['email']['id']);

Can you retry ?

PierreAmmeloot avatar Aug 19 '19 09:08 PierreAmmeloot