How to Use APIs

- Tokyo Open Data API is a service that provides some of the data on the Tokyo Metropolitan Open Data Catalog site as an API.
- You can use APIs immediately without signing up.
- The data targeted by this API is as follows for each file format among the data published on the Tokyo Metropolitan Open Data Catalog site. (as of March 2023)
File format: CSV
- Data published on the Tokyo Metropolitan Open Data Catalog site
File format: Excel
- Data of each Tokyo metropolitan government office etc. published on the Tokyo Metropolitan Open Data Catalog site

In order to use this site comfortably, the following environment is recommended.
* Even when using under the recommended environment, visual and functional problems may occur depending on the combination of OS and browser, and browser settings.
- OS
- Windows 10 or later
- Mac OS X 10.15 Catalina or later
- Recommended browsers (Windows)
- Microsoft Edge (latest version)
- Google Chrome (latest version)
- Firefox (latest version)
- Recommended browsers (Mac OS)
- Microsoft Edge (latest version)
- Google Chrome (latest version)
- Firefox (latest version)
- Safari (latest version)

- Decide which API to use
- Check API's search conditions
- Below is how to use API screen:
- The information of the API's request parameters (search conditions).
- You can try the API by clicking the button.
- Response example.
- Below is how to see the screen when you try API:
- You can modify the API request parameters (search conditions).
- Executes a trial of the API based on the request parameters set in A.
- Clears the result.
- Displays the curl command and the request URL of the tried request.
- Displays the result of the tried request (with blue background).
- Get API's request URL
- Execute API
- Acquiring data in JSON format
- Acquiring data in XML format
Search an API you wish to use from Search APIs screen. Keyword search and filtering search by category are available.
When you find the API you want to use, click the API name to move to the details.
Check the search conditions, etc. of the API to be used from the details screen. You can also try out the API.

Click "Try It Out" button to start trying the API.

Get the request URL displayed on the response screen after trying the API.

Below is a sample code for executing the API.
As an example, here is the procedure for obtaining data in JSON format for the year 2021, using 'Number of New Positives for New COVID-19 Infection in Tokyo (apiId:t000001d0000000011-819fb24a2e74a5f2ea848d548c5cff7d-0)'.
Since this data consists of one record for one day, specify 365 for limit when acquiring data for one year (365 days).
You can also narrow down the items you want to acquire with column. If column is not specified, the items are not narrowed down.
Below is an example of getting data with curl.
curl -X 'POST' \
'https://service.api.metro.tokyo.lg.jp/api/t000001d0000000011-819fb24a2e74a5f2ea848d548c5cff7d-0/json?limit=365' \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-d '{
"column": [
"公表_年月日","日別陽性者数","7日間合計陽性者数","7日間平均陽性者数"
],
"searchCondition": {
"conditionRelationship": "and",
"dateAndSearch": [
{
"column": "公表_年月日",
"relationship": "ge",
"condition": "2021/1/1"
},
{
"column": "公表_年月日",
"relationship": "le",
"condition": "2021/12/31"
}
]
}
}'
And the corresponding response looks like this:
{
"total": 365,
"subtotal": 365,
"limit":365,
"offset":null,
"metadata": {
"apiId": "t000001d0000000011-819fb24a2e74a5f2ea848d548c5cff7d-0",
"title": "東京都 新型コロナウイルス感染症新規陽性者数 東京都 新型コロナウイルス感染症新規陽性者数",
"datasetId": "t000001d0000000011",
"datasetTitle": "東京都 新型コロナウイルス感染症新規陽性者数",
"datasetDesc": "東京都 新型コロナウイルス対策サイト https://stopcovid19.metro.tokyo.lg.jp/ で公開している新規陽性者数です。(接触歴等不明者数は2020年3月27日から、増加比は2020年4月9日から掲載)",
"dataTitle": "東京都 新型コロナウイルス感染症新規陽性者数",
"dataDesc": "東京都 新型コロナウイルス対策サイト https://stopcovid19.metro.tokyo.lg.jp/ で公開している新規陽性者数です。(接触歴等不明者数は2020年3月27日から、増加比は2020年4月9日から掲載)※ システムの仕様上、下記では1000recordsと表示されておりますが、実際には1000件以上となっております。",
"sheetname": "",
"version": "1.0.7",
"created": "2022/9/15 15:06",
"updated": ""
},
"hits": [
{
"row": 348,
"公表_年月日": "2021-01-01",
"日別陽性者数": 793,
"7日間合計陽性者数": "6129",
"7日間平均陽性者数": "875.6"
},
{
"row": 349,
"公表_年月日": "2021-01-02",
"日別陽性者数": 829,
"7日間合計陽性者数": "6004",
"7日間平均陽性者数": "857.7"
},
{
"row": 350,
"公表_年月日": "2021-01-03",
"日別陽性者数": 826,
"7日間合計陽性者数": "6122",
"7日間平均陽性者数": "874.6"
},
{
"row": 351,
"公表_年月日": "2021-01-04",
"日別陽性者数": 905,
"7日間合計陽性者数": "6536",
"7日間平均陽性者数": "933.7"
},
...
]
}
You can also receive the response in XML format. It can be obtained with Shift JIS when in XML format if the API supports it. However, the request data must be encoded in UTF-8.
Below is an example of getting data with curl in XML format.
curl -X 'POST' \
'https://service.api.metro.tokyo.lg.jp/api/t000001d0000000011-819fb24a2e74a5f2ea848d548c5cff7d-0/xml?encoding=utf-8&limit=365' \
-H 'accept: application/xml' \
-H 'Content-Type: application/json' \
-d '{
"column": [
"公表_年月日","日別陽性者数","7日間合計陽性者数","7日間平均陽性者数"
],
"searchCondition": {
"conditionRelationship": "and",
"dateAndSearch": [
{
"column": "公表_年月日",
"relationship": "ge",
"condition": "2021/1/1"
},
{
"column": "公表_年月日",
"relationship": "le",
"condition": "2021/12/31"
}
]
}
}'
And the corresponding response looks like this:
<?xml version="1.0" encoding="UTF-8"?>
<result>
<total>365</total>
<subtotal>365</subtotal>
<limit>365</limit>
<offset></offset>
<metadata>
<apiId>t000001d0000000011-819fb24a2e74a5f2ea848d548c5cff7d-0</apiId>
<title>東京都 新型コロナウイルス感染症新規陽性者数 東京都 新型コロナウイルス感染症新規陽性者数</title>
<datasetId>t000001d0000000011</datasetId>
<datasetTitle>東京都 新型コロナウイルス感染症新規陽性者数</datasetTitle>
<datasetDesc>東京都 新型コロナウイルス対策サイト https://stopcovid19.metro.tokyo.lg.jp/ で公開している新規陽性者数です。(接触歴等不明者数は2020年3月27日から、増加比は2020年4月9日から掲載)</datasetDesc>
<dataTitle>東京都 新型コロナウイルス感染症新規陽性者数</dataTitle>
<dataDesc>東京都 新型コロナウイルス対策サイト https://stopcovid19.metro.tokyo.lg.jp/ で公開している新規陽性者数です。(接触歴等不明者数は2020年3月27日から、増加比は2020年4月9日から掲載)※ システムの仕様上、下記では1000recordsと表示されておりますが、実際には1000件以上となっております。</dataDesc>
<sheetname></sheetname>
<version>1.0.7</version>
<created>2022/9/15 15:06</created>
<updated></updated>
</metadata>
<hits>
<item>
<prop>
<rownum>348</rownum>
<key>公表_年月日</key>
<value>2021-01-01</value>
</prop>
<prop>
<rownum>348</rownum>
<key>日別陽性者数</key>
<value>793</value>
</prop>
<prop>
<rownum>348</rownum>
<key>7日間合計陽性者数</key>
<value>6129</value>
</prop>
<prop>
<rownum>348</rownum>
<key>7日間平均陽性者数</key>
<value>875.6</value>
</prop>
</item>
<item>
<prop>
<rownum>349</rownum>
<key>公表_年月日</key>
<value>2021-01-02</value>
</prop>
<prop>
<rownum>349</rownum>
<key>日別陽性者数</key>
<value>829</value>
</prop>
<prop>
<rownum>349</rownum>
<key>7日間合計陽性者数</key>
<value>6004</value>
</prop>
<prop>
<rownum>349</rownum>
<key>7日間平均陽性者数</key>
<value>857.7</value>
</prop>
</item>
<item>
<prop>
<rownum>350</rownum>
<key>公表_年月日</key>
<value>2021-01-03</value>
</prop>
<prop>
<rownum>350</rownum>
<key>日別陽性者数</key>
<value>826</value>
</prop>
<prop>
<rownum>350</rownum>
<key>7日間合計陽性者数</key>
<value>6122</value>
</prop>
<prop>
<rownum>350</rownum>
<key>7日間平均陽性者数</key>
<value>874.6</value>
</prop>
</item>
<item>
<prop>
<rownum>351</rownum>
<key>公表_年月日</key>
<value>2021-01-04</value>
</prop>
<prop>
<rownum>351</rownum>
<key>日別陽性者数</key>
<value>905</value>
</prop>
<prop>
<rownum>351</rownum>
<key>7日間合計陽性者数</key>
<value>6536</value>
</prop>
<prop>
<rownum>351</rownum>
<key>7日間平均陽性者数</key>
<value>933.7</value>
</prop>
</item>
...
</hits>
</result>