Cricket API Integration in PHP and Laravel — Complete Guide 2026
Developer Guide 03 Nov 2026

Cricket API Integration in PHP and Laravel — Complete Guide 2026

Learn how to integrate CricketLiveApi into your PHP or Laravel application. Complete guide with code examples for live scores, scorecards, player stats, webhooks, and the built-in AI assistant in the API docs.

CricketLiveApi Team
CricketLiveApi Team

CricketLiveApi is the easiest cricket data API to integrate into any PHP or Laravel application. This guide walks you through everything — from your first API call to advanced webhook integration — with real, working code examples you can copy and use immediately.


Prerequisites

  • PHP 8.0+ or Laravel 9+
  • Composer installed
  • A free CricketLiveApi key — get one here (no credit card required)

Step 1 — Get Your API Key

Sign up at cricketliveapi.com/register. After registration, your API key is available in the dashboard. The free plan gives you 100 API calls/day — enough to build and test your integration.


Step 2 — Plain PHP Integration (No Framework)

Install Guzzle HTTP Client

composer require guzzlehttp/guzzle

Fetch Live Matches

 'https://cricketliveapi.com/api/v1/',
    'headers'  => [
        'Authorization' => 'Bearer YOUR_API_KEY',
        'Accept'        => 'application/json',
    ],
]);

// Fetch all live matches
$response = $client->get('cricket/matches/live');
$data     = json_decode($response->getBody(), true);

foreach ($data['matches'] as $match) {
    echo $match['title'] . "\n";
    echo "Score: " . ($match['score'] ?? 'Not started') . "\n";
    echo "Status: " . $match['status'] . "\n\n";
}

Fetch Full Scorecard

get("cricket/match/{$matchId}/{$slug}/scorecard");
$scorecard = json_decode($response->getBody(), true);

echo "Score: " . $scorecard['score'] . "\n";
echo "CRR: "   . $scorecard['crr']   . "\n";

foreach ($scorecard['current_batsmen'] ?? [] as $batter) {
    echo $batter['name'] . ": " . $batter['runs'] . "(" . $batter['balls'] . ")\n";
}

$bowler = $scorecard['current_bowler'] ?? null;
if ($bowler) {
    echo "Bowling: " . $bowler['name'] . " " . $bowler['overs'] . "-" . $bowler['wickets'] . "-" . $bowler['runs'] . "\n";
}

Step 3 — Laravel Integration

Add API Key to .env

CRICKET_API_KEY=your_cricketliveapi_key
CRICKET_API_BASE=https://cricketliveapi.com/api/v1

Create a CricketApiService

client = new Client([
            'base_uri' => config('services.cricket.base_url', 'https://cricketliveapi.com/api/v1/'),
            'headers'  => [
                'Authorization' => 'Bearer ' . config('services.cricket.key'),
                'Accept'        => 'application/json',
            ],
            'timeout' => 10,
        ]);
    }

    /** Get all live matches. Cached 15 seconds. */
    public function getLiveMatches(): array
    {
        return Cache::remember('cricket_live_matches', 15, function () {
            $response = $this->client->get('cricket/matches/live');
            return json_decode($response->getBody(), true)['matches'] ?? [];
        });
    }

    /** Get full scorecard. Cached 15 seconds. */
    public function getScorecard(int $matchId, string $slug): array
    {
        return Cache::remember("scorecard_{$matchId}_{$slug}", 15, function () use ($matchId, $slug) {
            $response = $this->client->get("cricket/match/{$matchId}/{$slug}/scorecard");
            return json_decode($response->getBody(), true);
        });
    }

    /** Get upcoming matches. Cached 5 minutes. */
    public function getUpcomingMatches(): array
    {
        return Cache::remember('cricket_upcoming', 300, function () {
            $response = $this->client->get('cricket/matches/upcoming');
            return json_decode($response->getBody(), true)['matches'] ?? [];
        });
    }

    /** Get player profile. Cached 1 hour. */
    public function getPlayer(int $playerId, string $slug): array
    {
        return Cache::remember("player_{$playerId}", 3600, function () use ($playerId, $slug) {
            $response = $this->client->get("cricket/player/{$playerId}/{$slug}");
            return json_decode($response->getBody(), true);
        });
    }
}

Register in config/services.php

'cricket' => [
    'key'      => env('CRICKET_API_KEY'),
    'base_url' => env('CRICKET_API_BASE', 'https://cricketliveapi.com/api/v1/'),
],

Use in a Controller

json(['matches' => $this->cricket->getLiveMatches()]);
    }

    public function scorecard(int $matchId, string $slug): JsonResponse
    {
        return response()->json($this->cricket->getScorecard($matchId, $slug));
    }
}

Add Routes

// routes/api.php
Route::get('/live',                       [CricketController::class, 'liveMatches']);
Route::get('/scorecard/{matchId}/{slug}', [CricketController::class, 'scorecard']);

Step 4 — Webhook Integration in Laravel

Webhooks let CricketLiveApi push events to your server the moment something happens — no polling required.

Register Your Webhook Endpoint

POST https://cricketliveapi.com/api/v1/webhooks/register
Authorization: Bearer YOUR_API_KEY

{
  "url":    "https://yourapp.com/api/webhooks/cricket",
  "secret": "your_webhook_secret",
  "events": ["score_update", "wicket", "match_start", "match_end"]
}

Handle Incoming Webhooks

header('X-Signature');
        $expected  = 'sha256=' . hash_hmac('sha256', $request->getContent(), $secret);

        if (! hash_equals($expected, $signature ?? '')) {
            return response('Unauthorized', 401);
        }

        $payload = $request->json()->all();
        $event   = $payload['event'] ?? null;
        $data    = $payload['data']  ?? [];

        match ($event) {
            'score_update'   => $this->onScoreUpdate($data),
            'wicket'         => $this->onWicket($data),
            'match_start'    => $this->onMatchStart($data),
            'match_end'      => $this->onMatchEnd($data),
            'innings_change' => $this->onInningsChange($data),
            default          => null,
        };

        return response('OK', 200);
    }

    private function onScoreUpdate(array $data): void
    {
        // $data['live'] has batter_striker, batter_non_striker,
        // bowler_striker, bowler_non_striker, partnership, recent_balls, crr, rrr
        $batter = $data['live']['batter_striker']['name'] ?? null;
        $bowler = $data['live']['bowler_striker']['name'] ?? null;
        Log::info("Score update: {$data['score']} | Batting: {$batter} | Bowling: {$bowler}");

        // Broadcast to WebSocket clients, send push notifications, etc.
        // event(new ScoreUpdated($data));
    }

    private function onWicket(array $data): void
    {
        Log::info("Wicket: {$data['score']}");
        // Send push notification, update fantasy leaderboard, etc.
    }

    private function onMatchStart(array $data): void  { /* ... */ }
    private function onMatchEnd(array $data): void    { /* ... */ }
    private function onInningsChange(array $data): void { /* ... */ }
}

Step 5 — Webhook Payload with Live Batter/Bowler Data

{
  "event":     "score_update",
  "timestamp": "2026-11-03T10:30:15Z",
  "match_id":  163940,
  "data": {
    "match_id":     163940,
    "series_name":  "India tour of Australia 2026",
    "match_format": "T20",
    "team_a": { "team_id": "6",  "team_name": "India",     "team_short": "IND" },
    "team_b": { "team_id": "2",  "team_name": "Australia", "team_short": "AUS" },
    "score":        "IND 142/3 (16.4 ov)",
    "score_details": { "runs": 142, "wickets": 3, "overs": 16, "balls": 4 },
    "status":       "IND need 23 runs in 20 balls",
    "status_detail":"IND need 23 runs in 20 balls",
    "state":        "In Progress",
    "prev_score":   "IND 138/3 (16.0 ov)",
    "curr_score":   "IND 142/3 (16.4 ov)",
    "live": {
      "batter_striker":     { "id": 1234, "name": "Virat Kohli",  "runs": 67, "balls": 42, "fours": 6, "sixes": 3, "strike_rate": 159.5 },
      "batter_non_striker": { "id": 5678, "name": "Rohit Sharma", "runs": 31, "balls": 24, "fours": 3, "sixes": 1, "strike_rate": 129.2 },
      "bowler_striker":     { "id": 9012, "name": "Hazlewood",    "overs": "3.4", "maidens": 0, "runs": 28, "wickets": 1, "economy": 7.6 },
      "bowler_non_striker": { "id": 3456, "name": "Starc",        "overs": "4.0", "maidens": 0, "runs": 32, "wickets": 2, "economy": 8.0 },
      "partnership":  { "runs": 44, "balls": 31 },
      "recent_balls": "1 . 4 W 1 6",
      "crr": 8.59,
      "rrr": 6.9,
      "target": 165,
      "last_wicket": "Gill b Hazlewood 38(27)"
    }
  }
}

Step 6 — Caching Best Practices

// Recommended cache TTLs
Cache::remember('cricket_live_matches',     15,   fn() => ...); // 15s  — live data
Cache::remember("scorecard_{$id}_{$slug}", 15,   fn() => ...); // 15s  — live scorecard
Cache::remember('cricket_upcoming',         300,  fn() => ...); // 5min — schedule
Cache::remember("player_{$id}",             3600, fn() => ...); // 1hr  — player profile

// Use Redis for best performance
// .env: CACHE_DRIVER=redis

AI Assistant in the API Docs — Build Faster with AI Help

CricketLiveApi's documentation at cricketliveapi.com/api-docs includes a built-in AI assistant that helps you integrate the API faster. Instead of reading through every endpoint manually, you can ask it questions like:

  • "How do I fetch live scores in Laravel?"
  • "Show me the scorecard response structure"
  • "How do I verify a webhook signature in PHP?"
  • "What fields are in the live block?"
  • "How do I get the current batter and bowler from a webhook?"

The AI assistant is trained on the full CricketLiveApi documentation and generates working PHP/Laravel code snippets on demand. It's the fastest way to get unstuck during integration.

How to Use the AI Assistant

  1. Go to cricketliveapi.com/api-docs
  2. Click the AI Assistant button (chat icon) in the bottom-right corner
  3. Ask any question about the API in plain English
  4. Get instant code examples, endpoint explanations, and integration guidance

The AI assistant is available to all users — free and paid — and is especially useful for developers who want to quickly prototype a feature without reading the full documentation.


Available Endpoints — Quick Reference

GET  /cricket/matches/live                         — All live matches
GET  /cricket/matches/upcoming                     — Upcoming matches
GET  /cricket/matches/recent                       — Recent results
GET  /cricket/match/{matchId}/{slug}/scorecard     — Full scorecard
GET  /cricket/match/{matchId}/{slug}/commentary    — Ball-by-ball commentary
GET  /cricket/player/{playerId}/{slug}             — Player profile
GET  /cricket/series/{seriesId}/{slug}/standings   — Points table
GET  /cricket/rankings/batting/{format}            — ICC batting rankings
POST /webhooks/register                            — Register webhook
GET  /webhooks                                     — List webhooks
DELETE /webhooks/{id}                              — Delete webhook

Frequently Asked Questions

Is there a PHP SDK for CricketLiveApi?

CricketLiveApi uses a standard REST API with JSON responses — any HTTP client works. Guzzle is the recommended choice for PHP and Laravel. The API is simple enough that you don't need a dedicated SDK.

How do I handle rate limits in PHP?

Cache your API responses using Laravel's Cache facade or a simple file/Redis cache in plain PHP. Live match data should be cached for 15 seconds, player profiles for 1 hour. This keeps you well within rate limits even on high-traffic sites.

How do I test webhooks locally?

Use ngrok to expose your local Laravel server: ngrok http 8000. Register the ngrok URL as your webhook endpoint in the CricketLiveApi dashboard. You'll receive live webhook events on your local machine.

What is the AI assistant in the docs?

The AI assistant at cricketliveapi.com/api-docs is a built-in chat interface trained on the full CricketLiveApi documentation. Ask it any question about endpoints, response formats, or integration patterns and it will generate working PHP/Laravel code for you instantly.


Conclusion

Integrating CricketLiveApi into PHP or Laravel is straightforward. The key points to remember:

  • Use Cache::remember() with appropriate TTLs to avoid rate limits
  • Use webhooks for real-time events instead of polling
  • The live block in webhook payloads gives you batter/bowler data on every delivery
  • The AI assistant in the docs can generate working code for any integration question instantly

Get Your Free API Key — Start Building Today →

Share this article

Start building with CricketLiveApi

Free tier available. No credit card required.

Get Free API Key