- date
- entry
- 035
- topic
- integration
- rev
- —
Looking up Taiwan in UN Comtrade: code 158 is empty, and 490 isn't guaranteed to be only Taiwan
Look Taiwan up by its ISO code and the API returns an empty array, no error. Switch to 490 and there's data, but the code isn't guaranteed to be only Taiwan. Four traps, queried from the API.
The proper place for Taiwan's detailed trade figures is the customs import/export statistics published by the Customs Administration under Taiwan's Ministry of Finance (a query page on the single-window customs portal). That page asks for a CAPTCHA, and my scripts don't do CAPTCHAs, so I switched to mirror data: what other countries report to the UN as exports to Taiwan or imports from Taiwan, collected in UN Comtrade.
My first query came back as an empty array, status 200, no error. This note covers four places where a script querying Taiwan in UN Comtrade quietly gets fewer, or more, numbers than it should: Taiwan's code, what's inside 490, what an empty array means, and which reporters sit behind a cross-year sum. Trade values came from the public preview endpoint that needs no key, comtradeapi.un.org/public/v1/preview/C/A/HS (annual, HS classification; preview returns at most 500 records per query, and mine stayed below that), availability from getDA, and codes from the reference tables, all on October 13, 2026 (UTC).
Two Taiwan-related codes in the reference table
Comtrade's country table, partnerAreas.json, has two rows relevant to Taiwan (fields excerpted):
{"PartnerCode": 158, "PartnerDesc": "Taiwan, Province of China",
"PartnerCodeIsoAlpha2": "TW", "PartnerCodeIsoAlpha3": "TWN", "isGroup": false}
{"PartnerCode": 490, "PartnerDesc": "Other Asia, nes",
"partnerNote": "Other Asia, not elsewhere specified",
"PartnerCodeIsoAlpha3": "S19", "isGroup": false}
Code that maps countries by ISO code will turn TWN into 158. The same question asked with each code: Malaysia's (458) 2025 exports of HS 7213 (bars and rods of iron or non-alloy steel, hot-rolled, in irregularly wound coils; wire rod for short).
curl -s 'https://comtradeapi.un.org/public/v1/preview/C/A/HS?reporterCode=458&period=2025&partnerCode=158&cmdCode=7213&flowCode=X'
# {"elapsedTime":"0.63 secs","count":0,"data":[],"error":""}
With partnerCode=490 instead, one row: net weight 173,529,570 kg, USD 87,292,150.585.
It isn't just this query. Total 2025 exports to 158 from all reporters: 0 rows. Total imports from 158 by all reporters in 2015 and in 2024: 0 rows. The same 2025 export query against 490 returns 112 reporters. Reporters.json has no 158. (All of these are results of my queries this time.)
UN Comtrade's help article "Taiwan, Province of China trade data" says it directly: Taiwan is classified under 490, "Other Asia, not elsewhere specified", as both reporter and partner, and Taiwan's data isn't included in China's figures. I first inferred this from the size of the numbers (in 2024 China reported USD 75.18 billion of exports to 490 and the United States USD 118.73 billion of imports from it) and only found the article afterwards. Looking for the documentation first is cheaper than guessing from the data.
490 may hold other things too
The same article's next point is that trade data for territories belonging to Asia but not specified by country could also end up in 490. A separate article, "Areas not elsewhere specified", says these partners are used for low-value trade and when the partner was unknown to the reporter or wrongly assigned, sometimes to protect company information, and that the group's components vary by reporter, year and commodity.
Ranking each reporter's exports to 490 for 2023 through 2025, the top 2025 reporter was Saudi Arabia (682):
| Saudi Arabia → 490 | 2023 | 2024 | 2025 |
|---|---|---|---|
| Exports (USD) | 0.585 bn | 0.589 bn | 154.82 bn |
| Saudi exports to the world (USD) | (not queried) | 305.50 bn | 311.99 bn |
The 2025 figure is about 49.6% of Saudi Arabia's exports for the year, and HS 27 (mineral fuels) alone is USD 154.4 billion of it; the year before, the same flow was under 0.6 billion. Comtrade's data doesn't say what it is: real exports to Taiwan, goods that couldn't be assigned to a country, or a classification or reporting error. What I can say is that it adds over 150 billion dollars to the 2025 total for 490, and until that's understood it shouldn't be read as Taiwan's imports.
So rather than using the sum for 490 directly, I now look reporter by reporter; when one reporter jumps sharply in a year, I check its world total and commodity breakdown, and if that doesn't settle it, I keep the question open and compute the results both with and without it.
An empty array isn't zero
Back to wire rod. Viet Nam (704) has one row of HS 7213 exports to 490 for 2023, and empty arrays for 2024 and 2025. An empty array isn't a zero: it means "no matching records", which could be a wrong code (like 158 above), a year whose data hasn't been released, or genuinely no such trade. Write it down as 0 and your table shows a "fall to zero" that nothing supports.
To tell them apart, first check whether that reporter's dataset for the year has been released. Comtrade has a public data-availability endpoint:
curl -s 'https://comtradeapi.un.org/public/v1/getDA/C/A/HS?reporterCode=704&period=2023'
# → count 1 (Viet Nam, H6, totalRecords 537185, firstReleased 2025-04-15)
curl -s 'https://comtradeapi.un.org/public/v1/getDA/C/A/HS?reporterCode=704&period=2024'
# → {"count":0,"data":[],"error":""}
curl -s 'https://comtradeapi.un.org/public/v1/getDA/C/A/HS?reporterCode=704&period=2025'
# → {"count":0,"data":[],"error":""}
On the day of the query, no annual HS dataset for Viet Nam was available for 2024 or 2025; Malaysia's 2025 dataset was. Whether Viet Nam has submitted, or when the data will appear, this endpoint can't say; Comtrade's "Data availability" article notes that countries' data arrive at different times with no expected release date. All I can be sure of is that this query for Viet Nam's wire rod exports to 490 returned "no records" for those two years, not 0.
Fewer reporters, a different sum
Viet Nam isn't the only gap. Counting distinct reporterCode values with annual total-export records to 490 (cmdCode=TOTAL&flowCode=X&partnerCode=490), year by year, with amounts summed from primaryValue:
| Year | Reporters with records | Sum of exports (USD) |
|---|---|---|
| 2022 | 147 | 379.1 bn |
| 2023 | 145 | 330.2 bn |
| 2024 | 132 | 332.3 bn |
| 2025 | 112 | 575.3 bn |
36 reporters with records in 2023 have none in 2025, Viet Nam, the UAE, Iran, Qatar and Ukraine among them. In other words, each year's sum mixes several things: real changes in trade, which countries' data happen to be in for that year, and individual large records like Saudi Arabia's.
What I do is take the reporters with records in all three years (107 of them) and compare only those: USD 297.4, 327.7 and 575.3 billion. That step handles "who has data"; Saudi Arabia is present in all three years, so it's still included. Removing Saudi Arabia from all three years gives 296.8, 327.1 and 420.5 billion. Both versions still rise, so I won't claim the trend is entirely an artifact of collection; what I can say is that the raw sums can't be read directly as changes in Taiwan's trade. It's the same kind of warning as a trend made by a pagination cap: first make sure each year counts the same set of things.
My checklist for Comtrade now: use 490 for Taiwan, not an ISO lookup; don't write empty arrays down as 0, and check with getDA whether that year's dataset has been released; fix the reporter set before comparing years; and sort before summing, so any record that jumped sharply gets checked first, computing with and without it if it can't be settled.
If you remember one thing
In Comtrade an empty array isn't zero, and 490 isn't guaranteed to be only Taiwan. The empty array in the opening came from asking for 158 when Taiwan's code here is 490; switching to 490 gets you numbers, but they need going through reporter by reporter with the doubtful ones flagged. Mirror data comes from other countries' statistics, and it can differ from Taiwan's own in timing, valuation and coverage; it tells you which reporters have export records to 490, which isn't the same as Taiwan's official imports.
Revision history
- First published