I am using the following PHP script to fetch orders for a single customer over the period of the last year, i.e. longer than 60 days. It does not return any data. I am using an access token with over 60 days access, which used to work with the REST API. I am wondering if you can tell me why my query is not working for fetching the last years data. Which should be around 10 orders.
// Customer email
$customerEmail = $_GET["email"];
$fromDate = "\"2025-01-01T00:00:00+10:00\"";
$customerQuery = <<<GQL
query getCustomerByEmail {
customers(first: 1, query: "email:$customerEmail") {
edges {
node {
id
email
firstName
lastName
}
}
}
}
GQL;
$payload = json_encode(["query" => $customerQuery]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://$shop.myshopify.com/admin/api/2024-10/graphql.json");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/json",
"X-Shopify-Access-Token: $token",
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$data = json_decode($response, true);
print_r($data);
if (empty($data['data']['customers']['edges'])) {
die("Customer not found.");
}
$customerId = $data['data']['customers']['edges'][0]['node']['id'];
echo "Customer ID: $customerId\n";
$ordersQueryString = "customer_id:".str_replace("gid://shopify/Customer/", "", $customerId)." processed_at:>=$fromDate";
$ordersQuery = <<<GQL
query getOrders(\$ordersQuery: String!) {
orders(first: 250, query: \$ordersQuery, sortKey: PROCESSED_AT, reverse: true) {
edges {
node {
id
name
processedAt
totalPriceSet { shopMoney { amount currencyCode } }
lineItems(first: 100) {
edges {
node {
id
title
quantity
sku
variantTitle
product {
id
title
featuredImage { url altText }
}
}
}
}
}
}
pageInfo {
hasNextPage
endCursor
}
}
}
GQL;
$payload = json_encode([
"query" => $ordersQuery,
"variables" => ["ordersQuery" => $ordersQueryString]
]);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, "https://$shop.myshopify.com/admin/api/2024-10/graphql.json");
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
"Content-Type: application/json",
"X-Shopify-Access-Token: $token",
]);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
curl_close($ch);
$ordersData = json_decode($response, true);
echo "<pre>";
print_r($ordersData);
echo "</pre>";