VI | EN
Nhắn Messenger
Dành cho developer

Tải ảnh lên kho ảnh Shopee — API Shopee

v2.media_space.upload_image · gọi qua Quantri360 bằng một API key cho chính tài khoản / tài sản bạn đã kết nối và ủy quyền — 360 lo việc ký request và làm mới phiên đăng nhập bạn đã cấp.

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 / ratio khi 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_info khi 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ênVị tríKiểuMẫuMô tả
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.

Tham số request

TênVị tríKiểuBắt buộcMẫuMô tả
imagebodyfileCó(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.
scenebodystringKhôngnormalnormal (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ả).
ratiobodystringKhông1:11: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ênKiểuMẫuMô tả
request_idstringd52ca43b277a4f9292fb8be658bfd33dMã request của Shopee để tra lỗi.
errorstringMã lỗi Shopee; rỗng = thành công.
messagestringMô tả lỗi.
warningstring
responseobject
image_infoobjectẢnh đầu tiên.
image_idstringvn-10000000092-7r98o-lxm45esiq5zt3bMã ảnh — gửi trong image_id_list.
image_url_listobject[]
image_url_regionstringVN
image_urlstringLink ảnh.
image_info_listobject[]Kết quả từng ảnh khi tải nhiều ảnh.
idint0Thứ tự ảnh.
errorstringLỗi riêng ảnh này.
messagestring
image_infoobjectimage_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_paramTham 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_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_serverLỗi hệ thống Shopee — thử lại sau ít phút.
error_tier_img_partialInteral error, please contact openapi team.
error_tier_img_old_appInteral error, please contact openapi team.
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).

Bắt đầu dùng

  1. Đăng ký tài khoản Partner
  2. Mở loại dữ liệu thuộc nhóm Sản phẩm ở trang nền tảng
  3. Tạo API key (tick kênh Shopee)
  4. Gọi theo ví dụ ở trên