Transport for Spain API

Free to Use
53 D
Measured Score 0 50 100 Speed 15/30 Consistency 20/20 Security 14/20 Browser access 0/15 Transparency 4/15 TESTED 2026-08-10

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.

Measurement Record

What actually happened when we called this API from our own infrastructure. Every value below was recorded by the request, not copied from the provider's documentation.

Request
GET https://data.renfe.com/api/3/action/datastore_search?resource_id=a2368cff-1562-4dde-8466-9635ea3a572a&limit=5
Result
HTTP 200 · application/json · 3,363 bytes
Response time
245 ms (median of 3) · fastest 244 ms
Transport
TLSv1.2 · ECDHE-RSA-AES256-GCM-SHA384
Browser CORS
No Access-Control-Allow-Origin header — call it from a server, not the browser
Served by
nginx
Recorded
2026-08-10

Fields Returned

Top-level fields present in the response we captured, with the type and value we actually received.

Field Type Value received
include_total boolean true
resource_id string a2368cff-1562-4dde-8466-9635ea3a572a
fields array [1 item]
records_format string objects
records array [1 item]
limit integer 5
_links object {2 fields}
total integer 23

Captured Response

Captured from a real request to https://data.renfe.com/api/3/action/datastore_search?resource_id=a2368cff-1562-4dde-8466-9635ea3a572a&limit=5 on 2026-08-10. Long arrays and nested objects are truncated to keep the shape readable.

JSON Response · Captured
{
  "help": "https://data.renfe.com/api/3/action/help_show?name=datastore_search",
  "success": true,
  "result": {
    "include_total": true,
    "resource_id": "a2368cff-1562-4dde-8466-9635ea3a572a",
    "fields": [
      {
        "…": "(2 more fields)"
      }
    ],
    "records_format": "objects",
    "records": [
      {
        "…": "(11 more fields)"
      }
    ],
    "limit": 5,
    "_links": {
      "start": "/api/3/action/datastore_search?limit=5&resource_id=a2368cff-1562-4dde-8466-9635ea3a572a",
      "next": "/api/3/action/datastore_search?offset=5&limit=5&resource_id=a2368cff-1562-4dde-8466-9635ea3a572a"
    },
    "total": 23
  }
}

Field Reference

success Indicates whether the API request was successful.

Implementation Example

Calls a real endpoint of this API. Replace any placeholder credentials with your own key.

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.

How This API Fails

We deliberately sent this API a broken request and recorded exactly what came back on 2026-08-10. Knowing the shape of an error before you hit it makes error handling much easier to write.

HTTP 404 Requesting a path that does not exist text/html

Returned an HTML error page rather than JSON — worth knowing if your client assumes every response can be parsed as JSON.

HTTP 404 Sending an invalid value for "resource_id" application/json
{
  "help": "https://data.renfe.com/api/3/action/help_show?name=datastore_search",
  "success": false,
  "error": {
    "message": "No encontrado: Resource \"!!!invalid!!!\" was not found.",
    "__type": "Not Found Error"
  }
}

Common Errors & Troubleshooting

Generated guidance based on this API's documentation, not observed by us. Treat it as a starting point and check against the provider's own error reference.

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.

Measured Score Breakdown

Live HTTP request to the API endpoint

Speed 15/30
Consistency 20/20
Security 14/20
Browser access 0/15
Transparency 4/15
Endpoint Response Time 245ms

Fully tested on Aug 10, 2026

Technical Specifications

Auth No Auth
HTTPS REQUIRED
CORS UNKNOWN
Category Transportation
Difficulty Beginner
Endpoint last called: 2026-08-10

Related Tags

Similar APIs

View All →