# SHANGHAI METRO API

{% hint style="info" %}
This API script is designed to retrieve information from the airport info database using provided parameters. The script constructs the appropriate URL based on the parameters provided and then fetches data from the API. Please follow the instructions below to use this script effectively
{% endhint %}

## Usage

1. Making a HTTP request via a web browser or API Platform etc. Postman.
2. The following parameters are accepted:

| Name            | Description                                                | Format                                                                                                                                                                                                           |
| --------------- | ---------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| departure\_id   | To specific desired departure station id                   | • Station ID. Etc. **0926**                                                                                                                                                                                      |
| destination\_id | To specific desired destination station id                 | • Station ID. Etc. **0737**                                                                                                                                                                                      |
| ticket          | To specific desired ticket type                            | <p>• ‘<strong>0</strong>’ for metro-card</p><p>• ‘<strong>1</strong>’ for one-way ticket</p>                                                                                                                     |
| day             | To specific desired day                                    | <p>•‘<strong>MONTOTHUR\_0</strong>’ for Monday to Thursday</p><p>•‘<strong>FRIDAY\_0</strong>’ for Friday</p><p>•‘<strong>SATURDAY\_0</strong>’ for Saturday</p><p>•‘<strong>WEEKEND\_0</strong>’ for Sunday</p> |
| time            | To specific desired time to enter or leave metro in second | <p>• Time to enter or leave metro in second. Etc. 22:44 = ((22\*60) +44) \*60)</p><p>= <strong>82740</strong></p>                                                                                                |
| line            | To specific desired line number                            | • Line number. Etc. **1**                                                                                                                                                                                        |
| stat\_id        | To specific desired station id                             | • Station ID. Etc. **0926**                                                                                                                                                                                      |
| stat\_name      | To specific desired station name                           | • Station Name. Etc. **JiuTing**                                                                                                                                                                                 |
| download        | To download the JSON output                                | • This parameter does not require the content, **Leave empty** or **Type anything** is acceptable                                                                                                                |

3. Depending on the parameters provided, the script will construct a URL to fetch information from Shanghai-Metro API

## Parameter Guidelines

* **`departure_id`** Parameter:
  * If you provide a valid `departure_id` parameter of departure station etc. '**0926**', the script will retrieve information of selected departure station id.
* **`destination_id`** Parameter:
  * If you provide a valid `destination_id` parameter of destination station etc. '**0737**', the script will retrieve information of selected destination station id.
* **`ticket`** Parameter:
  * If you provide a valid `ticket` parameter as '**0**' or '**1**', the script will retrieve information of selected ticket.
* **`day`** Parameter:
  * If you provide a valid `day` parameter as '**MONTOTHUR\_0**', '**FRIDAY\_0**', '**SATURDAY\_0**' or '**WEEKEND\_0’**, the script will retrieve information of selected day.
* **`time`** Parameter:
  * If you provide a valid `time`parameter of entering or arriving metro etc. '**82740**', the script will retrieve information of selected time.
* **`line`** Parameter:
  * If you provide a `line`parameter of metro line etc. '**1'**, the script will retrieve information of selected line.
* **`stat_id`** Parameter:
  * If you provide a `stat_id`parameter of station etc. '**0926**', the script will retrieve information of selected station id.
* **`stat_name`** Parameter:
  * If you provide a valid `stat_name` parameter of station etc. '**JiuTing**', the script will retrieve information of selected station name.
* **`download`** Parameter:
  * If you want to download the JSON output of these parameters, define the download parameter with empty or any input will able you to auto download it.

## Station ID

Refer this <https://api.kosontechnology.com/json/station-ID.json> to find your station ID.

Below is a sample how you will see station ID at 'key' value:

1. Find station name and you will see station ID at top column.

<figure><img src="/files/rpdVbFzRXOruGjPHqM7z" alt=""><figcaption><p>'1438' is LuJiaZui (陆家嘴) Station ID</p></figcaption></figure>

## API

1. Retrieve all metro line number information: [All Line Number](/shanghai-metro-api/all-line-number.md)
2. Retrieve all metro line timetable: [All Line Timetable](/shanghai-metro-api/all-line-timetable.md)
3. Retrieve last line timetable: [Last Line Timetable](/shanghai-metro-api/last-line-timetable.md)
4. Retrieve history based on metro line: [Line History](/shanghai-metro-api/line-history.md)
5. Retrieve metro line colour: [Line Colour](/shanghai-metro-api/line-colour.md)
6. Retrieve all metro station information: [All Station Information](/shanghai-metro-api/all-station-information.md)
7. Retrieve metro station based on metro line: [Search Station With Line](/shanghai-metro-api/search-station-with-line.md)
8. Retrieve metro station based on station id: [Search Station With Station ID](/shanghai-metro-api/search-station-with-station-id.md)
9. Retrieve metro station information based on station name: [Search Station With Station Name](/shanghai-metro-api/search-station-with-station-name.md)
10. Retrieve last station timetable: [Last Station Timetable](/shanghai-metro-api/last-station-timetable.md)
11. Estimate arrival time: [Estimate Arrival Time](/shanghai-metro-api/estimate-arrival-time.md)
12. Check ticket price: [Check Price](/shanghai-metro-api/check-price.md)
13. Check route: [Check Route](/shanghai-metro-api/check-route.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://api-gitbook.kosontechnology.com/shanghai-metro-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
