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

Request
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.

Metadata Score Breakdown

Estimated from metadata — endpoint not independently tested

This score is estimated from observable metadata — HTTPS support, authentication model, declared CORS, and documentation reachability — because the API requires authentication or exposes no publicly testable endpoint. The five-signal breakdown is only shown for live-tested APIs.

Metadata estimate · endpoint not independently tested

Technical Specifications

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

Related Tags

Similar APIs

View All →