Dokumentasi API Harga Emas
API spot emas Malaysia untuk integrator dan laman hargaemas. Halaman ini hanya dokumentasi endpoint pengguna yang selamat.
Kontrak fasa 2: kekal GET /prices (tiada /v2/prices). Medan neutral (spotSellRmPerKg, dll.) adalah utama. Respons awam tidak mengandungi source atau nama pembekal spot.
Fasa 2 — Apa yang berubah
- ✓Medan neutral — guna
spotBuyRmPerKg/spotSellRmPerKg(RM/kg), bukan nama teknikal lama. - ✓Privasi sumber —
sourcedansourceLabeltidak dihantar padaGET /prices. - ✓API key baharu — format
hrgms_<publicId>_<secret>; format key lama masih sah semasa peralihan. - ✓Legacy sunset — medan nama lama boleh dibuang selepas tarikh sunset (header
Deprecation/Sunsetsemasa masih aktif). - ✓Pelanggan berdaftar —
spotPreferenceper API key (ditetapkan oleh admin); respons tetap tanpa dedahan sumber spot.
Authentication (hrgms)
Gunakan API key untuk production. Hantar dalam header — jangan letak key dalam URL query.
# .env — laman / app pelanggan
HRGMS_API_URL=https://api.hargaemas.my
HRGMS_API_KEY=hrgms_<publicId>_<secret>
Authorization: Bearer $HRGMS_API_KEY
# atau
X-API-Key: $HRGMS_API_KEY
Contoh token baharu: hrgms_a1b2c3d4e5f60708_<64 hex secret>. Format key lama masih diterima sehingga semua client rotate.
Endpoint pengguna
| Method | Path | Deskripsi | Auth |
|---|---|---|---|
GET |
/prices |
Bundle spot: medan neutral; lastUpdate, isStale, staleAgeMinutes. Tiada source spot. |
API key (production) |
GET |
/selling-price |
Harga jual spot sahaja: { "price": number } (daripada spotSellRmPerKg). |
API key (production) |
GET |
/api/rahnu/v1/history |
Sejarah Ar-Rahnu: query source, from, to, limit. |
Wajib API key |
GET |
/api/invest/v1/latest |
Harga jual/beli platform pelaburan emas (RM/g). Query optional id. |
Awam (production: INVEST_REQUIRE_API_KEY=1) |
GET |
/api/merchant/v1/latest |
Harga kedai emas (jual / beli / trade-in, RM/g). Query optional shop, category, purity. |
Awam (production: MERCHANT_REQUIRE_API_KEY=1) |
Contoh: /prices
curl -s "$HRGMS_API_URL/prices" \
-H "Authorization: Bearer $HRGMS_API_KEY"
{
"prices": {
"spotSellRmPerKg": 582115.79,
"spotBuyRmPerKg": 576508.77,
"taelSellRm": 22002.46,
"silverSellRmPerKg": 11190.66
},
"lastUpdate": "2026-05-29 19:47:47",
"isStale": false,
"staleAgeMinutes": 0
}
Semak tiada source: jq 'has("source")' → false.
Contoh: Ar-Rahnu
curl -s "$HRGMS_API_URL/api/rahnu/v1/history?source=yapeim&limit=30" \
-H "X-API-Key: $HRGMS_API_KEY"
{
"source": "yapeim",
"rows": [ { "date": "2026-06-01", "harga_999": 510.00 } ]
}
source di sini = id operator Ar-Rahnu (bukan kilang spot).
Contoh: /api/invest/v1/latest
curl -s "$HRGMS_API_URL/api/invest/v1/latest"
{
"unit": "RM/g",
"ok": 14,
"total": 14,
"platforms": [
{ "id": "meem", "label": "MEEM Gold", "buyRmPerG": 609, "sellRmPerG": 564, "ok": true }
]
}
Tapis satu platform: ?id=meem. Respons tidak termasuk URL scrape dalaman.
Contoh: /api/merchant/v1/latest
curl -s "$HRGMS_API_URL/api/merchant/v1/latest"
{
"unit": "RM/g",
"ok": 33,
"total": 33,
"shops": [
{ "id": "fitrah-gold", "label": "Fitrah Gold", "category": "merchant", "location": "Cheras", "negeri": "Wilayah Persekutuan Kuala Lumpur", "purity": "916", "sellRmPerG": 520, "buyRmPerG": 510, "tradeInRmPerG": 505, "ok": true }
]
}
Tapis: ?shop=fitrah-gold · ?category=merchant|supplier|buyback · ?purity=916. Respons tidak termasuk URL scrape dalaman.
Medan harga spot (neutral)
Integrasi baharu: guna medan di bawah sahaja.
| Field | Unit |
|---|---|
spotBuyRmPerKg | RM/kg |
spotSellRmPerKg | RM/kg |
taelBuyRm | RM |
taelSellRm | RM |
silverBuyRmPerKg | RM/kg |
silverSellRmPerKg | RM/kg |
usdMyrBuy | USD/MYR |
usdMyrSell | USD/MYR |
Pelanggan berdaftar
Dengan API key hrgms_, admin boleh tetapkan spotPreference untuk client — respons kekal harga spot neutral tanpa dedahan sumber kepada pengunjung.
Hanya pelanggan dengan key sah; pengunjung awam hanya nampak harga spot agregat.