[Python] WhatsApp Business API: Failed to send message: 400 {"error":{"message":"(#135000)...

Discussão em 'Python' iniciado por Stack, Fevereiro 24, 2025.

  1. Stack

    Stack Membro Participativo

    I am heaving problem with WhatsApp Api setup. I have already asked here but now I am going much deeper into the problem and giving you replicable solution in python.

    This is a working solution for sending the default hello_world:

    import requests
    import json

    phone_number_id = "xxx" # Your WhatsApp Cloud API phone number ID
    access_token = "xxx"
    template_name = "hello_world"

    # Replace with the recipient's phone number in E.164 format:
    recipient_phone = "whatsapp:+420602xxxxxx"

    # WhatsApp Cloud API endpoint URL
    url = f"https://graph.facebook.com/v15.0/{phone_number_id}/messages"

    # HTTP headers
    headers = {
    "Authorization": f"Bearer {access_token}",
    "Content-Type": "application/json"
    }

    # Payload for sending a WhatsApp template message
    payload = {
    "messaging_product": "whatsapp",
    "to": recipient_phone,
    "type": "template",
    "template": {
    "name": template_name,
    "language": {"code": "en_us"},
    "components": [
    {
    "type": "body",
    "parameters": [
    ]
    }
    ]
    }
    }

    # Send the POST request
    response = requests.post(url, headers=headers, json=payload)

    # Check and print the response
    if response.ok:
    print("Message sent successfully:")
    print(json.dumps(response.json(), indent=2))
    else:
    print("Failed to send message:")
    print(response.status_code, response.text)


    If I change the hello world to exactly same but my own created called "my_hello_world". I get this error:

    Failed to send message:
    400 {"error":{"message":"(#135000) Generic user error","type":"OAuthException","code":135000,"error_data":{"messaging_product":"whatsapp","details":"Generic user error"},"fbtrace_id":"AhxqWmU7Cl1iiCR-Jj7WD7A"}}


    all bellow is correct:

    • phone numer id
    • access token
    • recupient phone
    • template name ( I have tried different and it gives me diff error)

    What I tried:

    • different profile
    • different sending number
    • recreate template
    • used template without any parameters, headers
    • different languages of the template (now using en_us) as the default hello world

    Here is my previous question where I have used make.com to call the api with the same result.

    here are pictures of the templates: [​IMG] [​IMG]

    Continue reading...

Compartilhe esta Página