v2.media_space.upload_image
POST/api/v2/media_space/upload_imageGọi qua 360: POST https://partner.quantri360.com/v1/shopee/api/v2/media_space/upload_image
Endpoint ghi — thay đổi dữ liệu trên Shopee. Key phải được tạo với tick "Cho phép gọi API ghi", nếu không sẽ nhận 403 write_not_allowed. Mỗi lần gọi được ghi nhật ký.
Mô tả API
TẢI ẢNH lên kho ảnh Shopee để lấy image_id — bắt buộc trước khi gắn ảnh vào sản phẩm (add_item, update_item, ảnh phân loại, ảnh mô tả). Ảnh JPG / JPEG / PNG, tối đa 10 MB; qua 360 gửi 1 ảnh mỗi lần.
- Là API GHI — thay đổi dữ liệu thật trên Shopee; key cần quyền ghi (can_write).
- Gửi multipart/form-data: trường tệp
image(1 ảnh) + trường chữscene/ratiokhi cần. Nhiều ảnh: gọi lần lượt từng ảnh. - Đọc
image_idởimage_info, hoặc ởimage_info_list[].image_infokhi tải nhiều ảnh.
Request
Địa chỉ
POST https://partner.quantri360.com/v1/shopee/api/v2/media_space/upload_image
Xác thực & gian hàng
| Tên | Vị trí | Kiểu | Mẫu | Mô tả |
|---|---|---|---|---|
| Authorization | header | header | Bearer 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_id | query | string | 100001 | Gian 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. |
Tham số request
| Tên | Vị trí | Kiểu | Bắt buộc | Mẫu | Mô tả |
|---|---|---|---|---|---|
| image | body | file | Có | (tệp ảnh) | Một tệp ảnh JPG / JPEG / PNG ≤ 10 MB, gửi dạng multipart/form-data. 360 kiểm định dạng theo nội dung tệp. |
| scene | body | string | Không | normal | normal (mặc định — Shopee xử lý thành ảnh vuông, dùng cho ảnh sản phẩm) · desc (giữ nguyên ảnh, dùng cho ảnh trong mô tả). |
| ratio | body | string | Không | 1:1 | 1:1 (mặc định) hoặc 3:4 — 3:4 chỉ gian hàng được Shopee mở. |
Ví dụ request
curl -s -X POST "https://partner.quantri360.com/v1/shopee/api/v2/media_space/upload_image" \ -H "Authorization: Bearer $KEY" \ -F "scene=normal" \ -F "image=@ao-dam.jpg"
Python
import requests
from contextlib import ExitStack
KEY = "q360_live_..."
with ExitStack() as stack:
files = [("image", stack.enter_context(open("ao-dam.jpg", "rb")))]
r = requests.post("https://partner.quantri360.com/v1/shopee/api/v2/media_space/upload_image", params={}, data={
"scene": "normal"
}, files=files, headers={"Authorization": f"Bearer {KEY}"}, timeout=60)
print(r.status_code, r.json())Node.js
import { readFile } from 'node:fs/promises';
const KEY = 'q360_live_...';
const url = new URL('https://partner.quantri360.com/v1/shopee/api/v2/media_space/upload_image');
const form = new FormData();
form.append("scene", "normal");
form.append("image", new Blob([await readFile("ao-dam.jpg")]), "ao-dam.jpg");
const r = await fetch(url, { method: 'POST', headers: { Authorization: `Bearer ${KEY}` }, body: form });
console.log(r.status, await r.json());PHP
<?php
$key = 'q360_live_...';
$ch = curl_init('https://partner.quantri360.com/v1/shopee/api/v2/media_space/upload_image');
curl_setopt($ch, CURLOPT_HTTPHEADER, ['Authorization: Bearer ' . $key]);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, ['scene' => 'normal', 'image' => new CURLFile('ao-dam.jpg')]);
echo curl_exec($ch);
curl_close($ch);Response
Tham số phản hồi (nguyên của Shopee)
| Tên | Kiểu | Mẫu | Mô tả |
|---|---|---|---|
| request_id | string | d52ca43b277a4f9292fb8be658bfd33d | Mã request của Shopee để tra lỗi. |
| error | string | Mã lỗi Shopee; rỗng = thành công. | |
| message | string | Mô tả lỗi. | |
| warning | string | ||
| response | object | ||
| image_info | object | Ảnh đầu tiên. | |
| image_id | string | vn-10000000092-7r98o-lxm45esiq5zt3b | Mã ảnh — gửi trong image_id_list. |
| image_url_list | object[] | ||
| image_url_region | string | VN | |
| image_url | string | Link ảnh. | |
| image_info_list | object[] | Kết quả từng ảnh khi tải nhiều ảnh. | |
| id | int | 0 | Thứ tự ảnh. |
| error | string | Lỗi riêng ảnh này. | |
| message | string | ||
| image_info | object | image_id, image_url_list. |
Mẫu phản hồi
{
"error": "",
"message": "",
"warning": "",
"request_id": "a1b2c3d4e5f60718…",
"response": {
"image_info": {
"image_id": "vn-10000000092-7r98o-lxm45esiq5zt3b",
"image_url_list": [
{
"image_url_region": "VN",
"image_url": "https://example.com/anh-mau.jpg"
}
]
},
"image_info_list": [
{
"id": 0,
"error": "",
"message": "",
"image_info": {
"image_id": "vn-10000000092-7r98o-lxm45esiq5zt3b",
"image_url_list": [
{
"image_url_region": "VN",
"image_url": "https://example.com/anh-mau.jpg"
}
]
}
}
]
}
}
Mã lỗi của Shopee (8)
Bấm để xem
| Mã | Ý nghĩa |
|---|---|
| error_param | Tham số sai / thiếu / sai kiểu — xem `message` để biết tham số nào. |
| 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_data | Dữ 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_server | Lỗi hệ thống Shopee — thử lại sau ít phút. |
| error_tier_img_partial | Interal error, please contact openapi team. |
| error_tier_img_old_app | Interal error, please contact openapi team. |
| error_limit | Chạ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_limit | Gọ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). |
Bắt đầu dùng
- Đăng ký tài khoản Partner
- Mở loại dữ liệu thuộc nhóm Sản phẩm ở trang nền tảng
- Tạo API key (tick kênh Shopee)
- Gọi theo ví dụ ở trên