I am working on retrieving all orders that had any transaction activity (e.g., fully paid, partially paid, or refunded) on a specific date using the Admin API.
To fetch all orders that had any of the following transaction kinds on a given date:
-
sale (full or partial)
-
capture
-
refund
-
manual
My code is below:
$targetDate = ‘2025-06-01’;
$endDate1 = ‘2025-06-01’;
$startDate = $targetDate . ‘T00:00:00Z’;
$endDate = $endDate1 . ‘T23:59:59Z’;// Checkpoint file to resume pagination
$checkpointFile = DIR . ‘/page_info_checkpoint.txt’;
$pageInfo = file_exists($checkpointFile) ? trim(file_get_contents($checkpointFile)) : null;echo “Fetching orders on: $targetDate\nRange: $startDate to $endDate\n\n”;
$baseParams = [
‘limit’ => 100,
‘status’ => ‘any’,
‘fields’ => ‘id,name,total_price,created_at,financial_status,user_id,customer’,
‘created_at’ => $startDate,
‘created_at’ => $endDate,
‘order’ => ‘created_at’
];// Build URL with or without page_info
$baseUrl = “https://$shop/admin/api/2024-04/orders.json”;
$url = $baseUrl;
if ($pageInfo) {
$url .= ‘?page_info=’ . urlencode($pageInfo);
foreach ($baseParams as $key => $value) {
$url .= ‘&’ . $key . ‘=’ . urlencode($value);
}
} else {
$url .= ‘?’ . http_build_query($baseParams);
}// Fetch Orders
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
“X-Shopify-Access-Token: $accessToken”
]);
$response = curl_exec($ch);// Handle cURL errors
if (curl_errno($ch)) {
echo "cURL Error: " . curl_error($ch) . “\n”;
exit;
}$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$headersRaw = substr($response, 0, $headerSize);
$body = substr($response, $headerSize);
curl_close($ch);$data = json_decode($body, true);
echo “”;
print_r($data);
exit;