Skip to main content

Tổng quan

1.1. Endpoint & Variables

Các biến số dưới đây sẽ được sử dụng trong tài liệu này

Tên biếnMô tảSTAGINGPRODUCTION
AUTHORIZATION_SERVERDomain tích hợp API lấy access tokenhttps://iam-staging.gam.vnhttps://iam.gam.vn
RESOURCE_SERVERDomain tích hợp open APIhttps://gateway-staging.gam.vn/omshttps://gateway.gam.vn/oms
Tên biếnMô tả
MESSAGEThông báo trả về của API
ERROR_MESSAGEMô tả lỗi
LOG_IDLog Id cho tracing
STATUS_CODEMã HTTP status code

1.2. Xác thực,

Hệ thống sử dụng OAuth2 với grant type client_credentials để cấp quyền truy cập API. Bạn cần gọi Token Endpoint để lấy access_token, sau đó dùng token này để gọi các API nghiệp vụ.

OAuth2 Client Credentials Grant Flow

API lấy Access token

Token Endpoint

POST {AUTHORIZATION_SERVER}/oauth2/v3/token

Header

Content-Type: application/x-www-form-urlencoded

Body parameters

ParameterRequiredDescription
grant_typeYesLuôn là client_credentials.
client_idYesID của ứng dụng được cấp từ IAM.
client_secretYesSecret gắn với client_id (phải được bảo mật).
scopeYesDanh sách quyền cần cấp, phân tách bởi dấu cách. Ví dụ: iam:user-password:update gamp:erp.customer-reconciliation.write-direct.

cURL Example

curl --location '{{AUTHORIZATION_SERVER}}/oauth2/v3/token' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'grant_type=client_credentials' \
--data-urlencode 'scope=iam:user-password:update gamp:erp.customer-reconciliation.write-direct' \
--data-urlencode 'client_secret=YOUR_CLIENT_SECRET' \
--data-urlencode 'client_id=YOUR_CLIENT_ID'

Response

{
"access_token": "eyJraWQiOiJrM2F...",
"expires_in": 3600,
"token_type": "Bearer",
"scope": "iam:user-password:update gamp:erp.customer-reconciliation.write-direct"
}

Response data

Tham sốMô tả
access_tokenToken bạn sẽ dùng để gọi API.
expires_inThời gian sống của token (tính bằng giây, mặc định là 1 ngày).
token_typeLuôn là Bearer.
scopeQuyền hạn được cấp trong token.

1.3. Request format

API hỗ trợ định dạng dữ liệu là aplication/json. Các request cần set giá trị trên cho header Content-Type Khi gọi API nghiệp vụ, bạn cần gửi header Authorization kèm access_token đã nhận được

info
  • Giá trị mặc định của Content-Typeaplication/json

Example

POST /api/v1/authenticated HTTP/1.1
Host: {RESOURCE_SERVER}
X-Client-Source: `PARTNER_CODE`
Authorization: Bearer eyJraWQiOiJrM2F...

{"field1":value1,"field2":value2}

1.4. Định dạng phản hồi

Với request xác thực thất bại

HTTP/1.1 403 Forbidden Content-Type:application/json; charset=UTF-8 Content-Length: 0

Với request xác thực thành công

Content type: JSON

{
"status": "{STATUS_CODE}",
"message":"{MESSAGE}",
"timestamp": "...",
"data": "..."
}

Với request xác thực thành công nhưng gặp lỗi xử lý

Content type: JSON

{
"status": "{STATUS_CODE}",
"message": "{ERROR_MESSAGE}",
"error_code": "{ERROR_CODE}",
"timestamp": "..."
}