VI | EN
Message us on Messenger
Developer resources

Add voucher — Shopee API

v2.voucher.add_voucher · call it through Quantri360 with one API key for your own accounts / assets that you connected and authorized — 360 handles request signing and refreshing the authorization you granted.

v2.voucher.add_voucher

POST/api/v2/voucher/add_voucherVia 360: POST https://partner.quantri360.com/v1/shopee/api/v2/voucher/add_voucher
Write endpoint — changes data on Shopee. The key must be created with "Allow write API calls" ticked, otherwise you get 403 write_not_allowed. Every call is logged.
Description

Tạo mã giảm giá hoặc hoàn xu cho toàn gian hàng hoặc các sản phẩm được chọn.

  • Gọi qua /v1/shopee/api/v2/voucher/add_voucher với Authorization: Bearer <key>; dùng platform_shop_id khi có nhiều shop. 360 tự gắn partner_id, shop_id, sign và access_token.
  • API GHI: thay đổi dữ liệu thật trên Shopee; cần key có quyền ghi (can_write) và gói mở module Khuyến mãi. Thay đổi cấu hình ưu đãi hoặc giá khuyến mãi người mua thấy.
  • HTTP 200 vẫn có thể có lỗi nghiệp vụ; kiểm error trước khi dùng kết quả.
  • Tổng mã sắp / đang diễn ra tối đa 1000; hiệu lực không quá 3 tháng, kết thúc sau bắt đầu ít nhất 1 giờ, bắt đầu không trước hiện tại. voucher_code chỉ gồm 0–9, A–Z hoặc a–z, tối đa 5 ký tự. min_basket_price khác 0 phải lớn hơn discount_amount.
  • Sản phẩm không trùng, phải tồn tại, trạng thái bình thường, có tồn kho và không thuộc diện cấm khuyến mãi; kiểm message về ngưỡng chất lượng ưu đãi. Giá trị giảm tối đa phải > percentage*min_basket_price*0.01 hoặc chi tiêu tối thiểu < max_price*100/percentage khi gặp voucher_max_discount_low_quality.

Request

Endpoint

POST https://partner.quantri360.com/v1/shopee/api/v2/voucher/add_voucher

Authentication & shop

NameInTypeSampleDescription
AuthorizationheaderheaderBearer q360_live_ab12cd34_…Khóa API của brand (tạo ở mục API key). Bắt buộc với mọi request. Brand suy từ key — không truyền mã brand.
platform_shop_idquerystring100001Gian hàng (lấy ở GET /v1/platforms → shops[].platform_shop_id). BẮT BUỘC khi brand có > 1 gian hàng trên nền tảng; 360 bỏ tham số này trước khi chuyển tiếp.

Request parameters

NameInTypeRequiredSampleDescription
voucher_namebodystringYesƯu đãi minh họaTên mã giảm giá.
voucher_codebodystringYesDEMO1Mã người mua nhập để sử dụng ưu đãi.
start_timebodytimestampYes1794009600Thời điểm người mua bắt đầu được nhận và dùng mã, Unix giây; chỉ sửa khi mã chưa bắt đầu.
end_timebodytimestampYes1794182400Thời điểm mã hết hiệu lực, Unix giây; sau đó người mua không được nhận hoặc sử dụng.
voucher_typebodyint32Yes1Loại mã: 1 = mã toàn gian hàng, 2 = mã cho sản phẩm.
reward_typebodyint32Yes1Loại ưu đãi: 1 = giảm số tiền cố định, 2 = giảm phần trăm, 3 = hoàn xu.
usage_quantitybodyint32Yes100Số lượt sử dụng ưu đãi.
min_basket_pricebodyfloatYes100000Chi tiêu tối thiểu để sử dụng mã.
discount_amountbodyfloatNo10000Số tiền giảm; chỉ gửi khi reward_type=1 (giảm số tiền cố định).
percentagebodyint32No10Tỷ lệ phần trăm; chỉ gửi cho giảm phần trăm (reward_type=2) hoặc hoàn xu (reward_type=3).
max_pricebodyfloatNo20000Giá trị giảm / hoàn xu tối đa; chỉ dùng với giảm phần trăm hoặc hoàn xu, 0 = không giới hạn.
display_channel_listbodyint32[]No[1]Kênh hiển thị: 1 = mọi nơi, 3 = bảng tin, 4 = phát trực tiếp; [] = ẩn.
item_id_listbodyint64[]No[100011]Danh sách mã sản phẩm áp dụng; chỉ gửi với mã cho sản phẩm (voucher_type=2).
display_start_timebodyint32No1794009600Thời điểm hiển thị mã trên trang gian hàng để người mua nhận, Unix giây; phải bỏ trống khi display_channel_list=[] (mã ẩn).

Request examples

curl -s -X POST "https://partner.quantri360.com/v1/shopee/api/v2/voucher/add_voucher" \
  -H "Authorization: Bearer $KEY" \
  -H "Content-Type: application/json" \
  -d '{"voucher_name":"Ưu đãi minh họa","voucher_code":"DEMO1","start_time":1794009600,"end_time":1794182400,"voucher_type":1,"reward_type":1,"usage_quantity":100,"min_basket_price":100000,"discount_amount":10000}'
Python
import requests

KEY = "q360_live_..."  # khóa API của brand
r = requests.post(
    "https://partner.quantri360.com/v1/shopee/api/v2/voucher/add_voucher",
    params={},
    json={
        "voucher_name": "Ưu đãi minh họa",
        "voucher_code": "DEMO1",
        "start_time": 1794009600,
        "end_time": 1794182400,
        "voucher_type": 1,
        "reward_type": 1,
        "usage_quantity": 100,
        "min_basket_price": 100000,
        "discount_amount": 10000
    },
    headers={"Authorization": f"Bearer {KEY}"},
    timeout=60,
)
print(r.status_code)
print(r.json())
Node.js
const KEY = 'q360_live_...'; // khóa API của brand
const url = new URL('https://partner.quantri360.com/v1/shopee/api/v2/voucher/add_voucher');
for (const [k, v] of Object.entries({})) url.searchParams.set(k, typeof v === 'object' ? JSON.stringify(v) : String(v));
const r = await fetch(url, {
  method: 'POST',
  headers: { Authorization: `Bearer ${KEY}`, 'Content-Type': 'application/json' },
  body: JSON.stringify({"voucher_name":"Ưu đãi minh họa","voucher_code":"DEMO1","start_time":1794009600,"end_time":1794182400,"voucher_type":1,"reward_type":1,"usage_quantity":100,"min_basket_price":100000,"discount_amount":10000}),
});
console.log(r.status, await r.json());
PHP
<?php
$key = 'q360_live_...'; // khóa API của brand
$url = 'https://partner.quantri360.com/v1/shopee/api/v2/voucher/add_voucher' . '?' . http_build_query([]);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer ' . $key, 'Content-Type: application/json']);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, '{"voucher_name":"Ưu đãi minh họa","voucher_code":"DEMO1","start_time":1794009600,"end_time":1794182400,"voucher_type":1,"reward_type":1,"usage_quantity":100,"min_basket_price":100000,"discount_amount":10000}');
$res = curl_exec($ch);
$status = curl_getinfo($ch, CURLINFO_HTTP_CODE);
curl_close($ch);
echo $status, "\n", $res;

Response

Response fields (as returned by Shopee)

Phản hồi minh họa thành công; đọc error/message trước khi dùng kết quả.

NameTypeSampleDescription
request_idstringd52ca43b277a4f9292fb8be658bfd33dMã request của Shopee để tra lỗi.
errorstringMã lỗi Shopee; rỗng = thành công.
messagestringMô tả lỗi.
responseobjectKết quả xử lý.
voucher_idint64100004Mã giảm giá.

Response sample

{
  "request_id": "demo-request",
  "error": "",
  "message": "",
  "response": {
    "voucher_id": 100004
  }
}

Shopee error codes (28)

Show
CodeMeaning
error_dataDữ liệu không tồn tại hoặc không hợp lệ cho thao tác (vd mã không có, loại yêu cầu không cho phép).
error_paramTham số sai / thiếu / sai kiểu — xem `message` để biết tham số nào.
error_serverLỗi hệ thống Shopee — thử lại sau ít phút.
error_shopGian hàng không hợp lệ — kiểm tra platform_shop_id.
voucher.voucher_min_price_errormin_basket_price khác 0 phải lớn hơn số tiền giảm cố định.
voucher.voucher_btoc_item_blocked_errorCó sản phẩm B2C của shop FBS không được thêm.
voucher.voucher_code_duplicate_errorMã giảm giá bị trùng.
voucher.voucher_code_errorMã chỉ gồm 0–9, A–Z, a–z, tối đa 5 ký tự.
voucher.voucher_coin_errorKhông được tạo mã hoàn xu.
voucher.voucher_display_channel_errorKênh hiển thị mã không hợp lệ.
voucher.voucher_end_time_errorHiệu lực mã không được quá 3 tháng.
voucher.fix_amount_low_qualtiy_errorrMức giảm chưa đạt tỷ lệ tối thiểu trong message.
voucher.voucher_item_blocked_from_promotion_errorCó sản phẩm bị cấm khuyến mãi theo quy định.
voucher.voucher_item_duplication_erroritem_id_list có sản phẩm trùng.
voucher.voucher_item_count_limit_erroritem_id_list vượt giới hạn số sản phẩm.
voucher.voucher_item_not_existCó sản phẩm trong item_id_list không tồn tại.
voucher.voucher_item_status_errorCó sản phẩm trong item_id_list không ở trạng thái bình thường.
voucher.voucher_item_stock_errorCó sản phẩm trong item_id_list hết hàng.
voucher.voucher_max_discount_low_qualityCần tăng mức giảm tối đa hoặc giảm chi tiêu tối thiểu để người mua hưởng đúng tỷ lệ giảm; xem message.
voucher.voucher_over_limitTối đa 1000 mã đang / sắp diễn ra.
voucher.percentage_low_quality_errorPhần trăm giảm chưa đạt ngưỡng tối thiểu trong message.
voucher.voucher_start_time_errorBắt đầu không được trước hiện tại.
voucher.voucher_time_period_errorKết thúc phải sau bắt đầu ít nhất 1 giờ.
error_authỦy quyền gian hàng cho 360 đã hết hạn hoặc bị thu hồi (360 đã tự làm mới token một lần) — chủ gian hàng kết nối lại Shopee trong Partner.
error_limitChạm hạn mức gọi Shopee trong ngày của kết nối — 360 trả kèm thời điểm thử lại; giảm tần suất gọi.
error_rate_limitGọi quá nhanh — chờ vài giây rồi gọi lại (360 cũng giới hạn theo key: 429 + Retry-After).
shop_bannedGian hàng đang bị Shopee khóa — mọi API tạm ngưng tới khi gỡ khóa.
error_kyc_authGian hàng chưa hoàn tất đăng ký người bán trên Kênh Người Bán.

Get started

  1. Sign up for Partner
  2. Enable a data type of the Khuyến mãi (Marketing) group on the platform page
  3. Create an API key (tick the Shopee channel)
  4. Call it as in the examples above