Search code examples
whatsapp

WhatsApp invalid num of params


What is wrong with the message? My WhatsApp template has two params:
lorem ipsum {{1}}, dolor sit amet {{2}}

data = {
    'messaging_product': 'whatsapp',
    'recipient_type': 'individual',
    'to': f'{mobile}',
    'type': 'template',
    'template': {
        'name': 'inform',
        'language': {
            'code': 'pt_PT',
        },
    },
    'components' : [{
        'type': 'header',
        'parameters': [{
            'type': 'text',
                'text': name,
        },
        {
            'type': 'text',
             'text': msg,
        }]
     }]
    }

Solution

  • As I can see, your request is invalid, the components property should be inside the template object,

    data = {
        'messaging_product': 'whatsapp',
        'recipient_type': 'individual',
        'to': f'{mobile}',
        'type': 'template',
        'template': {
            'name': 'inform',
            'language': {
                'code': 'pt_PT',
            },
            'components' : [{
                'type': 'header',
                'parameters': [{
                    'type': 'text',
                        'text': name,
                },
                {
                    'type': 'text',
                     'text': msg,
                }]
            }]
        }    
    }
    

    You can refer to the documentation:
    https://developers.facebook.com/docs/whatsapp/cloud-api/guides/send-message-templates#interactive