Bank Al-Maghrib Exchange Rate API: Official MAD Rates as JSON

Reviewed by Madhushan, Fintech Developer — August 2026

The Bank Al-Maghrib publishes the official exchange rates that accounting, tax, and customs practice in Morocco reference — published official rates, not moving market prices. This guide shows how to pull them as JSON: via a REST endpoint or the zero-dependency bank-al-maghrib-exchange-rate npm package.

The cours de référence, machine-readable

Bank Al-Maghrib publishes daily cours de référence for the dirham — the benchmark Moroccan accounting, customs and contracts cite under the managed-float regime. The bank’s own portal serves them as a CSV export behind the rates page, and the API serves the same numbers as clean JSON: a published mid rate since 2017, and the buying/selling pairs the bank published before that.

Why official rates, not market rates

A live mid-market feed answers "what is USD/MAD trading at right now?" — the right tool for checkouts and dashboards. But accountants, auditors, and tax authorities ask a different question: "which rate were you required to use for this date?" That answer comes from the Bank Al-Maghrib’s published rates, and it never changes after publication.

Get the latest rates (REST)

curl "https://allratestoday.com/api/v1/central-bank/bam/latest" \
  -H "Authorization: Bearer YOUR_API_KEY"

The response is the bank's most recent published table — every rate and the publication date. The latest rates are available on every plan, including the free tier (300 requests/month, no credit card).

The npm SDK

npm install bank-al-maghrib-exchange-rate
import { getRate, getLatestRates } from 'bank-al-maghrib-exchange-rate';

// One pair at the official rate
const pair = await getRate('USD', 'MAD', { apiKey: 'art_live_...' });
console.log(pair.rate, pair.rate_date);

// The bank's full published table
const table = await getLatestRates({ apiKey: 'art_live_...' });
console.log(table.rate_date, table.rates.length);

Zero dependencies, TypeScript types included, and it runs anywhere fetch exists — Node 18+, Bun, Deno, and edge runtimes.

Historical rates for an invoice date

import { getRatesForDate, getHistory } from 'bank-al-maghrib-exchange-rate';

const day = await getRatesForDate('2026-08-18', { apiKey: 'art_live_...' });

const series = await getHistory(
  { source: 'USD', target: 'MAD', from: '2026-01-01' },
  { apiKey: 'art_live_...' }
);

Historical dates and time series need a paid plan; the latest rates stay free.

Published vs derived pairs

If the Bank Al-Maghrib does not print a pair directly, the API resolves it from the bank's published rates — an inverse, or a cross via MAD — and flags it derived: true with the method used. Official and computed values are never silently mixed, which is exactly the distinction an auditor will ask about.

The archive

The archive reaches back to January 2000 — buy/sell pairs through 2016, the published mid rate from 2017 on, through the 2020 band-widening steps of Morocco’s gradual float.

FAQ

Does the Bank Al-Maghrib have an official exchange rate API?

The bank publishes its official rates on its own site, and AllRatesToday serves the same published rates as clean JSON via REST or the bank-al-maghrib-exchange-rate npm package. The latest table is free.

How do I get the official Morocco exchange rate for a past date?

The rates-for-date endpoint returns the official table for any archived date; non-publication days resolve to the most recent published date and are flagged, so audit trails stay honest. Historical dates require a paid plan; latest rates are free.

Does the API serve the official mid rate or buy/sell?

Both, era-appropriately: since 2017 Bank Al-Maghrib publishes a mid (Moyen) reference rate, served as rate_type "reference"; the pre-2017 archive carries the buying and selling quotes the bank published then.

Official Bank Al-Maghrib rates, as JSON

The latest rates are free — 300 requests/month, no credit card.

Get your free API key

Related Articles