Hi everyone,
I’m working on a Customer Account UI Extension and trying to query order data using the Customer Account API. However, when I run the query, it returns null
for the order
field.
Here’s my current query and code:
const order = useOrder();
const dataQuery = {
query: `query {
order(id: "${order.id}") {
createdAt
id
}
}`
};
useEffect(() => {
async function getData() {
const query = await fetch("shopify://customer-account/api/unstable/graphql.json", {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(dataQuery),
});
const result = await query.json();
console.log(result);
}
getData();
});
Result from console:
{
"data": {
"order": null
},
"extensions": {
"cost": {
"requestedQueryCost": 1,
"actualQueryCost": 1,
"throttleStatus": {
"maximumAvailable": 7500.0,
"currentlyAvailable": 7499,
"restoreRate": 100.0
}
}
}
}
To verify that the API works correctly in general, I successfully queried customer data:
query: `query {
customer {
id
creationDate
}
}`
Result:
{
"data": {
"customer": {
"id": "gid://shopify/Customer/6846038638883",
"creationDate": "2023-03-17T21:25:43Z"
}
},
...
}
Scopes in .toml
file:
[access_scopes]
scopes = "customer_read_orders, customer_read_customers"
Extension target in shopify.extension.toml
file:
[[extensions.targeting]]
module = "./src/OrderStatusBlock.tsx"
target = "customer-account.order-status.block.render"
Am i missing something or why order query returns nothing?
Thanks!