im trying to create public Shopify App, using Shopify / shopify-app-template-php , im stuck at one place, on how to get current cart data using API.
i have tried code like below,
Routes
Route::get('/api/get-cart-data', [App\Http\Controllers\FormController::class, 'fetchCart']);
FormController
$accessToken,
'X-Shopify-Storefront-Access-Token' => $storePassword,
])->get($url);
// Debugging statements
//var_dump($response->status()); // status 200
//var_dump($response->body()); // response body 11483
// Check if the request was successful
if ($response->successful()) {
// Get the cart data from the response body
$cartData = $response->json();
// Return the cart data as a JSON response
return response()->json($cartData);
} else {
// Handle the error case
$errorMessage = $response->json()['errors'][0] ?? 'Unknown error occurred.';
return response()->json(['error' => $errorMessage], $response->status());
}
}
}
Reactjs Component
import React from 'react';
import { Toast, Form, FormLayout, TextField, Select, Frame } from '@shopify/polaris';
import { useState, useEffect, useCallback } from 'react';
import { Button } from '@shopify/polaris';
import { useAppQuery } from "../hooks";
export function GetCart() {
useEffect(() => {
const fetchCartData1 = async () => {
try {
const response = await fetch('/api/get-cart-data');
const data = await response.json();
console.log('Cart data:', data);
} catch (error) {
console.error('Error fetching cart data:', error);
}
};
fetchCartData1();
}, []);
}
but when i run the code, its gives nothing, when i check with
var_dump($response->status()); gives status 200
var_dump($response->body()); gives response body 11483
and aslo asked for the store password,
below screenshot display the Response of API
please help me with this how can i get current cart details using API?
i have treid code, that i add already in above question

