Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Emmanuel71's avatar

nexmo/vonage Unexpected response from the API

Hello,I'm experiencing following problem sending sms in Laravel 9 with the nexmo solution: everything works well until I do 'php artisan config:cache'. After this, sending an sms throws following error: 'Unexpected response from the API'. This error also occurs when the sms-key and sms-secret are not set in the env-file. So I suppose it might be related to the fact that caching the config makes the settings unreadable or invalid. Any ideas on this please? Thx!

0 likes
3 replies
Emmanuel71's avatar

Just found following info in the docs in https://laravel.com/docs/9.x/configuration#configuration-caching :

"If you execute the config:cache command during your deployment process, you should be sure that you are only calling the env function from within your configuration files. Once the configuration has been cached, the .env file will not be loaded; therefore, the env function will only return external, system level environment variables."

As I'm sending the sms from the controller fetching the api keys from the env-file, I suppose this is the reason for the error. Any ideas on how to get around this? Of course I could hard code the api-keys in the controller or in a dedicated service, but is there also a more elegant solution? Thx.

Sinnbeck's avatar
Sinnbeck
Best Answer
Level 102

@Emmanuel71 You load them from env in a config file and then load that config file

For instance.

config('vonage.api_key');

Please or to participate in this conversation.