Search code examples
facebookfacebook-graph-apiwhatsapp

Send whatsapp messages from app system token


I am building a Meta app to integrate whatsapp messaging in our appointment software.

On first step, I have completed the oauth steps in my app and can check all the scopes etc is fine /debug_token response :

{
    "data": {
        "app_id": "xxxxxxxxxx",
        "type": "USER",
        "application": "DaySchedule",
        "data_access_expires_at": 1686914263,
        "expires_at": 1684243122,
        "is_valid": true,
        "issued_at": 1679059122,
        "scopes": [
            "email",
            "business_management",
            "whatsapp_business_management",
            "whatsapp_business_messaging",
            "public_profile"
        ],
        "granular_scopes": [
            {
                "scope": "business_management"
            },
            {
                "scope": "whatsapp_business_management",
                "target_ids": [
                    "3166497446926227",
                    "100885679528085"
                ]
            },
            {
                "scope": "whatsapp_business_messaging",
                "target_ids": [
                    "3166497446926227",
                    "100885679528085"
                ]
            }
        ],
        "user_id": "xxxxx"
    }
}

On 2nd step, I have completed the phone number registration successfully.

fb registration

On 3rd step, I am trying to send message

But when I am sending template message via PHONE_ID/messages API from registered phone number ID, it's throwing permission error. While the necessary permission are granted business_management, whatsapp_business_management, whatsapp_business_messaging.

FB messaging error

The error:

You do not have the necessary permissions required to send messages on behalf of this WhatsApp Business Account

Am i missing something?


Solution

  • Are you using user short duration token or long live user token? You can't send messages with short duration tokens, you need to exchage it for a long live user token. See how to do it here: Getting long live duration tokens