Discuss and resolve questions on Liquid, JavaScript, themes, sales channels, and site speed enhancements.
Hello all,
I'm develping on App using Shopify PHP App Template,
in-app I'm trying top get cart data, but its gives the error, below is my code, that I have tried,
MycartComponent.jsx
const shopDomain = 'myshop.myshopify.com';
const accessToken = 'shpa0dfe2de8c1c791a9a8e2c7a2de9a5901';
const apiUrl = `https://${shopDomain}/admin/api/2023-07/graphql.json`;
//const corsAnywhereUrl = 'https://cors-anywhere.herokuapp.com/';
const corsAnywhereUrl = 'http://localhost:8080/';
const cartId = "gid://shopify/Cart/1";
const query = `
query {
cart(
id: "gid://shopify/Cart/1"
) {
id
createdAt
updatedAt
lines(first: 10) {
edges {
node {
id
quantity
attributes {
key
value
}
}
}
}
attributes {
key
value
}
cost {
totalAmount {
amount
currencyCode
}
subtotalAmount {
amount
currencyCode
}
}
}
}
`;
axios.post(corsAnywhereUrl + apiUrl, {
query: query
}, {
headers: {
'Content-Type': 'application/json',
'X-Shopify-Access-Token': accessToken,
}
})
.then(response => {
console.log('Response:', response.data.data);
})
.catch(error => {
console.error('Error:', error);
});
below is the error.
{
"errors": [
{
"message": "Field 'cart' doesn't exist on type 'QueryRoot'",
"locations": [
{
"line": 2,
"column": 7
}
],
"path": [
"query",
"cart"
],
"extensions": {
"code": "undefinedField",
"typeName": "QueryRoot",
"fieldName": "cart"
}
}
]
}
now, how can I fix that error, I don't understand this.
please help me with this,
Thanks.
Hi @rushikesh93 , did you got any solution for this issue, 'cause am also facing the same. If you got any solution, please help me with that. Thanks.
In Canada, payment processors, like those that provide payment processing services t...
By Jacqui Mar 14, 2025Unlock the potential of marketing on your business growth with Shopify Academy's late...
By Shopify Mar 12, 2025Learn how to increase conversion rates in every stage of the customer journey by enroll...
By Shopify Mar 5, 2025