DEV Community

allratestoday
allratestoday

Posted on Originally published at allratestoday.com

Which Exchange Rate Goes on a Customs Declaration? Building the Rate Step

Every customs declaration that carries a foreign-currency invoice needs one number the declarant does not choose: the exchange rate the customs authority of the clearance country fixed for that declaration. If you build customs filing, brokerage or freight forwarding software, that lookup sits in the middle of every entry, and getting the key wrong (the date, the country, the direction) produces a customs value that won't match what the authority computes.

This post walks through how we'd build that step: which date picks the rate, how to route by clearance country, and what to store so the entry survives a post-clearance audit. The data source in the examples is the AllRatesToday customs exchange rate API. The full guide is at allratestoday.com/docs/customs/customs-filing-software/.

1. Pick the rate by the date the law names

The invoice date and the shipping date are usually the wrong keys. Each customs law names its own date, and the rate is the one in force on that date:

  • European Union: the monthly table under Article 53 of the Union Customs Code and Article 146 of its Implementing Regulation, for the month in which the declaration is accepted.
  • United States: the rate for the date of exportation of the goods (19 CFR 159.32), not the date of entry.
  • India: the rate in force on the date the bill of entry (imports) or shipping bill (exports) is presented (Customs Act 1962, section 14).

So your entry model needs a "legal date" field that is filled per country, and that is what you pass to /api/v1/customs/{country}/{YYYY-MM-DD}. The API returns the table in force then: the latest table on or before the date. Weekends and holidays fall back to the table still in force, which is what the rules require.

2. Route by clearance country, not by authority

Your software knows the clearance country (the office of entry, or the country of the declaration). It does not need to know that Dutch customs, US CBP or the Korea Customs Service sets the table. The country endpoint takes the ISO code and answers from the right authority, and a map endpoint lists them all:

# Which authority's table applies in each clearance country (no key needed)
curl "https://allratestoday.com/api/v1/customs"
Enter fullscreen mode Exit fullscreen mode

Cache the map and refresh it weekly. A country that is not covered returns 404 with a link to request it, so your UI can fall back to a manual rate field instead of silently using a market rate.

Inside the EU, the clearance country decides, not where the importer is established: goods cleared in Rotterdam use the Dutch table, goods cleared in Hamburg the German one. Euro-area states without their own table in the API return the rule-based EU table, labelled as such.

3. The call for one declaration

A bill of entry presented in India on 24 November 2026, invoice in USD:

curl "https://allratestoday.com/api/v1/customs/IN/2026-11-24?source=USD&target=INR&type=import" \
  -H "Authorization: Bearer art_live_your_key"
Enter fullscreen mode Exit fullscreen mode
{
  "clearance_country": "IN",
  "authority": { "code": "cbic", "name": "Central Board of Indirect Taxes and Customs (CBIC)", ... },
  "bank": "cbic",
  "rate_date": "2026-11-20",
  "source": "USD",
  "target": "INR",
  "rate": 94.1,
  "rate_type": "import",
  "derived": false,
  "method": "published",
  ...
}
Enter fullscreen mode Exit fullscreen mode

The date asked for is 24 November; rate_date is 20 November because the CBIC notification issued for that date was still in force. Store rate_date, not the request date.

A fuller client that returns the rate together with the evidence to keep on the entry:

import requests

API = "https://allratestoday.com/api/v1/customs"
HEADERS = {"Authorization": "Bearer art_live_your_key"}

def declaration_rate(country, legal_date, invoice_ccy, local_ccy, direction="import"):
    """Rate for one declaration line, plus the evidence to store with the entry.

    legal_date: the date the clearance country's law names (acceptance in the EU,
    exportation in the US, bill of entry / shipping bill presentation in India).
    direction:  "import" or "export"; only two-sided tables use it.
    """
    params = {"source": invoice_ccy, "target": local_ccy}
    if direction == "export":
        params["type"] = "export"
    r = requests.get(f"{API}/{country}/{legal_date}", params=params, headers=HEADERS, timeout=10)
    r.raise_for_status()
    body = r.json()
    evidence = {
        "authority": body["authority"]["code"],
        "table_date": body["rate_date"],      # the authority's table, not today
        "rate_type": body["rate_type"],
        "derived": body["derived"],
        "method": body["method"],
        "basis": body.get("basis"),           # set when a table is built by rule
    }
    return body["rate"], evidence

rate, evidence = declaration_rate("IN", "2026-11-24", "USD", "INR")
customs_value_inr = round(18_400 * rate, 2)
Enter fullscreen mode Exit fullscreen mode

4. Import and export rates are different series

Some authorities fix a separate rate for each direction. CBIC's notification in force from 20 November 2026 sets USD at 94.10 rupees for imported goods and 92.40 for exported goods. Thai Customs, the Korea Customs Service, Iceland Revenue and Customs and the Uganda Revenue Authority also keep separate import and export series. They come back as rate_type import and export:

  • Without type, a pair resolves to the import side.
  • For an export declaration, always send type=export. Do not rely on the default.
  • Single-series tables (most EU monthly tables, Japan's weekly rate) ignore direction; the same rate values both.

5. Tables known before they apply

Many tables are fixed before their period starts. EU monthly customs tables are set from the rate of the second-last Wednesday of the previous month, Canada and Australia set tomorrow's rate the evening before, and China's monthly rate is fixed mid-month for the next.

/api/v1/customs/{country}/next (paid plans) returns that table as soon as it exists, with in_force_from. Use it to pre-load rates for declarations you will file at the start of a period. It returns 404 until the authority has set the next table, so treat that as "not yet", not as an error.

6. Amendments and mid-period changes

A few authorities revise part of a table mid-period: German, French and Belgian customs among them, plus North Macedonia and Uganda. The API applies the revision for you. A request for a date returns the table as it stood in force on that date, with every row carrying the date it was set. Re-query only if you file after a revision for a date before it, which is the case the authority's own rules govern.

7. Caching

A table does not change inside its period, so one fetch per country per period covers every declaration in it. Store each table once under (country, rate_date) from the response, and map the legal dates you looked up onto it:

tables = {}    # (country, rate_date) -> table, one copy per authority table
by_date = {}   # (country, legal_date) -> the same table object

def table_for(country, legal_date):
    key = (country, legal_date)
    if key not in by_date:
        t = requests.get(f"{API}/{country}/{legal_date}", headers=HEADERS, timeout=10).json()
        by_date[key] = tables.setdefault((country, t["rate_date"]), t)
    return by_date[key]
Enter fullscreen mode Exit fullscreen mode

An answer for a date in a closed period does not change, so it can be kept. Refresh dates inside the current period once a day, which also picks up amendments. Daily tables (Canada, Australia, South Africa, Switzerland and others) need a fetch per day; weekly and monthly tables far fewer. The response's stale flag is true if the authority is late with its next table. Show that to the user rather than filing on it unchecked.

8. What to store with each entry

  • authority code and rate_date: which table was applied.
  • rate_type: import, export, or the table's own series name.
  • derived and method: whether the pair was printed by the authority or computed from its table (an inverse or a cross through the home currency).
  • basis, when present: the US CBP and China customs tables, and the EU Article 146 tables, are built by applying the regulation to official central bank rates, and say so with "method": "rule" and the rule they follow.
  • The legal date you looked up, and the rate as returned before any rounding. Round the converted amount, not the rate.

With those fields, a post-clearance audit can re-run the lookup months later (/api/v1/customs/{country}/{date} returns the same table) and get the same value.

Files instead of JSON

If the system imports a rate file rather than calling an API, add format=csv, xml or xlsx to the same URL. File responses carry the authority in the X-Customs-Authority header. For Node.js, the customs-exchange-rates npm package wraps these calls. Past dates, /next and /all/latest need a paid plan; the latest table is on every plan.

Links

Rates are redistributed from each institution's own publication. They are reference rates for accounting, tax and compliance, not dealing quotes.

Top comments (1)

Collapse
 
hiredov profile image
Dov at HireDov •

The "legal date" field per clearance country is the detail I'd fight to keep, because invoice date is what everyone defaults to. One practical addition from the buyer side: when a landed-cost estimate is built at quote time, store the assumed rate and its date next to the supplier's quoted price. Then when the entry's official rate lands weeks later, you can show exactly how much of the landed-cost variance came from FX versus freight or duty, instead of arguing about it. Otherwise finance sees a cost overrun and nobody can say why. Do you see teams feeding the customs rate back into pre-shipment cost estimates, or does it stay a filing-only step?