Possible bug - send email - wrong JSON format for template values

Hi,

Just wanted to let you know about an issue I had.

The Codeless “Send Email from Template” block does not appear in the Codeless doc. So I had a look at the REST doc, where it says for the template-values parameter : a JSON object containing values which will be used Smart and Dynamic text substitutions.

Turns out my JSON object was not accepted because it was not “flat” (i.e. it had an object within the object).

The error I got was

ResponseError: Wrong json format: Cannot deserialize value of type `java.lang.String` from Object value (token `JsonToken.START_OBJECT`)
 at [Source: UNKNOWN; byte offset: #UNKNOWN] (through reference chain: com.backendless.services.mail.SendTemplateMailMessage["template-values"]->java.util.LinkedHashMap["localizations"])
    at checkStatus (/usr/local/lib/node_modules/backendless-coderunner/node_modules/backendless-request/lib/request.js:330:9)
    at processTicksAndRejections (internal/process/task_queues.js:95:5)

When trying out with a flat object, it worked. I don’t know it this is intentional. But I now need to flatten my object before sending it into the template. Would be nice to have the information in the doc, and it would be easier to be able to call an item such as object1.object2.property in the templates Smart text.

Hello @Nicolas_REMY

Thanks for letting me know.
Could you provide us with a simple codeless example?

Regards

I have changed my logic since then, in order to use a flat object, so it won’t show up anymore.

But you can send an object to the template with a object1->object2->property structure, and then try a Smart text using {object1.object2.property} in the template. This is pretty much what caused the issue for me.

@Nicolas_REMY ,

It seems to me that you have misunderstood usage of template values. They were not designed to contain some complex object structures.
According to our documentation

A JSON object containing values which will be used Smart and Dynamic text substitutions. The property names in the object are matched against the Smart/Dynamic text placeholder names. The corresponding values are used for substitution in the resulting email message.

Yes, description does not directly mentions type of values for “template values” field but from context assumption can be made that they should be of primitive type.

I will create an internal ticket to update this documentation to mention values types explicitly.

Regards, Andriy