API đang hoạt động · Yêu cầu API Key

Giá Vàng API

API RESTful cung cấp dữ liệu giá vàng Việt Nam theo thời gian thực từ các thương hiệu SJC, PNJ, DOJI, Phú Quý, Mi Hồng tại Hà Nội, TP.HCM, Đà Nẵng, Cần Thơ.

Base URL: https://tygiavang24h.com/api.php

Cấu trúc response

{
  "success":   true,
  "version":   "v1",
  "timestamp": "2026-05-14T10:30:00+07:00",
  "data":      { ... }
}

Đơn vị giá

Tất cả giá buy / sell tính bằng VND / lượng (1 lượng = 37.5g). Ví dụ: 165000000 = 165 triệu đồng.

Xác thực

Mọi request đều yêu cầu API key. Truyền key qua query string hoặc header:

Qua query string

GET /api.php?v=1&endpoint=prices&api_key=tvg_your_key_here

Qua HTTP header

GET /api.php?v=1&endpoint=prices
X-Api-Key: tvg_your_key_here
⚠️ Giữ API key bí mật. Không commit key vào source code công khai. Nếu key bị lộ, liên hệ api@tygiavang24h.com để revoke và cấp key mới.

Chưa có API key? 🔑 Đăng ký miễn phí →

Rate Limit

Free
1 request / ngày
Data hôm nay
Tất cả brands & cities
Miễn phí mãi mãi
Pro
Không giới hạn request
Lịch sử 30 ngày+
Ưu tiên hỗ trợ
SLA uptime 99.9%

Khi vượt giới hạn, server trả 429 Too Many Requests:

{
  "success": false,
  "error": {
    "code":    429,
    "message": "Rate limit exceeded. Free tier: 1 request/day."
  },
  "docs": "https://tygiavang24h.com/api-docs.html"
}

Lỗi

CodeMô tả
400Request không hợp lệ (sai tham số)
401Thiếu hoặc API key không hợp lệ
429Vượt rate limit
503Không kết nối được BigQuery
{
  "success": false,
  "error":   { "code": 401, "message": "API key không hợp lệ. Đăng ký tại tygiavang24h.com/api-register.php" },
  "docs":    "https://tygiavang24h.com/api-docs.html"
}

GET /prices

Lấy toàn bộ bảng giá vàng hiện tại. Hỗ trợ filter theo brand, city, loại vàng.

GET https://tygiavang24h.com/api.php?v=1&endpoint=prices FREE

Query Parameters

Tham sốKiểuMô tả
api_keybắt buộcAPI key của bạn
vbắt buộcPhiên bản API. Hiện tại: 1
endpointbắt buộcprices
brandtuỳ chọnLọc theo thương hiệu: SJC, DOJI, PNJ, Phú Quý, Mi Hồng
citytuỳ chọnLọc theo khu vực: Hà Nội, Hồ Chí Minh, Đà Nẵng, Cần Thơ
qtuỳ chọnTìm theo tên loại vàng (ví dụ: nhẫn, SJC 1L)
limittuỳ chọnSố dòng trả về (mặc định: 100, tối đa: 500)
formattuỳ chọnjson (mặc định) hoặc csv

Response

{
  "success": true,
  "data": {
    "data": [
      {
        "brand":      "SJC",
        "city":       "Hồ Chí Minh",
        "gold_type":  "Vàng SJC 1L, 10L, 1KG",
        "buy":        162000000,
        "sell":       165000000,
        "buy_diff":   0,
        "sell_diff":  500000,
        "updated_at": "10:25:18"
      }
    ],
    "total":      63,
    "updated_at": "10:25 14/05/2026",
    "source":     "TyGiaVang24h.com"
  }
}

GET /latest

Lấy giá mới nhất, đã dedup — mỗi loại vàng chỉ xuất hiện 1 lần.

GET https://tygiavang24h.com/api.php?v=1&endpoint=latest FREE

Query Parameters

Tham sốKiểuMô tả
api_keybắt buộcAPI key của bạn
brandtuỳ chọnLọc theo thương hiệu
citytuỳ chọnLọc theo khu vực

Ví dụ

GET /api.php?v=1&endpoint=latest&brand=PNJ&city=Hồ Chí Minh&api_key=tvg_xxx

GET /summary

Tóm tắt thị trường: giá cao/thấp, spread trung bình, số loại tăng/giảm.

GET https://tygiavang24h.com/api.php?v=1&endpoint=summary FREE
{
  "data": {
    "sjc_sell_max":   165000000,
    "sjc_buy_min":    162000000,
    "avg_spread_sjc": 3000000,
    "count_up":       12,
    "count_down":     3,
    "count_flat":     48,
    "total_items":    63,
    "brands":         ["DOJI","Mi Hồng","PNJ","Phú Quý","SJC"],
    "cities":         ["Cần Thơ","Đà Nẵng","Hà Nội","Hồ Chí Minh"],
    "updated_at":     "10:25 14/05/2026"
  }
}

GET /brands

Danh sách thương hiệu, khu vực, loại vàng hiện có trong hệ thống.

GET https://tygiavang24h.com/api.php?v=1&endpoint=brands FREE
{
  "data": {
    "brands":     ["DOJI","Mi Hồng","PNJ","Phú Quý","SJC"],
    "cities":     ["Cần Thơ","Đà Nẵng","Hà Nội","Hồ Chí Minh"],
    "gold_types": ["Vàng SJC 1L, 10L, 1KG","Nhẫn Trơn PNJ 999.9","AVPL - Bán Lẻ","..."],
    "updated_at": "10:25 14/05/2026"
  }
}

Ví dụ: JavaScript

const API_KEY = 'tvg_your_key_here';

// Lấy giá vàng SJC tại TP.HCM
const res = await fetch(
  `https://tygiavang24h.com/api.php?v=1&endpoint=prices&brand=SJC&city=Hồ Chí Minh&api_key=${API_KEY}`
);
const { data } = await res.json();

data.data.forEach(item => {
  console.log(`${item.gold_type}: ${item.sell.toLocaleString('vi-VN')}₫`);
});
import axios from 'axios';

const { data } = await axios.get('https://tygiavang24h.com/api.php', {
  params: { v: '1', endpoint: 'prices', brand: 'PNJ', api_key: 'tvg_your_key_here' }
});

data.data.data.forEach(item => {
  console.log(`${item.gold_type}: ${item.sell.toLocaleString('vi-VN')}₫`);
});

Ví dụ: Python

import requests

API_KEY = 'tvg_your_key_here'

r = requests.get('https://tygiavang24h.com/api.php', params={
    'v':        '1',
    'endpoint': 'prices',
    'brand':    'DOJI',
    'api_key':  API_KEY,
    'limit':    10
})
data = r.json()

for item in data['data']['data']:
    print(f"{item['brand']} - {item['gold_type']}: {item['sell']:,}₫")

Ví dụ: PHP

$apiKey = 'tvg_your_key_here';
$url    = "https://tygiavang24h.com/api.php?v=1&endpoint=summary&api_key={$apiKey}";
$res    = file_get_contents($url);
$data   = json_decode($res, true);

echo "Spread TB SJC: " . number_format($data['data']['data']['avg_spread_sjc']) . "₫";
echo "Tổng loại: "     . $data['data']['data']['total_items'];

Ví dụ: Google Apps Script

const API_KEY = 'tvg_your_key_here';

function getGoldPrices() {
  const url  = `https://tygiavang24h.com/api.php?v=1&endpoint=prices&brand=SJC&api_key=${API_KEY}`;
  const res  = UrlFetchApp.fetch(url);
  const data = JSON.parse(res.getContentText());

  data.data.data.forEach(item => {
    Logger.log(`${item.gold_type}: ${item.sell}`);
  });
}

function getGoldSummary() {
  const url  = `https://tygiavang24h.com/api.php?v=1&endpoint=summary&api_key=${API_KEY}`;
  const res  = UrlFetchApp.fetch(url);
  const json = JSON.parse(res.getContentText());
  Logger.log('Spread TB SJC: ' + json.data.data.avg_spread_sjc);
}