Public
Documentation Settings

API by MTREC

This Postman collection provides information about the types of APIs and acts as a quick user guide for using our API service.
Please contact us if you have any questions.

Rate Limiting

Our API employs rate limiting to control the volume of requests to the server within a specified time frame. This helps mitigate malicious bot activity and reduces strain on the backend infrastructure.

Details:

  • Queries Per Second (QPS): The maximum allowed QPS is 1 request per second, or equivalently, 10 requests per 10 seconds from same IP Address.

  • Exceeding Rate Limit: If the rate limit is exceeded, the server will respond with an HTTP 429 Too Many Requests status code, along with a JSON response containing the following information:

    • Your IP address

    • Total number of requests made in the last 10 seconds

  • Rate Limit Reset: The rate limit is reset every 10 seconds.

GETTrain Active Status

https://api.mtrec.name.my/api/servicestatus

The API endpoint shows the numbers of trains which are active and put into service based on the crowdsourced data from MTREC Spotters.

Example Request
curl
curl --location 'https://api.mtrec.name.my/api/spottersstatus'
200 OK
Example Response
json
{
  "Timestamp": "2024-12-08 13:23:43",
  "IP_Address": "54.86.50.139",
  "Status": 200,
  "Data": [
    {
      "line": "AGSPL",
      "Not_Spotted": "23",
      "In_Service": "27",
      "Decommissioned": "0"
    },
    {
      "line": "DMU",
      "Not_Spotted": "12",
      "In_Service": "1",
      "Decommissioned": "0"
    },
    {
      "line": "ERL",
      "Not_Spotted": "1",
      "In_Service": "17",
      "Decommissioned": "0"
    },
    {
      "line": "ETS",
      "Not_Spotted": "24",
      "In_Service": "5",
      "Decommissioned": "5"
    },
    {
      "line": "KGL",
      "Not_Spotted": "14",
      "In_Service": "41",
      "Decommissioned": "3"
    },
    {
      "line": "KJL",
      "Not_Spotted": "52",
      "In_Service": "26",
      "Decommissioned": "19"
    },
    {
      "line": "Komuter",
      "Not_Spotted": "37",
      "In_Service": "10",
      "Decommissioned": "17"
    },
    {
      "line": "Locomotive",
      "Not_Spotted": "44",
      "In_Service": "10",
      "Decommissioned": "44"
    },
    {
      "line": "MRL",
      "Not_Spotted": "3",
      "In_Service": "6",
      "Decommissioned": "15"
    },
    {
      "line": "PYL",
      "Not_Spotted": "14",
      "In_Service": "35",
      "Decommissioned": "0"
    },
    {
      "line": "SAL",
      "Not_Spotted": "22",
      "In_Service": "0",
      "Decommissioned": "0"
    }
  ]
}
Date

Sun, 08 Dec 2024 05:23:43 GMT

Content-Type

application/json

Transfer-Encoding

chunked

Connection

keep-alive

access-control-allow-origin

*

strict-transport-security

max-age=0; includeSubDomains; preload

CF-Cache-Status

DYNAMIC

Report-To

{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=do646X7%2BebZTswPbocbucpCNYdTvgx3hhrtXjXvR268TeBmMklCZpEtexbc8qDYtkpdp%2FmLU5rRDrjjANAtjMPjV6n%2Fw1bo8HJQisixQqVSo5ITgTypikmBnMxuZ3F9ot0ETJQ%3D%3D"}],"group":"cf-nel","max_age":604800}

NEL

{"success_fraction":0,"report_to":"cf-nel","max_age":604800}

X-Content-Type-Options

nosniff

Server

cloudflare

CF-RAY

8eea53344d75c59b-IAD

Content-Encoding

br

alt-svc

h3=":443"; ma=86400

server-timing

cfL4;desc="?proto=TCP&rtt=2055&min_rtt=2017&rtt_var=784&sent=3&recv=5&lost=0&retrans=0&sent_bytes=219&recv_bytes=983&delivery_rate=717897&cwnd=238&unsent_bytes=0&cid=92bd14e4dcf6f783&ts=564&x=0"

GETKlang Valley Train Service Status

https://api.mtrec.name.my/api/servicestatus

This API endpoint shows the real-time train service status as well as service updates operated by RapidKL and Express Rail Link (ERL).

Example Request
curl
curl --location 'https://api.mtrec.name.my/api/servicestatus'
200 OK
Example Response
json
{
  "Timestamp": "2024-12-08 13:21:00",
  "Status": 200,
  "IP_Address": "54.86.50.139",
  "Data": [
    {
      "LineID": "SPL",
      "Line": "LRT Sri Petaling Line",
      "Line_Colour": "76232f",
      "Remark": "",
      "Status": "Normal Service",
      "Status_Colour": "rgba(0, 122, 51, 1)"
    },
    {
      "LineID": "AGL",
      "Line": "LRT Ampang Line",
      "Line_Colour": "e57200",
      "Remark": "",
      "Status": "Normal Service",
      "Status_Colour": "rgba(0, 122, 51, 1)"
    },
    {
      "LineID": "KJL",
      "Line": "LRT Kelana Jaya Line",
      "Line_Colour": "D50032",
      "Remark": "",
      "Status": "Normal Service",
      "Status_Colour": "rgba(0, 122, 51, 1)"
    },
    {
      "LineID": "MRL",
      "Line": "KL Monorail Line",
      "Line_Colour": "84bd00",
      "Remark": "",
      "Status": "Normal Service",
      "Status_Colour": "rgba(0, 122, 51, 1)"
    },
    {
      "LineID": "KGL",
      "Line": "MRT Kajang Line",
      "Line_Colour": "047940",
      "Remark": "",
      "Status": "Normal Service",
      "Status_Colour": "rgba(0, 122, 51, 1)"
    },
    {
      "LineID": "PYL",
      "Line": "MRT Putrajaya Line",
      "Line_Colour": "FFCD00",
      "Remark": "",
      "Status": "Normal Service",
      "Status_Colour": "rgba(0, 122, 51, 1)"
    },
    {
      "LineID": "ERL",
      "Line": "KLIA Ekspres / Transit",
      "Line_Colour": "941c71",
      "Remark": "",
      "Status": "Normal Service",
      "Status_Colour": "rgba(0, 122, 51, 1)"
    }
  ]
}
Date

Sun, 08 Dec 2024 05:21:01 GMT

Content-Type

application/json; charset=UTF-8

Transfer-Encoding

chunked

Connection

keep-alive

access-control-allow-origin

*

strict-transport-security

max-age=0; includeSubDomains; preload

CF-Cache-Status

DYNAMIC

Report-To

{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=Lc%2BfXMCbgdu%2Bej62hH8p5wznXaTL0ncyNDRS5Ts9uHAjlXRHYIGVs2RXF5nwqK5BeH6nLzmUMnZecHm8J%2FFIvibhVlevFQYZFoE21mUHTTpDLMNhh8z4u6pBqzOMUBD%2F2h%2BcsA%3D%3D"}],"group":"cf-nel","max_age":604800}

NEL

{"success_fraction":0,"report_to":"cf-nel","max_age":604800}

X-Content-Type-Options

nosniff

Server

cloudflare

CF-RAY

8eea4f39ed1cc98d-IAD

Content-Encoding

br

alt-svc

h3=":443"; ma=86400

server-timing

cfL4;desc="?proto=TCP&rtt=2208&min_rtt=2085&rtt_var=870&sent=3&recv=5&lost=0&retrans=0&sent_bytes=219&recv_bytes=982&delivery_rate=694484&cwnd=250&unsent_bytes=0&cid=2fa2df8f98f10a81&ts=554&x=0"

GETTrain Live Position

https://api.mtrec.name.my/api/position?agency=ktmb

This API endpoint shows the current train position of the rail operator. Only KTM Berhad is available for now.
Credit to : https://developer.data.gov.my/realtime-api/gtfs-realtime

PARAMS
agency

ktmb

Train Operator , currently only KTM Berhad live feed is available through GTFS-R

Example Request
curl
curl --location 'https://api.mtrec.name.my/api/position?agency=ktmb'
200 OK
Example Response
json
{
  "IP_Address": "54.86.50.139",
  "status": 200,
  "message": "Request successful",
  "timestamp": 1733635503,
  "data": [
    {
      "trip": {
        "tripId": "weekend_2334"
      },
      "position": {
        "latitude": 3.202283,
        "longitude": 101.588264,
        "bearing": 0,
        "speed": 21
      },
      "timestamp": "1733635483",
      "vehicle": {
        "id": "weekend_2334",
        "label": "SCS21"
      }
    },
    {
      "trip": {
        "tripId": "2964"
      },
      "position": {
        "latitude": 5.768763,
        "longitude": 100.49462,
        "bearing": 0,
        "speed": 81
      },
      "timestamp": "1733635478",
      "vehicle": {
        "id": "2964",
        "label": "SCS10"
      }
    },
    {
      "trip": {
        "tripId": "weekend_2343"
      },
      "position": {
        "latitude": 3.685803,
        "longitude": 101.51685,
        "bearing": 0,
        "speed": 0
      },
      "timestamp": "1733635477",
      "vehicle": {
        "id": "weekend_2343",
        "label": "SCS17"
      }
    },
    {
      "trip": {
        "tripId": "2963"
      },
      "position": {
        "latitude": 6.084542,
        "longitude": 100.37738,
        "bearing": 0,
        "speed": 117
      },
      "timestamp": "1733635476",
      "vehicle": {
        "id": "2963",
        "label": "SCS13"
      }
    },
    {
      "trip": {
        "tripId": "weekend_2225"
      },
      "position": {
        "latitude": 2.699357,
        "longitude": 101.962524,
        "bearing": 0,
        "speed": 85
      },
      "timestamp": "1733635490",
      "vehicle": {
        "id": "weekend_2225",
        "label": "SCS19"
      }
    },
    {
      "trip": {
        "tripId": "weekend_2339"
      },
      "position": {
        "latitude": 3.135687,
        "longitude": 101.68889,
        "bearing": 0,
        "speed": 0
      },
      "timestamp": "1733635488",
      "vehicle": {
        "id": "weekend_2339",
        "label": "SCS32"
      }
    },
    {
      "trip": {
        "tripId": "weekend_2331"
      },
      "position": {
        "latitude": 2.999787,
        "longitude": 101.39135,
        "bearing": 0,
        "speed": 10
      },
      "timestamp": "1733635486",
      "vehicle": {
        "id": "weekend_2331",
        "label": "SCS05"
      }
    },
    {
      "trip": {
        "tripId": "2909"
      },
      "position": {
        "latitude": 4.893468,
        "longitude": 100.71973,
        "bearing": 0,
        "speed": 68
      },
      "timestamp": "1733635485",
      "vehicle": {
        "id": "2909",
        "label": "EMU35"
      }
    },
    {
      "trip": {
        "tripId": "weekend_2233"
      },
      "position": {
        "latitude": 3.1763,
        "longitude": 101.685814,
        "bearing": 0,
        "speed": 21
      },
      "timestamp": "1733635469",
      "vehicle": {
        "id": "weekend_2233",
        "label": "EMU29"
      }
    },
    {
      "trip": {
        "tripId": "weekend_2229"
      },
      "position": {
        "latitude": 2.939075,
        "longitude": 101.7886,
        "bearing": 0,
        "speed": 0
      },
      "timestamp": "1733635467",
      "vehicle": {
        "id": "weekend_2229",
        "label": "SCS28"
      }
    },
    {
      "trip": {
        "tripId": "weekend_2335"
      },
      "position": {
        "latitude": 3.083622,
        "longitude": 101.59557,
        "bearing": 0,
        "speed": 39
      },
      "timestamp": "1733635417",
      "vehicle": {
        "id": "weekend_2335",
        "label": "SCS11"
      }
    },
    {
      "trip": {
        "tripId": "weekend_2342"
      },
      "position": {
        "latitude": 3.056703,
        "longitude": 101.52589,
        "bearing": 0,
        "speed": 0
      },
      "timestamp": "1733635475",
      "vehicle": {
        "id": "weekend_2342",
        "label": "SCS22"
      }
    },
    {
      "trip": {
        "tripId": "weekend_2338"
      },
      "position": {
        "latitude": 3.084125,
        "longitude": 101.63429,
        "bearing": 0,
        "speed": 35
      },
      "timestamp": "1733635475",
      "vehicle": {
        "id": "weekend_2338",
        "label": "SCS38"
      }
    },
    {
      "trip": {
        "tripId": "weekend_2228"
      },
      "position": {
        "latitude": 3.04898,
        "longitude": 101.70662,
        "bearing": 0,
        "speed": 99
      },
      "timestamp": "1733635472",
      "vehicle": {
        "id": "weekend_2228",
        "label": "SCS27"
      }
    }
  ]
}
Date

Sun, 08 Dec 2024 05:25:06 GMT

Content-Type

application/json

Transfer-Encoding

chunked

Connection

keep-alive

access-control-allow-origin

*

strict-transport-security

max-age=0; includeSubDomains; preload

CF-Cache-Status

DYNAMIC

Report-To

{"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v4?s=MJ%2Bnuk360AteSaOcv%2Ffpqjhbo%2BlMm8MP0CjCRLtZVXyXeiym4k8zner0S3ORImxbXL6YQg1WUm6u%2BEaJorGp3f6t%2BRif7Ui5IHAur%2F%2FHd%2FjXbhzSNQCQDeC0V60DMh9PLUUXxQ%3D%3D"}],"group":"cf-nel","max_age":604800}

NEL

{"success_fraction":0,"report_to":"cf-nel","max_age":604800}

X-Content-Type-Options

nosniff

Server

cloudflare

CF-RAY

8eea55357ca482c9-IAD

Content-Encoding

br

alt-svc

h3=":443"; ma=86400

server-timing

cfL4;desc="?proto=TCP&rtt=1653&min_rtt=1463&rtt_var=685&sent=3&recv=5&lost=0&retrans=0&sent_bytes=219&recv_bytes=989&delivery_rate=989747&cwnd=249&unsent_bytes=0&cid=69dc3b5811b0e1ca&ts=562&x=0"