Cannot get or add Cart through API
Forum rules
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Always add your Laravel, Aimeos and PHP version as well as your environment (Linux/Mac/Win)
Spam and unrelated posts will be removed immediately!
Cannot get or add Cart through API
Laravel version: 8.76.2
Aimeos version: 2021.10
PHP version: 8.0.14
Environment: Nginx, Linux, Laravel
I am building an application using Aimeos APIs. The APIs for adding products to the cart works fine while using them with Postman. But inside the application when I try those APIs with GuzzleHttp, products won't add to the cart.
When hitting API to add a product, the response is as expected, but hitting again won't change the quantity. Also, fetching the cart returns an empty cart. My guess is that the session for the cart is not set properly by the application as the same APIs work in Postman.
I am not sure what I am missing in my application setup. I am using Laravel and have set SESSION_DRIVER=file. Also, I am sending setting the cookie in GuzzleHttp object with CSRF Token.
My complete GuzzleHttp Setting:
$cookieJar = CookieJar::fromArray(
[
'XSRF-TOKEN' => $_COOKIE['XSRF-TOKEN'],
strtolower(env('APP_NAME')) . '_session' => $_COOKIE[strtolower(env('APP_NAME')) . '_session']
],
env('APP_DOMAIN')
);
$this->headers = [
'Host' => env('APP_DOMAIN'),
'Accept' => 'application/json',
'Content-type' => 'application/json'
];
$this->client = new Client([
'base_uri' => env('APP_URL'),
'headers' => $this->headers,
'cookies' => $cookieJar
]);
Is there anything more that I need to change?
Aimeos version: 2021.10
PHP version: 8.0.14
Environment: Nginx, Linux, Laravel
I am building an application using Aimeos APIs. The APIs for adding products to the cart works fine while using them with Postman. But inside the application when I try those APIs with GuzzleHttp, products won't add to the cart.
When hitting API to add a product, the response is as expected, but hitting again won't change the quantity. Also, fetching the cart returns an empty cart. My guess is that the session for the cart is not set properly by the application as the same APIs work in Postman.
I am not sure what I am missing in my application setup. I am using Laravel and have set SESSION_DRIVER=file. Also, I am sending setting the cookie in GuzzleHttp object with CSRF Token.
My complete GuzzleHttp Setting:
$cookieJar = CookieJar::fromArray(
[
'XSRF-TOKEN' => $_COOKIE['XSRF-TOKEN'],
strtolower(env('APP_NAME')) . '_session' => $_COOKIE[strtolower(env('APP_NAME')) . '_session']
],
env('APP_DOMAIN')
);
$this->headers = [
'Host' => env('APP_DOMAIN'),
'Accept' => 'application/json',
'Content-type' => 'application/json'
];
$this->client = new Client([
'base_uri' => env('APP_URL'),
'headers' => $this->headers,
'cookies' => $cookieJar
]);
Is there anything more that I need to change?
Re: Cannot get or add Cart through API
Seems to be fine. The important parts are the cookies for "laravel_session" and CSRF token.
Professional support and custom implementation are available at Aimeos.com
If you like Aimeos, give us a star
If you like Aimeos, give us a star