Search code examples
laravelnotificationswhatsapp-cloud-api

How to fix WhatsApp API error with Laravel?


I'm using this package to send messages on WhatsApp Business, but when I try to use it i get this error:

{"error":{"message":"Unsupported post request. Object with ID 'messages' does not exist, cannot be loaded due to missing permissions, or does not support this operation. Please read the Graph API documentation at https://developers.facebook.com/docs/graph-api","type":"GraphMethodException","code":100,"error_subcode":33,"fbtrace_id":"AZy2DQf7fRL003f1RJcY8Kf"}}

I tried changing the token many times and also switching phone numbers. What can I do?

Here's what i did:

Added this to config/services.php:

 'whatsapp' => [
            'from-phone-number-id' => env('WHATSAPP_FROM_PHONE_NUMBER_ID'),
            'token' => env('WHATSAPP_TOKEN'),
        ],

Added application token and phone number id inside .env:

WHATSAPP_FROM_PHONE_NUMBER_ID=XXXXXX

WHATSAPP_TOKEN=XXXXXX

And then I created a notification class in Laravel like the instructions said and used the notification facade to send the message.

I just tried using the notify method of the Notifiable Trait like this:

Route::get('/wa', function ()
{
    $user = User::find(4);

    $user->notify(new AppuntamentiPazienti());

    return view('homepage');
});

but i got the same error.


Solution

  • Looks like i wasn't updating my .env and therefore using an old token. I solved using the command:

    php artisan config:clear