API request fails with the exception: Session has not been set

Edit on GitHub

Executing an API command leads to the exception Session has not been set.


Most probably, you’re using a code that is relying on session. However, obviously, in case of an API, you don’t have the session.


Switch the session storage for the Messenger module to IN MEMORY:

use Spryker\Shared\Messenger\MessengerConfig as SharedMessengerConfig;
use Spryker\Zed\Messenger\MessengerConfig;