Most UAE finance teams start with someone copying the Central Bank of the UAE (CBUAE) rate table into the ERP by hand. Then that person goes on holiday, three days of invoices go out on a stale rate, and someone asks for "a script".
The script is easy. The parts that matter are when it runs, what it does on days without a new table, and how it tells you it's broken. Here's a version that handles all three.
What the CBUAE table is
- More than 70 currencies against the dirham, as dirhams per one unit of foreign currency.
- Mid rates, based on FX rates prevailing at 6pm UAE time.
- Updated Monday to Friday. There is no Saturday or Sunday table.
- No API from the bank: it's a web page plus monthly download files.
The table is what UAE VAT points to for foreign-currency invoices (Article 69: the Central Bank rate on the date of supply), so it's the rate most UAE ERPs need loaded.
When to run
The 6pm rates don't appear instantly. In the AllRatesToday feed the new CBUAE table usually arrives around 19:15 UAE time (15:15 UTC). So schedule the job for 20:00 Asia/Dubai, Monday to Friday, and give it one retry at 22:00.
# m h dom mon dow command (server in Asia/Dubai)
0 20 * * 1-5 /opt/fx/cbuae_sync.py
0 22 * * 1-5 /opt/fx/cbuae_sync.py
Running it twice is fine because the job is idempotent (below).
The job
#!/usr/bin/env python3
import os, sys, datetime as dt, requests
KEY = os.environ["ALLRATES_KEY"]
WANT = {"USD", "EUR", "GBP", "INR", "SAR", "CNY", "PKR"}
def fetch_latest():
r = requests.get(
"https://allratestoday.com/api/v1/central-bank/cbuae/latest",
headers={"Authorization": f"Bearer {KEY}"},
timeout=15,
)
r.raise_for_status()
return r.json()
def main():
table = fetch_latest()
rate_date = table["rate_date"]
today = dt.date.today().isoformat()
if rate_date != today:
# No new table yet (or a day the bank didn't update).
# Do NOT write anything: the ERP keeps the last official table.
print(f"latest CBUAE table is {rate_date}, not {today}; nothing loaded")
sys.exit(0)
rows = {r["base"]: r["value"] for r in table["rates"] if r["base"] in WANT}
# Sanity checks before touching the ERP.
if abs(rows.get("USD", 0) - 3.6725) > 1e-6:
sys.exit(f"USD/AED is {rows.get('USD')}, expected 3.6725; refusing to load")
missing = WANT - rows.keys()
if missing:
sys.exit(f"missing currencies {sorted(missing)}; refusing to load")
for ccy, value in sorted(rows.items()):
erp_upsert_rate(ccy, "AED", rate_date, value) # keyed on (ccy, date)
print(f"loaded {len(rows)} CBUAE rates for {rate_date}")
def erp_upsert_rate(src, tgt, date, value):
... # your ERP's API: Odoo res.currency.rate, ERPNext Currency Exchange, etc.
if __name__ == "__main__":
main()
The decisions baked into it
Upsert keyed on (currency, date). Running twice, or re-running after a fix, can't create duplicates.
If there's no new table, write nothing. The naive version copies the latest table onto today's date. Don't: that makes it look as if CBUAE printed a rate it didn't. Leave the gap and let the ERP use the most recent table, which is what it does anyway when a date has no rate. Your records then show the true table date for every invoice.
The peg check. USD/AED has been 3.6725 since 1997. If the job ever sees anything else, a column got mixed up or the response changed, and loading it would poison every dollar invoice. It costs one line.
Exit non-zero on failure. Cron mail, a systemd OnFailure= unit or your monitoring picks up the non-zero exit. A silent failure here goes unnoticed until month-end.
Weekends and backdated invoices
Weekend supplies have no table of their own. When someone raises an invoice dated Saturday, the ERP will use the latest rate on or before that date, which is Friday's table. Most teams are happy with that, but write it into your VAT policy so it's a decision, not an accident.
For invoices backdated beyond what's in the ERP, use the dated endpoint (paid plans) instead of the latest one. It tells you which table it actually used:
curl -H "Authorization: Bearer YOUR_KEY" \
"https://allratestoday.com/api/v1/central-bank/cbuae/2026-11-21?source=EUR&target=AED"
# requested_date 2026-11-21 (a Saturday), rate_date 2026-11-20,
# published_on_requested_date: false
published_on_requested_date: false is the flag to store with the invoice when the rate came from an earlier day.
Before you switch it on
Run it for a week next to the manual process and compare. If the two disagree, check the direction first: CBUAE quotes dirhams per unit of foreign currency (EUR → AED 4.018053 on 25 November 2026), and some ERPs want the inverse.
The latest CBUAE table is free with an API key (register, no card). Endpoint details and the npm package are on the CBUAE exchange rate API page.
Top comments (0)