Issue Fetching All Orders with Transactions on a Specific Date (Partial/Fully Paid or Refunded)

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;

Hey @pramod1222

You’re currently filtering orders by created_at, which will only fetch orders created on the given date — not orders that had transaction activity like payments, refunds, or captures on that date.

If you want to fetch orders with any kind of transaction (sale, capture, refund, manual) on a specific date, you’ll need to:

Updated Approach:1. Pull all orders (within a reasonable date range)

  1. Loop through each order’s transactions endpoint

  2. Filter transactions by created_at timestamp that matches your target date

  3. Collect those order IDs where a transaction occurred on that date

Step-by-step Logic:

$targetDate = '2025-06-01';
$startDate = $targetDate . 'T00:00:00Z';
$endDate = $targetDate . 'T23:59:59Z';

// Step 1: Get all recent orders (e.g., from past X days)
$ordersUrl = "https://$shop/admin/api/2024-04/orders.json?status=any&limit=100&created_at_max=$endDate";

// Step 2: Loop through orders
foreach ($orders as $order) {
    $orderId = $order['id'];
    
    // Step 3: Fetch transactions for each order
    $transactionsUrl = "https://$shop/admin/api/2024-04/orders/$orderId/transactions.json";
    
    // Make the API call and get transactions
    // ...

    foreach ($transactions as $txn) {
        $txnDate = $txn['created_at'];

        if ($txnDate >= $startDate && $txnDate <= $endDate) {
            // Match found! Add to result list
            $matchedOrders[] = $order;
            break; // No need to check more txns for this order
        }
    }
}

Why This Works:- Shopify doesn’t allow filtering orders by transaction timestamp directly via the Admin API.

  • So we pull relevant orders, then inspect their transactions.json to find any matches on the specific date.

Let me know if you’d like a more optimized script or how to handle pagination for larger stores.

Want me to write this in pure PHP with cURL too? Let me know!