api->call($endpoint, ['shopid' => $shopid], 'get'); } catch (Throwable $e) { $content = []; } if (!is_array($content)) { continue; } // Common shapes we might receive from the API. if (!empty($content['data']) && is_array($content['data'])) { $maybe = $content['data']; if (!empty($maybe['history']) && is_array($maybe['history'])) { $history_rows = $maybe['history']; } elseif (!empty($maybe['items']) && is_array($maybe['items'])) { $history_rows = $maybe['items']; } else { $history_rows = $maybe; } } elseif (!empty($content['history']) && is_array($content['history'])) { $history_rows = $content['history']; } elseif (!empty($content['data']['history']) && is_array($content['data']['history'])) { $history_rows = $content['data']['history']; } if (!empty($history_rows)) { break; } } // Normalize if the API returns an associative object. $history_rows = is_array($history_rows) ? array_values($history_rows) : []; ?>