You need sports data in your PHP app now, not next sprint. By the end of this guide you’ll list all supported sports from SofaScore - Live API, search entities like clubs and national teams, and fetch country flags—using production-ready PHP code that you can ship this week via Zyla API Hub.
What you can build with the SofaScore - Live API
The SofaScore - Live API on Zyla API Hub provides sports metadata you can integrate quickly:
- Get all supported sports (e.g., Football, Tennis, Basketball).
- Search across SofaScore entities (teams, players, competitions and more) by query string.
- Fetch country flags as image bytes for UI badges and league country markers.
This API is a fit for scoreboards, match centers, betting tools, scouting dashboards, or any sports product that needs clean metadata and images. It’s hosted behind Zyla API Hub, so you use one key and one subscription model across all APIs you adopt.
Getting started on Zyla API Hub
To call the SofaScore - Live API:
- Open the listing: SofaScore - Live API on Zyla.
- Click Subscribe (or Start Free Trial when available). Zyla uses a subscription + quota model, not pay-per-call. Typically, first-time users can access a 7-day trial or 50 requests for their first API—check the API page for current access options and pricing.
- Copy your API key from your dashboard.
All requests require the header Authorization: Bearer YOUR_API_KEY. Do not pass any origin access keys—use only the Zyla key. You can add more sports APIs later with the same account and billing on Zyla API Hub.
Endpoints you will use
Below are the documented endpoints exposed through Zyla for this API. Only use the URLs, methods, and parameters exactly as listed.
1) Get all sports
Returns a list of all available sports.
- Method: GET
- URL: https://zylalabs.com/api/12787/sofascore-live-api/25080/get-all-sports
- Parameters: none
- Auth: Authorization: Bearer YOUR_API_KEY
cURL
curl -s -X GET "https://zylalabs.com/api/12787/sofascore-live-api/25080/get-all-sports" \
-H "Authorization: Bearer YOUR_API_KEY"
PHP (curl_init)
<?php
$ch = curl_init();
curl_setopt_array($ch, [
CURLOPT_URL => "https://zylalabs.com/api/12787/sofascore-live-api/25080/get-all-sports",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
"Authorization: Bearer YOUR_API_KEY"
],
CURLOPT_TIMEOUT => 15
]);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ($response === false || $httpCode >= 400) {
throw new RuntimeException("Request failed: HTTP $httpCode - ".curl_error($ch));
}
curl_close($ch);
$data = json_decode($response, true);
if (json_last_error() !== JSON_ERROR_NONE) {
throw new RuntimeException("Invalid JSON: ".json_last_error_msg());
}
// Example: build a select menu of sports
foreach ($data as $sport) {
printf("<option value='%s'>%s</option>\n",
htmlspecialchars($sport["slug"], ENT_QUOTES),
htmlspecialchars($sport["name"], ENT_QUOTES)
);
}
JSON (real example)
[
{
"id": 1,
"name": "Football",
"slug": "football"
},
{
"id": 5,
"name": "Tennis",
"slug": "tennis"
},
{
"id": 2,
"name": "Basketball",
"slug": "basketball"
},
{
"id": 64,
"name": "Baseball",
"slug": "baseball"
},
{
"id": 23,
"name": "Volleyball",
"slug": "volleyball"
},
{
"id": 63,
"name": "American football",
"slug": "american-football"
},
{
"id": 6,
"name": "Handball",
"slug": "handball"
},
{
"id": 20,
"name": "Table tennis",
"slug": "table-tennis"
},
{
"id": 4,
"name": "Ice hockey",
"slug": "ice-hockey"
},
{
"id": 22,
"name": "Darts",
"slug": "darts"
},
{
"id": 72,
"name": "E-sports",
"slug": "esports"
},
{
"id": 11,
"name": "Motorsport",
"slug": "motorsport"
},
{
"id": 65,
"name": "Cycling",
"slug": "cycling"
},
{
"id": 62,
"name": "Cricket",…
Field notes you’ll actually use:
- id: Integer identifier for the sport. Useful for mapping and filtering.
- name: Human-friendly label (render this in your UI).
- slug: URL-safe unique key (use in routes, cache keys, and lookups).
Implementation tips:
- Cache this response server-side for at least a few hours. The set of sports changes infrequently compared to live scores.
- Treat slugs as stable identifiers for UI routing. Show names to users; store slugs in URLs.
2) Search all entities
Search all SofaScore entities by query string (teams, competitions, players, etc.).
- Method: GET
- URL: https://zylalabs.com/api/12787/sofascore-live-api/25082/search-all-entities
- Parameters:
- q (string, required): real madrid
cURL
Response details are not fully documented here, but it returns entities matched by your query with metadata such as id, name, slug, images, and country data where available. Parse only the fields your UI needs and log unknown attributes for later inspection.
3) Get country flag
Returns the country flag image bytes.
- Method: GET
- URL: https://zylalabs.com/api/12787/sofascore-live-api/31197/get-country-flag
- Parameters:
- country_code (string, required): EN
cURL
JSON (real example)
iVBORw0KGgoAAAANSUhEUgAAAJYAAACWCAMAAAAL34HQAAAABGdBTUEAALGPC/xhBQAAAAFzUkdCAK7OHOkAAAAJcEhZcwAACxMAAAsTAQCanBgAAAELUExURUdwTN/f37QVJd7e3t3d3d/f39/f39/f397e3t7e3t3d3d3d3d3d3d/f397e3t/f39/f39zc3N7e3rQUJN/f37MUJLUTJd/f39/f3+Hh4d3d3bMUJLUVJbQUJLUVJbUUJLcQKOHh4d3d3bQVJLQUJN/f397e3rQVJbIWI7ITI7QUJLcYKM4RJP///97e3rQUJPv7++Li4v39/ebm5uDg4Orq6vDw8OTk5Pf397sTJPn5+bsUJPPz8/Ly8u7u7rcUJMcSJOzs7PHx8cQSJO/v77gUJLgTJOjo6MoSJMETJL8TJLUUJL4TJOvr680RJMsSJMsRJMQTJL0TJO3t7cwRJLYUJM0SJLwUJL4UJDN2488AAAAsdFJOUwB/38+AMBAg79+fcJBAv3CfYKC/YICfj79vr0AwcGCvIF+Pz8+vsKBQULAgUCRTtgAABilJREFUeNrtnGdX40YUhoWrhA1uGFj6tmQ34VrFKl6vzdqYDrtJNvX//5JMkSU3YWk0kiYn3A/CB3zMc+776s54NHMlKV6cfThp756+zeVUErlcq7XbPj48kjKLYqOel9WAkLf3GsXUkcqVA7mDIwiL/FE+qKSItrWndKZBIR6vrz+TuL6excKhbG6lwyR3/ND/eZiM7r6dz8bdaHL/tzPzJmUz4ZyVKtvePzMtu2fAeUCA0bNvde/N+UaCUBteorp2H0gEYpHo210/ZeVkXL7pMxkwjeexUGgDjywBMA/KufKZwmARMj0ZME++bg/mIwwWip7lgm1wBHtFocyxBsCGhVLmgim8zF+md585r15ULB8szyVhrn6WBhAPywfb4JWqJU8xYSEwan6lzMNV5iUAHywAelfKlTg34B5NlQb8sKZKvikxC5hfkyomLJQwM46QRTJPcDTgjeU6TGEawF+TXP8OwB8L4Ip8OIPBNoiAA0gGCy5NpkpBqPQ+JIXlCrnBQqVBclgsXITKMSBJLDCciFyEqhuGKg5WVC5C9RUgaSyArxG4XhEFIQ0sIDPX16GqaGhfccCiOoaoq2Vc2/WwVHGxwNBDjUMlJWRl4IRF60R+3biN5wxmeKr4WNDH…
Field notes:
- The response is image bytes (base64-like content in the example). Store and serve as PNG bytes or cache as a file. If your runtime expects binary, ensure you don’t accidentally double-encode.
- Use a CDN or HTTP caching headers on your edge to avoid re-fetching the same flags.
JavaScript example (fetching sports)
Use this when you need to hydrate a client-side settings page or pre-render sports lists in Node.js. For production, call from your server to avoid exposing your key to the browser.
async function getAllSports() {
const res = await fetch("https://zylalabs.com/api/12787/sofascore-live-api/25080/get-all-sports", {
method: "GET",
headers: { "Authorization": "Bearer YOUR_API_KEY" }
});
if (!res.ok) {
throw new Error(`HTTP ${res.status}`);
}
const data = await res.json();
// Example: find Football
const football = data.find(s => s.slug === "football");
console.log(football);
return data;
}
getAllSports().catch(console.error);
Real-world integration patterns in PHP
Cache immutable metadata
Sports enumerations and flags don’t change often. Cache “Get all sports” for 6–24 hours and country flags indefinitely with a versioned filename (e.g., flags/EN.png). This reduces latency and quota usage.
Handle image bytes safely
For the country flag endpoint, write the raw response to storage as binary. In PHP:
<?php
$ch = curl_init("https://zylalabs.com/api/12787/sofascore-live-api/31197/get-country-flag?country_code=EN");
curl_setopt_array($ch, [
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => ["Authorization: Bearer YOUR_API_KEY"],
CURLOPT_TIMEOUT => 15
]);
$bytes = curl_exec($ch);
$http = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
if ($http >= 400 || $bytes === false) {
throw new RuntimeException("Flag fetch failed: HTTP $http");
}
file_put_contents(__DIR__ . "/flags/EN.png", $bytes);
Serve that file via your CDN or public assets path. If you need dynamic resizing, process into multiple sizes on first request and cache.
Search ergonomics
For “Search all entities”, debounce user input (e.g., 250–400ms), lowercase the query, and cache results for popular teams. Because the endpoint accepts q only, keep your UI’s filters client-side and re-query when needed. Always sanitize output since names may include special characters.
MCP: call this API from an AI agent
Every Zyla API is also callable from AI agents that support the Model Context Protocol (MCP), including Claude Code, Cursor, Windsurf, and other MCP-compatible clients. Point your tool to:
Pass your key as apikey in the MCP URL (e.g., https://mcp.zylalabs.com/mcp?apikey=YOUR_API_KEY). From there, your agent can invoke the same SofaScore - Live API endpoints by name through the MCP interface. This is useful for internal chatops, admin consoles, or rapid prototyping of sports lookups.
Use cases you can ship this week
- Sports selector widget: Hydrate a sport dropdown using Get all sports and route users to sport-specific pages by slug.
- Team search bar: Use Search all entities to autocomplete clubs like “Real Madrid” and jump straight to your internal team dashboards using returned ids/slugs.
- Country-badged tables: Attach country flags to standings, player lists, and competition cards by fetching and caching the flag image bytes once per country code.
Operational considerations
- Authentication: Always include Authorization: Bearer YOUR_API_KEY.
- Timeouts: Set client timeouts (10–20s) and retry idempotent GETs on transient failures.
- Caching strategy:
- Get all sports: cache for hours; invalidate on deploy or scheduled job.
- Country flags: cache indefinitely; store files on disk or object storage.
- Search results: cache by normalized q for a short TTL (e.g., minutes).
- Quotas and billing: Zyla uses subscription + quota. Typically, first-time users get a 7-day trial or 50 requests for their first API—confirm the current terms on the API page.
- Error handling: Inspect HTTP status codes. For 4xx, check parameters; for 5xx, implement backoff and surface diagnostics to logs.
Link references
- API page: SofaScore - Live API on Zyla
- Zyla hub: Zyla API Hub
FAQ
Does the SofaScore - Live API require any parameters for “Get all sports”?
No. The endpoint takes no parameters and only needs the Authorization header.
What’s the correct way to authenticate?
Use the header Authorization: Bearer YOUR_API_KEY on every request to https://zylalabs.com/api/… endpoints.
Can I display country flags directly in the browser?
Yes. Fetch once on your server using Get country flag, write bytes to a PNG file, and serve it as a static asset or via a CDN. Avoid fetching from the browser to keep your key private.
How do I search for a specific team or competition?
Call Search all entities with the q parameter. For example, q=real madrid. Parse the response to extract id, name, slug, and any image or country attributes you need.
Is there a free plan?
There is no free plan. Zyla uses a subscription + quota model. For first-time users, you typically get a 7-day trial or 50 requests for your first API; check the API page for current access options and pricing.
Get your key and ship
Create your Zyla account, subscribe to the SofaScore - Live API, and plug the Authorization header into the PHP code above. You can be rendering sports and country flags today. Register to get your API key and start integrating.
Official API response
[
{
"id": 1,
"name": "Football",
"slug": "football"
},
{
"id": 5,
"name": "Tennis",
"slug": "tennis"
},
{
"id": 2,
"name": "Basketball",
"slug": "basketball"
},
{
"id": 64,
"name": "Baseball",
"slug": "baseball"
},
{
"id": 23,
"name": "Volleyball",
"slug": "volleyball"
},
{
"id": 63,
"name": "American football",
"slug": "american-football"
},
{
"id": 6,
"name": "Handball",
"slug": "handball"
},
{
"id": 20,
"name": "Table tennis",
"slug": "table-tennis"
},
{
"id": 4,
"name": "Ice hockey",
"slug": "ice-hockey"
},
{
"id": 22,
"name": "Darts",
"slug": "darts"
},
{
"id": 72,
"name": "E-sports",
"slug": "esports"
},
{
"id": 11,
"name": "Motorsport",
"slug": "motorsport"
},
{
"id": 65,
"name": "Cycling",
"slug": "cycling"
},
{
"id": 62,
"name": "Cricket",
"slug": "cricket"
},
{
"id": 76,
"name": "Mixed Martial Arts",
"slug": "mma"
},
{
"id": 12,
"name": "Rugby",
"slug": "rugby"
},
{
"id": 29,
"name": "Futsal",
"slug": "futsal"
},
{
"id": 31,
"name": "Badminton",
"slug": "badminton"
},
{
"id": 26,
"name": "Waterpolo",
"slug": "waterpolo"
},
{
"id": 19,
"name": "Snooker",
"slug": "snooker"
},
{
"id": 13,
"name": "Aussie rules",
"slug": "aussie-rules"
},
{
"id": 34,
"name": "Beach volley",
"slug": "beach-volley"
},
{
"id": 109,
"name": "Minifootball",
"slug": "minifootball"
},
{
"id": 7,
"name": "Floorball",
"slug": "floorball"
},
{
"id": 15,
"name": "Bandy",
"slug": "bandy"
},
{
"id": 110,
"name": "Padel",
"slug": "padel"
}
]