2

Is there a way to send e-mail over Mautic API with own properties sended in single-request with send request? Example: I want to send process e-mail with order summary to client. So I want to prepare e-mail template with ex. {special:orderId}, {special:orderPrice},... and want to do something like this

$api->send(emailId, contactId, [
    special => [
        'orderId' => 123,
        'orderPrice' => 1000
    ]
]);

Something extra - Client has some our e-shop categories in his favourites and I want to send basic newsletter with "new in your favourite category"... and just select created e-mail template and send with parameters

$parameters = [
    1 => [
        'name' => 'Product name',
        'price' => 123,
        'imgPath' => 'http://pathToImage'
        ...
    ],
    ...
]

Is there some way how to do this? I am beginner in Mautic but i thought it is designed for these specials but don't know how to do that...

Thank you very much for responds. Mautic v. 2.4

Radim Kleinpeter
  • 108
  • 2
  • 11

2 Answers2

4

Yes, you can use custom tokens in your e-mails. However API library does not support this directly. You need to put the values in an array structure and call makeRequest() function directly. This is because the API library sendToContact() function does not have a 3rd argument for optional data. It passes an empty array to makeRequest()

/**
 * Send email to a specific contact
 *
 * @param int $id
 * @param int $contactId
 *
 * @return array|mixed
 */
public function sendToContact($id, $contactId)
{
    return $this->makeRequest($this->endpoint.'/'.$id.'/contact/'.$contactId.'/send', array(), 'POST');
}

So you have to call it like this:

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

    $data = array(
        'tokens' => array(
            '{custom_token}' => 'My Custom Token'
        )
    );

    $email = $emailApi->makeRequest('emails/'.$email_id.'/contact/'.$contact_id.'/send', $data, 'POST');

Then you can use {custom_token} in your e-mail.

Or you can use the sendToContact method. Just replace the last line above as follows:

$email = $emailApi->sendToContact($email_id, $contact_id, $data);
Ricardo Martins
  • 5,702
  • 3
  • 40
  • 59
Evren Yurtesen
  • 2,267
  • 1
  • 22
  • 40
  • Sorry, but I don't see `sendToContact()` being used in your second example. "So you have to call it like this" implies that we are calling the function defined above. – TerranRich Dec 10 '19 at 16:39
0

I don't think something like this is possible, but it's a good idea for a feature request which you can submit here: https://github.com/mautic/mautic/issues

What you'd have to do now to achieve this, you'd have to add the contact custom fields like orderId and orderPrice, make the API call to update contact with latest order and then send the predefined email with {contactfield=orderId} and {contactfield=orderPrice} tokens to the contact and Mautic will take care of the token replacement for you.

John Linhart
  • 1,746
  • 19
  • 23