Cannot get or add Cart through API

Help for integrating the Laravel package
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!
nick
Posts: 1
Joined: 10 Dec 2021, 05:25

Cannot get or add Cart through API

Post by nick » 23 Dec 2021, 05:14

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?

User avatar
aimeos
Administrator
Posts: 8262
Joined: 01 Jan 1970, 00:00

Re: Cannot get or add Cart through API

Post by aimeos » 23 Dec 2021, 12:25

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, Image give us a star

Post Reply