# Sweden Road Incidents & Train Delays – Trafikverket (`madeform/trafikverket-disruptions`) Actor

Get live road incidents, roadworks, ferry changes, rail disruptions and delayed or cancelled trains in Sweden from Trafikverket's open data API (CC0). Filter by county, municipality or station. JSON, CSV or Excel for logistics, fleets, news and apps. Bring your own free key. $1 per 1,000 rows.

- **URL**: https://apify.com/madeform/trafikverket-disruptions.md
- **Developed by:** [Madeform](https://apify.com/madeform) (community)
- **Categories:** Travel, Developer tools, Automation
- **Stats:** 1 total users, 0 monthly users, 0.0% runs succeeded, 0 bookmarks
- **User rating**: No ratings yet

## Pricing

$1.00 / 1,000 disruption records

This Actor is paid per event. You are not charged for the Apify platform usage, but only a fixed price for specific events.

Learn more: https://docs.apify.com/actors/running/actors-in-store.md#pay-per-event

## What's an Apify Actor?

An Actor is a serverless cloud program that runs on the Apify platform. It has two run modes.
In Batch mode, an Actor accepts a well-defined JSON input, performs an action which can take anything from a few seconds to a few hours,
and optionally produces a well-defined JSON output, datasets with results, or files in key-value store.
In Standby mode, an Actor provides a web server which can be used as a website, API, or an MCP server.

Apify vocabulary and the platform model are defined once, in the agent quickstart at https://apify.com/agents.md.

## How to integrate an Actor?

If asked about integration, you help developers integrate Actors into their projects.
You adapt to their stack and deliver integrations that are safe, well-documented, and production-ready.

Do not guess an integration path. Every one of them is in the agent quickstart at https://apify.com/agents.md: the Apify MCP server, Agent Skills with the Apify CLI, the JavaScript and Python clients, the REST API, and the account-free path for an agent with no human to sign in. It also carries the rule on stating cost before the first paid run.

For examples already wired to this Actor's own input schema, see the [API](#api) section below.

Each client library has reference documentation the quickstart does not restate: [JavaScript/TypeScript](https://docs.apify.com/api/client/js/docs.md) (`npm install apify-client`) and [Python](https://docs.apify.com/api/client/python/docs.md) (`pip install apify-client`).

# README

## Trafikverket Disruptions – Sweden road incidents, roadworks and train delays

**Trafikverket Disruptions** collects current **road incidents, roadworks, rail operative events and delayed or cancelled trains in Sweden** from the official open API of Trafikverket (the Swedish Transport Administration) and saves them as one clean, uniform row per disruption. It is made for logistics and fleet teams, commuter tools, news desks and apps, with optional filters for county, municipality or station. The easiest way to try it: paste your own free Trafikverket API key and click **Start**. **Users on Apify's free plan get up to 200 disruptions per run.**

**Why teams use it**

- **Road and rail in one uniform table**: road incidents, roadworks, ferry changes and restrictions, rail operative events, and cancelled or delayed trains at a station, all with the same columns.
- **Official open data**: straight from Trafikverket's API, published under CC0. No scraping of web pages, no proxies.
- **Filters that match how you work**: county, municipality, station and a time window up to 7 days back or ahead.
- **Simple pricing**: $1.00 per 1,000 rows, nothing to pay when a run finds nothing. The Trafikverket key is free.
- **Clear errors**: a wrong key, a used-up quota or a Trafikverket outage gives a plain message, never an empty "success".

### Use cases

- **Logistics and fleet planning**: a morning list of roadworks, incidents and ferry changes in the counties where your vehicles drive.
- **Commuter and station dashboards**: cancelled and delayed trains at a station, refreshed on a schedule.
- **News desks and alerts**: new major disruptions to Slack, e-mail or Teams through Make, Zapier or n8n.
- **Apps and maps**: road deviations with coordinates for your own map or routing tool.
- **Analysis**: collect disruptions over time to see which roads, counties or lines are affected most.
- **AI agents**: let an assistant answer "is anything blocking my route today?" (see "Use it with AI agents" below).

### Example: a morning list of roadworks and incidents in your county

A transport team in Västra Götaland wants a list every morning of roadworks, road incidents and ferry changes that can affect the day's routes. They set `type` to `road`, `countyNo` to `14`, `hoursAhead` to 24, schedule the Actor for early morning and send the rows to a spreadsheet or another tool through an integration. A second team runs `rail` with `stationSignature` `Cst` and `includeTrainAnnouncements` to see cancelled and delayed trains at Stockholm Central.

### You need your own free API key

Trafikverket's API needs an API key in every request (the limit is 100 calls per second per key, and Trafikverket contacts users who exceed the limits). This Actor's rule is that each user brings their own free key.

1. Register at [data.trafikverket.se/get-started](https://data.trafikverket.se/get-started) with your e-mail address and accept the licence. A key is created for you.
2. Paste the key in the input field **Trafikverket API key** (`trafikverketApiKey`). The field is required and stored as a secret.

The key is your own and is never shared between users. Without a key the run stops with a clear error and a link to the registration. If you run the code locally (outside the Apify platform) you can set the environment variable `TRAFIKVERKET_API_KEY` instead; it is ignored on the platform.

If a run fails, the run status in Apify Console shows why and what to do: missing key, key rejected by Trafikverket (HTTP 401), key denied (HTTP 403), request quota reached (HTTP 429), Trafikverket temporarily unavailable, or no connection. The message never contains your key or Trafikverket's raw response.

### How to use Trafikverket Disruptions

1. Get your free key at [data.trafikverket.se/get-started](https://data.trafikverket.se/get-started) and paste it in **Trafikverket API key**.
2. Choose `type`: `road`, `rail` or `both`, and optionally a county, a municipality text or a station signature.
3. Set the time window (`hoursBack`, `hoursAhead`) and `maxResults`, then click **Start**.
4. Open the **Output** tab to view the rows as a table, or download them as JSON, CSV or Excel, or read them through the Apify API.
5. Optional: create a schedule so the Actor runs every morning (see below).

### What you get

| `recordType` | Source (Trafikverket object) | One row is |
|---|---|---|
| `road-deviation` | `Road.TrafficInfo` / `Situation` 1.6 | one deviation (incident, roadwork, restriction) |
| `rail-operative-event` | `ols.open` / `OperativeEvent` 1.0 | one operative event with traffic impact on the railway |
| `train-announcement` | `rail.trafficinfo` / `TrainAnnouncement` 2.0 | one cancelled or delayed departure/arrival at your station |

Note: Trafikverket retired the `TrainMessage` dataset on 9 September 2025 and replaced it with `OperativeEvent` and `RailwayEvent` in the `ols.open` namespace ([announcement](https://data.trafikverket.se/news/datacache/disposal-of-the-trainmessage-dataset---api-open-data)). This Actor uses `OperativeEvent` for rail disruptions.

### Input

| Field | Description |
|---|---|
| `type` | `rail`, `road` or `both` (default). |
| `countyNo` | Optional list of counties (official numbers, e.g. 1 Stockholm, 14 Västra Götaland, 25 Norrbotten). Empty means all of Sweden. |
| `municipality` | Optional text. Trafikverket has no municipality field, so this is a case-insensitive text match against the (sanitised) `location`, `title` and `description` of each row, for example `Sundsvall`. Rows that never name the municipality are not returned. |
| `stationSignature` | Optional station signature, e.g. `Cst`. Rail events are kept when their affected section includes the station. |
| `includeTrainAnnouncements` | Default `false`. Needs `stationSignature`; adds cancelled and delayed departures and arrivals at that station. |
| `hoursBack` / `hoursAhead` | Time window, default 0 and 24 hours (maximum 168). |
| `maxResults` | 1–10,000, default 200. Free plan: at most 200 per run. With `both`, road rows are saved first, so use a higher value or run `rail` separately if you need rail rows too. |
| `trafikverketApiKey` | Your Trafikverket key (secret, required). |

Road deviations that Trafikverket marks as suspended (inactive) and deleted objects are skipped.

### Example output

These rows come from real test runs on 28 October 2026 (road run `7bFikBIb4usQXPZgJ`, rail and train run `J08Ta0xQ5BBNMkPYE` with station `Cst`). Values are exactly as Trafikverket published them at that time. The table shows the most important columns.

| recordType | id | category | title | severity | startTime | endTime | countyNo | roadNumber / location | delayMinutes | canceled |
|---|---|---|---|---|---|---|---|---|---|---|
| road-deviation | SE_STA_TRISSID_1_1160220 | Färjor | Isöleden | Mycket stor påverkan | 2026-10-29T06:00:00Z | 2026-10-29T19:30:00Z | 23 | Väg 623 | null | null |
| road-deviation | SE_STA_TRISSID_1_6736542 | Vägarbete | null | Liten påverkan | 2025-02-02T23:00:00Z | 2026-11-19T15:00:00Z | 25 | E45 | null | null |
| rail-operative-event | O261027-023 | Banarbete/transport (Vid överskriden tid eller annat oförutsett) | Banarbete Södertälje syd–Gnesta | green | 2026-10-27T08:26:38.003Z | null | 1, 2 | Cst – Ksc | null | null |
| train-announcement | 1500adde-1c5d-5c23-08df-29aad2244acd | arrival | Delayed 52 min arrival: train 591 at Cst | null | null | null | – | Cst | 52 | false |
| train-announcement | 1500adde-1c5d-5c23-08df-29aabc79e5a1 | arrival | Cancelled arrival: train 166 at Cst | null | null | null | – | Cst | null | true |

One row of each main type as JSON:

```json
{
  "recordType": "road-deviation",
  "id": "SE_STA_TRISSID_1_1160220",
  "category": "Färjor",
  "messageType": "Färja",
  "title": "Isöleden",
  "description": "Färjan är inställd torsdagen den 29/10 kl 20:00 till 20:30 på grund av bunkring.",
  "severity": "Mycket stor påverkan",
  "startTime": "2026-10-29T06:00:00Z",
  "endTime": "2026-10-29T19:30:00Z",
  "countyNo": [
    23
  ],
  "roadNumber": "Väg 623",
  "location": "Väg 623 mellan Isön och Norderön Ö, i båda riktningar.",
  "fromStation": null,
  "toStation": null,
  "trainIdent": null,
  "advertisedTime": null,
  "estimatedTime": null,
  "canceled": null,
  "delayMinutes": null,
  "operator": null,
  "latitude": 63.1376661364807,
  "longitude": 14.3936920273737,
  "lastModified": "2026-10-26T14:49:56.345Z",
  "sourceUrl": "http://www.trafikverket.se/isoleden",
  "source": "Trafikverket – Swedish Transport Administration, open API (CC0), https://data.trafikverket.se",
  "retrievedAt": "2026-10-28T08:45:57.066Z"
}
```

```json
{
  "recordType": "rail-operative-event",
  "id": "O261027-023",
  "category": "Banarbete/transport (Vid överskriden tid eller annat oförutsett)",
  "messageType": "16",
  "title": "Banarbete Södertälje syd–Gnesta",
  "description": "Från 6 november kl. 22:00 till 8 november kl. 13:55 påverkas tågtrafiken av ett banarbete mellan Södertälje syd och Gnesta. Snabbtågen mellan Stockholm–Malmö/Göteborg/Karlstad går ändrad väg via Eskilstuna eller Västerås. Mälartåg ersätts med buss mellan Gnesta/Vagnhärad och Södertälje syd. SL Pendeltåg ersätts med buss mellan Södertälje centrum och Gnesta. Räkna med längre restid än normalt. För mer information om din resa hänvisas du till ditt tågbolag.",
  "severity": "green",
  "startTime": "2026-10-27T08:26:38.003Z",
  "endTime": null,
  "countyNo": [
    1,
    2
  ],
  "roadNumber": null,
  "location": "Cst – Ksc",
  "fromStation": "Cst",
  "toStation": "Ksc",
  "trainIdent": null,
  "advertisedTime": null,
  "estimatedTime": null,
  "canceled": null,
  "delayMinutes": null,
  "operator": null,
  "latitude": 59.12855761082926,
  "longitude": 17.60817527347914,
  "lastModified": "2026-10-27T10:00:36.212Z",
  "sourceUrl": null,
  "source": "Trafikverket – Swedish Transport Administration, open API (CC0), https://data.trafikverket.se",
  "retrievedAt": "2026-10-28T08:43:57.117Z"
}
```

```json
{
  "recordType": "train-announcement",
  "id": "1500adde-1c5d-f923-08df-29aa4224da1a",
  "category": "arrival",
  "messageType": "ANA055",
  "title": "Delayed 3 min arrival: train 925 at Cst",
  "description": "Spårändrat",
  "severity": null,
  "startTime": null,
  "endTime": null,
  "countyNo": [],
  "roadNumber": null,
  "location": "Cst",
  "fromStation": "U",
  "toStation": "Arb",
  "trainIdent": "925",
  "advertisedTime": "2026-10-28T08:46:00Z",
  "estimatedTime": "2026-10-28T08:49:00Z",
  "canceled": false,
  "delayMinutes": 3,
  "operator": "TDEV",
  "latitude": null,
  "longitude": null,
  "lastModified": "2026-10-28T08:43:52.812Z",
  "sourceUrl": null,
  "source": "Trafikverket – Swedish Transport Administration, open API (CC0), https://data.trafikverket.se",
  "retrievedAt": "2026-10-28T08:43:57.117Z"
}
```

[examples/sample-output.json](examples/sample-output.json) has a few more rows.

Fields (all rows, `null` when missing): `recordType`, `id`, `category`, `messageType`, `title`, `description` (max 500 characters), `severity`, `startTime`, `endTime`, `countyNo` (array), `roadNumber`, `location`, `fromStation`, `toStation`, `trainIdent`, `advertisedTime`, `estimatedTime`, `canceled`, `delayMinutes`, `operator`, `latitude`, `longitude`, `lastModified`, `sourceUrl`, `source`, `retrievedAt`.

Times are ISO 8601. Trafikverket's API sends times with a zone offset, and these are converted to UTC (`Z`). A time sent without a zone is read as Swedish local time and keeps the Europe/Stockholm offset (`+01:00` or `+02:00`).

### How much does it cost to get Swedish traffic disruptions?

The Actor uses pay per event pricing: **$1.00 per 1,000 disruptions** ($0.001 per saved row). One saved row equals one billed event, and a run that finds nothing costs nothing.

Example: a run that saves 1,000 disruptions costs $1.00. A run with the default maximum of 200 rows costs $0.20.

| Typical setup | Rows saved | Cost |
|---|---|---|
| One test run with the default input | up to 200 | up to $0.20 |
| A morning run for one county that saves 50 rows, every day | about 1,500 a month | about $1.50 a month |
| A station check that saves 20 trains, every hour | about 14,400 a month | about $14.40 a month |
| One run of 10,000 rows | 10,000 | $10.00 |

The rows per run in these examples are assumptions; the real number depends on traffic that day. You pay only for the rows that are saved, and you can cap the cost of any run with **Maximum cost per run** in the run options.

**Free plan:** users on Apify's free plan get at most **200 disruptions per run**. For plans and platform credits, see [Apify pricing](https://apify.com/pricing). The Trafikverket API key is free and not part of the Actor price.

### Schedule it and connect it

- **Schedule:** run the Actor every morning or every few hours with [Apify schedules](https://docs.apify.com/platform/schedules).
- **API:** start runs and read the dataset through the Apify API.
- **Integrations:** send new rows to other tools through [Apify integrations](https://docs.apify.com/platform/integrations), for example [Make](https://docs.apify.com/platform/integrations/make), [Zapier](https://docs.apify.com/platform/integrations/zapier), [n8n](https://docs.apify.com/platform/integrations/n8n) or [Slack](https://docs.apify.com/platform/integrations/slack).
- **Google Sheets:** use the Actor [Google Sheets Import & Export](https://apify.com/lukaskrivka/google-sheets) to write the dataset to a spreadsheet.
- **Export:** download the dataset as JSON, CSV or Excel.

### Use it from your code: cURL, Python and JavaScript

You can start Trafikverket Disruptions and read the results through the [Apify API](https://docs.apify.com/api/v2). Get your API token in Apify Console under [Settings → API & Integrations](https://console.apify.com/settings/integrations) and set it as the environment variable `APIFY_TOKEN`. Put your own Trafikverket key in the environment variable `TRAFIKVERKET_API_KEY` too, so it never ends up in your code. The snippets below were run against this Actor on 28 October 2026.

**cURL**: start a run, wait for it and get the rows in one request. The synchronous endpoint waits up to 5 minutes, so use it for small and medium runs.

```bash
curl -X POST "https://api.apify.com/v2/acts/madeform~trafikverket-disruptions/run-sync-get-dataset-items" \
  -H "Authorization: Bearer $APIFY_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"type":"road","countyNo":["1"],"maxResults":20,"trafikverketApiKey":"'"$TRAFIKVERKET_API_KEY"'"}'
```

**Python** (`pip install apify-client`, tested with version 3.4):

```python
import os
from apify_client import ApifyClient

client = ApifyClient(os.environ["APIFY_TOKEN"])
run = client.actor("madeform/trafikverket-disruptions").call(run_input={
    "type": "rail",
    "stationSignature": "Cst",
    "includeTrainAnnouncements": True,
    "maxResults": 50,
    "trafikverketApiKey": os.environ["TRAFIKVERKET_API_KEY"],
})
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item["recordType"], item["title"], item["location"], item["delayMinutes"])
```

With apify-client 1.x or 2.x, `call()` returns a dict: use `run["defaultDatasetId"]` instead of `run.default_dataset_id`.

**JavaScript / TypeScript** (`npm install apify-client`, tested with version 2.25):

```javascript
import { ApifyClient } from 'apify-client';

const client = new ApifyClient({ token: process.env.APIFY_TOKEN });
const run = await client.actor('madeform/trafikverket-disruptions').call({
    type: 'road',
    countyNo: ['14'],
    maxResults: 50,
    trafikverketApiKey: process.env.TRAFIKVERKET_API_KEY,
});
const { items } = await client.dataset(run.defaultDatasetId).listItems();
for (const item of items) console.log(item.recordType, item.category, item.location, item.startTime);
```

The **API** tab on this Actor's page has more examples and the full OpenAPI definition.

### Use it with AI agents (MCP)

Trafikverket Disruptions also works as a tool for AI assistants and agents through the [Apify MCP server](https://docs.apify.com/platform/integrations/mcp). Add this server URL to Claude, Cursor, VS Code or any other MCP client, and sign in with your Apify account when asked:

```text
https://mcp.apify.com?tools=madeform/trafikverket-disruptions
```

Then ask in plain language, for example: *"Are there any roadworks or incidents on the E4 in Stockholm county right now? List them with location, severity and end time."* The agent fills in the input (`type`, `countyNo`, `municipality`, `stationSignature`, `hoursAhead`, `maxResults`), runs the Actor and reads the rows. Agent runs are billed exactly like normal runs, one event per saved row. The Actor needs your own Trafikverket key in `trafikverketApiKey`; an agent can only pass it on if you give it to the agent, so treat it like any other secret.

### FAQ

#### Is it legal to use Trafikverket data?

Trafikverket publishes the information in its open API for traffic information under Creative Commons CC0, which requires no attribution. See "Data source and licence" below. You are responsible for how you use the output.

#### How up to date is the data?

Every run fetches the data live from Trafikverket's API. The Actor keeps no archive of its own, and you can look back at most 168 hours with `hoursBack`. Each row has `lastModified` (from Trafikverket) and `retrievedAt` (when the Actor fetched it).

#### What is covered, and what are the limits?

Road deviations (incidents, roadworks, ferries and other restrictions), rail operative events with traffic impact, and, for one station at a time, cancelled or delayed train announcements. With `type` set to `both`, road rows are saved first, so a low `maxResults` can leave out rail rows. Road deviations that Trafikverket marks as suspended are skipped. There is no historical archive beyond `hoursBack` of 168 hours.

#### Why do I need my own API key?

Trafikverket's API requires a key in every request and limits calls per key (100 per second). Each user brings their own free key, which is stored as a secret and never shared. Register at [data.trafikverket.se/get-started](https://data.trafikverket.se/get-started).

#### Does the data contain personal data?

Public traffic information rarely does. The Actor requests only a fixed list of fields and removes e-mail addresses, telephone numbers and personal identity numbers from free text. The scrubbing is pattern based and can miss unusual wording. See "Minimised personal data" below.

#### Can I filter by municipality or station?

Yes. `municipality` is a text match, because Trafikverket has no municipality field. `stationSignature` limits rail events to those whose affected section includes the station and, with `includeTrainAnnouncements`, adds cancelled and delayed trains at that station.

#### Can I connect it to Google Sheets, Make or Zapier?

Yes. See "Schedule it and connect it" above. You can also use the Apify API.

#### What happens on the free plan?

You get up to 200 disruptions per run. Paid usage costs $1.00 per 1,000 disruptions.

#### Is this an official Trafikverket service?

No. It is an independent tool that reads Trafikverket's open API with your own key and turns the answers into uniform rows. The data is Trafikverket's, published under CC0.

#### Can I get new disruptions in Slack or by e-mail?

Yes. Schedule the Actor and connect the run to Slack, e-mail, Make, Zapier or n8n through [Apify integrations](https://docs.apify.com/platform/integrations).

#### Can I use it from my own code or an AI agent?

Yes. See "Use it from your code" and "Use it with AI agents (MCP)" above.

### Minimised personal data

- The Actor asks the API only for a fixed whitelist of fields. Creator, images, journey references and other fields are never requested.
- Free text (`title`, `description`, `location`) is scrubbed of e-mail addresses (including obfuscated forms), telephone numbers and Nordic personal identity numbers, and of names after words such as "contact person" or "kontaktperson". Removed parts are replaced by `[removed]`. The text scrubbing is pattern based and can miss unusual wording.

Notices in public traffic information rarely hold personal data, but you remain the controller for your use of the output. Check your legal basis and retention period.

Data storage: Apify stores datasets in AWS us-east-1 (USA) under Apify's [Data Processing Addendum](https://docs.apify.com/legal/data-processing-addendum) with Standard Contractual Clauses (SCC); see Apify's [shared responsibility model](https://docs.apify.com/security/shared-responsibility). If you need to keep the data in the EU, export it and delete the dataset after the run.

### Data source and licence

Source: Trafikverket – Swedish Transport Administration, open API for traffic information, [data.trafikverket.se](https://data.trafikverket.se). The information is licensed under [Creative Commons CC0](https://creativecommons.org/publicdomain/zero/1.0/) ("The information contained in the Swedish Transport Administration's open API for traffic information is licensed under Creative Commons CC0"). CC0 requires no attribution; the Actor states the source in every row (`source`) as good practice. Each row's `retrievedAt` gives the retrieval time.

Each user runs the Actor with their own free key. That is this Actor's rule, not a literal requirement in Trafikverket's terms. Trafikverket's documentation says that each request carries the user's unique key, that the limit is [100 calls per second per key](https://data.trafikverket.se/documentation/datacache/the-response), and that Trafikverket monitors the traffic of each service and contacts users who exceed the limits.

Free text is shortened to 500 characters and scrubbed as described above, so it can differ from the original.

This Actor is an independent tool. It is not affiliated with, endorsed by or operated by Trafikverket or the Swedish Transport Administration.

### More from Madeform

- [TED Europe Tenders](https://apify.com/madeform/ted-europe-tenders) – public tenders from all 30 EU/EEA countries, same fields and filters, $3.00 per 1,000 tenders.
- [TED Nordic Tenders](https://apify.com/madeform/ted-nordic-tenders) – tenders from Sweden, Norway, Denmark, Finland and Iceland only, with Sweden as the default, $3.00 per 1,000 tenders.

# Actor input Schema

## `trafikverketApiKey` (type: `string`):

Required. Your own free Trafikverket API key, stored encrypted as a secret and never logged. Get one in a few minutes at <a href="https://data.trafikverket.se/get-started" target="_blank">data.trafikverket.se/get-started</a>.

## `type` (type: `string`):

Which disruptions to collect: road (incidents, roadworks, ferries), rail (operative events) or both. With both, road rows are saved first.

## `countyNo` (type: `array`):

Optional. Only disruptions in these counties (official county numbers), for example 14 for Västra Götaland. Empty means all of Sweden. Not applied to train announcements.

## `municipality` (type: `string`):

Optional. Trafikverket has no municipality field, so this is a case-insensitive text match against the location, title and description of each disruption, for example: Sundsvall.

## `stationSignature` (type: `string`):

Optional. Trafikverket station signature, for example: Cst (Stockholm Central). Limits rail events to those whose affected section includes the station. Required for train announcements.

## `includeTrainAnnouncements` (type: `boolean`):

Also fetch cancelled or delayed departures and arrivals at the station. Requires a station signature.

## `hoursBack` (type: `integer`):

Include disruptions that ended, and trains advertised, up to this many hours ago (0–168). Default 0 means only current ones.

## `hoursAhead` (type: `integer`):

Include disruptions that start, and trains advertised, up to this many hours ahead (0–168). Default 24.

## `maxResults` (type: `integer`):

Maximum number of disruptions to save (1–10,000). Each saved row is one billed event. Users on Apify's free plan get at most 200 per run.

## Actor input object example

```json
{
  "type": "both",
  "countyNo": [
    "1",
    "14"
  ],
  "municipality": "Sundsvall",
  "stationSignature": "Cst",
  "includeTrainAnnouncements": false,
  "hoursBack": 0,
  "hoursAhead": 24,
  "maxResults": 200
}
```

# Actor output Schema

## `results` (type: `string`):

Swedish road deviations, rail operative events and delayed or cancelled trains, one row per disruption, in the run's default dataset.

# API

You can run this Actor programmatically using our API. Below are code examples in JavaScript, Python, and CLI, as well as the OpenAPI specification and MCP server setup.

## JavaScript example

```javascript
import { ApifyClient } from 'apify-client';

// Initialize the ApifyClient with your Apify API token
// Replace the '<YOUR_API_TOKEN>' with your token
const client = new ApifyClient({
    token: '<YOUR_API_TOKEN>',
});

// Prepare Actor input
const input = {};

// Run the Actor and wait for it to finish
const run = await client.actor("madeform/trafikverket-disruptions").call(input);

// Fetch and print Actor results from the run's dataset (if any)
console.log('Results from dataset');
console.log(`💾 Check your data here: https://console.apify.com/storage/datasets/${run.defaultDatasetId}`);
const { items } = await client.dataset(run.defaultDatasetId).listItems();
items.forEach((item) => {
    console.dir(item);
});

// 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/js/docs

```

## Python example

```python
from apify_client import ApifyClient

# Initialize the ApifyClient with your Apify API token
# Replace '<YOUR_API_TOKEN>' with your token.
client = ApifyClient("<YOUR_API_TOKEN>")

# Prepare the Actor input
run_input = {}

# Run the Actor and wait for it to finish
run = client.actor("madeform/trafikverket-disruptions").call(run_input=run_input)

# Fetch and print Actor results from the run's dataset (if there are any)
print(f"💾 Check your data here: https://console.apify.com/storage/datasets/{run.default_dataset_id}")
for item in client.dataset(run.default_dataset_id).iterate_items():
    print(item)

# 📚 Want to learn more 📖? Go to → https://docs.apify.com/api/client/python/docs/quick-start

```

## CLI example

```bash
echo '{}' |
apify call madeform/trafikverket-disruptions --silent --output-dataset

```

## MCP server setup

```json
{
    "mcpServers": {
        "apify": {
            "type": "http",
            "url": "https://mcp.apify.com/?tools=fetch-actor-details,madeform/trafikverket-disruptions"
        }
    }
}
```

The hosted server signs you in with OAuth on first connect, so no API token belongs in this config. Clients without OAuth support can send an `Authorization: Bearer <APIFY_API_TOKEN>` header instead, using a token from API & Integrations in Apify Console (https://console.apify.com/settings/integrations).

## OpenAPI specification

Download the OpenAPI definition: https://api.apify.com/v2/actors/bTxecf2JA85G2lbb6/builds/9N32sYwf7SDQDaaHx/openapi.json
