Transport for Spain API

Free to Use Varies (check documentation)

Overview

Transport for Spain provides access to public train data from Renfe, Spain's national rail operator. You can retrieve train schedules, station information, and route data for the Spanish rail network. No API key is required, making it easy to start building travel and transport apps.

💡

Beginner Tip

Start by browsing the open data portal to discover available datasets and their resource IDs before making API requests. Data is returned in JSON format and requires no authentication.

Available Data

match scores and results
team standings
player statistics
schedule and fixtures
Response fields: renfe com
Use case: Integrate public trains of spain data into web and mobile applications

Example Response

JSON Response
{
  "route": "Line 1",
  "origin": "Station A",
  "destination": "Station B",
  "departure": "08:30",
  "arrival": "09:15",
  "status": "On Time",
  "delays_min": 0
}

Field Reference

result.records Array of data records from the dataset.
result.total Total number of records available in the dataset.
result.fields Metadata describing the fields/columns in the dataset.
result.offset The offset used for pagination of results.
success Indicates whether the API request was successful.

Implementation Example

const url = "https://data.renfe.com/api/1/util/snippet/";
const response = await fetch(url);
if (!response.ok) throw new Error(`Request failed: ${response.status}`);
const data = await response.json();
console.log(data);

What Can You Build?

Note: These code examples are AI-generated and unverified. Always refer to the official API documentation for accurate usage.

Common Errors & Troubleshooting

404 Not Found The resource_id in the URL may be outdated or the dataset has been moved.
Visit https://data.renfe.com to browse current datasets and get the correct resource_id.
Empty or no results The dataset may have no records matching your query filters.
Remove filters and retrieve all records first to confirm data exists, then refine your query.
CORS error in browser Some endpoints may not support cross-origin requests from browsers.
Make requests from a server-side script (Node.js, Python) rather than directly from a browser.

Matrix Score Breakdown

🌐 Reachability 15/30
⚡ Speed 2/20
🔒 Security 15/15
🛠 Developer XP 15/20
✓ Reliability 7/15
Response Time 8380ms

Fully tested on Apr 5, 2026

Technical Specifications

Auth No Auth
HTTPS REQUIRED
CORS UNKNOWN
Category Transportation
Difficulty Beginner
Verified: 2026-04-04

Similar APIs

View All →