TWIG JSON Payload in Send Email API

Your software
My Mautic version is: 4.1.1

Your problem
My problem is:

I am using the Twig Advanced Email Templates Plugin

I am using TWIG to JSON_DECODE an order confirmation payload.
As per the examples, I am successful in doing this by first writing the JSON payload to a custom field on the Contact i.e. {% set cart = contact.json_last_order| json_decode %}

Everything works successfully, but my question is whether I could eliminate the step of writing the JSON to the contact field, and instead post the JSON as part of the send email API ? (/api/emails/39/contact/689/send)

It seems that if I post JSON as part of the Send API payload body, e.g. my payload looks like

    "tokens": {
        "locale": "en_GB",
        "currency": "EUR",
        "entity_id": "36140"

I can print within the Mautic email, values from the JSON e.g. {entity_id} will print in the email “36140”.
So it seems that the Mautic email somehow see’s the JSON attributes and can reference/print them.

What I can’t seem to figure out is whether I can use the same concept with the TWIG to just reference the JSON payload without referencing the contact.json_last_order field.

I have tried a simple TWIG of

{% set cart = tokens| json_decode %} 
{% if cart %} <!-- If Cart Not Null -->
{% endif %}

This doesn’t appear to work

Has anyone had any similar success?

My reasoning for eliminating the solution around the contact field, is simply because the contact field will contain the last order JSON, and if this wasn’t updated and the email triggered then it would print the previous order and perhaps not the most recent.

HI Gravitai

Have you apply the patch for this feature?

It’s this one:


Thanks Sebastian,

We had first tried tried this plugin, but it wouldn’t work for us on Mautic 4.
We are using the Mautic Extendee plugin, which does work for Mautic 4.

The feature you mention for arbitrary tokens using email send api is precisely what we’re doing.
Zdeno Kuzmany from Mautic Extendee has reached out to me and I’ll sponsor a custom fix/feature for this Mautic Extendee plugin.

Thanks for your input.