Passing template as expression in Whatsapp Business Node

Hello everyone, I have been trying to pass the template as an expression, a json returned earlier by a code node so I can change the template based on the input.

My Whatsapp send template node views the expression I wrote,
{{ $json.template_resposta }} as returning [Object: {"name": "------", "language": {"code": "----"}}]

With this input condition, i get the error message: template.split is not a function or its return value is not iterable

So, I already tried to .toJsonString() it, in this way I get the following input: {"name":"------","language":{"code":"------"}}

And the different error message:
Bad request - please check your parameters
The parameter template[‘language’][‘code’] is required.

According to the Meta API, a sample template request should be like this:

curl -X  POST \
 'https://graph.facebook.com/v21.0/FROM_PHONE_NUMBER_ID/messages' \
 -H 'Authorization: Bearer ACCESS_TOKEN' \
 -H 'Content-Type: application/json' \
 -d '{
  "messaging_product": "whatsapp",
  "recipient_type": "individual",
  "to": "PHONE_NUMBER",
  "type": "template",
  "template": {
    "name": "TEMPLATE_NAME",
    "language": {
      "code": "LANGUAGE_AND_LOCALE_CODE"
    },
    "components": [
      {
        "type": "body",
        "parameters": [
          {
            "type": "text",
            "text": "text-string"
          },
          {
            "type": "currency",
            "currency": {
              "fallback_value": "VALUE",
              "code": "USD",
              "amount_1000": NUMBER
            }
          },
          {
            "type": "date_time",
            "date_time": {
              "fallback_value": "DATE"
            }
          }
        ]
      }
    ]
  }
}'

I don’t see what is wrong with my implementation of the template json, thank you for any suggestions

Information on your n8n setup

  • n8n version: 1.64.3
  • Database: SQLite
  • n8n EXECUTIONS_PROCESS setting: own, main:
  • Running n8n via Docker
  • Operating system: Windows

It looks like your topic is missing some important information. Could you provide the following if applicable.

  • n8n version:
  • Database (default: SQLite):
  • n8n EXECUTIONS_PROCESS setting (default: own, main):
  • Running n8n via (Docker, npm, n8n cloud, desktop app):
  • Operating system:

hello @luizfv

try this one:
{{ JSON.stringify($json.template_resposta) }}