如何為 SiteChat 上傳你的產品目錄

A secure merchant key unlocks catalog upload APIs that send products and images into SiteChat search and chat

如果你在自己的網站上使用 SiteChat(而非 Shopify 商店),你可以將結構化的產品記錄傳送至 Shoply,讓顧客能在 SiteChat 對話及產品搜尋中找到它們。

這些端點與其餘 Shoply Merchant API 共用相同的 Settings → Store owner API secret,而 SiteChat 管理後台的 Product Catalog 頁面則可使用你已登入的管理員 access token 來呼叫它們。Shopify 商店會繼續透過 Shopify 同步產品目錄資料;這些上傳路由只適用於尚未同步 Magento 產品目錄的 SiteChat 帳戶。

在 SiteChat 管理後台中,Product Catalog 會開啟一個類似 Shopify 的區域,包含 Products、Collections 及 Inventory。你可以新增或編輯產品、匯入 CSV/Excel、將產品分組到手動集合,並調整庫存數量。

有哪些 API 可用?

APIMethod作用
/merchant/products/batchPOST在單一請求中建立或完整取代最多 50 個產品
/merchant/productsPOST建立或完整取代一個產品
/merchant/productsGET依 source 及 external_id 讀取一個已匯入產品
/merchant/productsPATCH部分更新一個產品;如要取代 variants 或 metafields,必須使用來自 GET 的版本
/merchant/productsDELETE將產品作軟封存(status=archived)
/merchant/products/listGET分頁列出已匯入產品,供管理表格使用
/merchant/products/imagesPOST上傳產品圖片並取得公開 HTTPS URL
/merchant/collectionsGET / POST列出或建立手動集合
/merchant/collections/{id}GET / PUT / DELETE讀取、取代或封存一個集合
/merchant/inventoryGET列出庫存資料列(產品及變體數量)
/merchant/inventory/adjustPOST設定產品或變體的追蹤庫存數量

成功儲存產品後,Shoply 會要求重建商店索引。在重建完成前,回應會顯示 index_status: "pending"。已發佈的產品之後會同時出現在產品索引,以及 SiteChat 對話所使用的知識中。

誰可以使用這些 API?

  • 你的商店必須是 SiteChat 帳戶(app_platform 為 SiteChat)。
  • Shopify 商店 key(包括任何 *.myshopify.com 網域)會被拒絕。
  • 驗證必須使用有效的店主 API 密鑰,或用於請求中確切 store_key 的 SiteChat 管理員 access token。
  • Shopify Admin API token 無法呼叫這些路由。

建立或輪換 owner secret 的方式,與其他 Merchant API 整合相同:如何使用 Shoply Merchant API。在 SiteChat 管理控制台中,開啟 Product Catalog 即可管理產品、集合及庫存,或匯入 CSV / Excel 檔案,而無需自行管理 secret。

驗證如何運作?

從伺服器連接器

請從受信任的後端透過 HTTPS 呼叫 API。在 Authorization header 中放入 JSON 字串:

json
{ "store_key": "YOUR_SITECHAT_STORE_KEY", "store_owner_api_secrete": "YOUR_STORE_OWNER_API_SECRET" }

store_owner_api_secrete 是公開欄位名稱,包括其歷史拼寫。store_owner_api_secret 亦可接受。這不是 Bearer token。

從 SiteChat 管理後台

Product Catalog 頁面則會改為傳送你已登入的管理員工作階段:

json
{ "store_key": "YOUR_SITECHAT_STORE_KEY", "admin_auth_token": "YOUR_SITECHAT_ACCESS_TOKEN" }

access_token 可作為 admin_auth_token 的別名使用。

store_key 查詢參數必須與 header 相符。請只將 owner secret 儲存在伺服器端環境變數中——切勿放在店面腳本、URL 或公開儲存庫中。

bash
export SHOPLY_STORE_KEY="your-sitechat-store-key" export SHOPLY_STORE_OWNER_API_SECRETE="shoply_owner_key_example123.secret-value"

如何上傳產品?

POST https://api.shoplyai.ai/merchant/products/batch?store_key=YOUR_SITECHAT_STORE_KEY

json
{ "source": "woocommerce-main", "products": [ { "external_id": "123", "title": "Trail shoes", "description": "Water-resistant hiking shoes.", "url": "https://example.com/products/trail-shoes", "currency": "USD", "price": "49.95", "original_price": "59.95", "available": true, "status": "published", "images": ["https://example.com/images/trail-shoes.jpg"], "categories": ["Footwear"], "metafields": {"material": "Leather"}, "variants": [ { "external_id": "124", "title": "Brown / 42", "sku": "TRAIL-BR-42", "price": "49.95", "available": true, "metafields": {"color": "Brown", "size": "42"} } ] } ] }

必填欄位與規則

  • 必填產品欄位:external_id、title、url、currency、price 及 available。status 預設為 published。
  • 可選庫存:在產品或變體上將 tracks_inventory 設為 true,並設定非負數的 quantity。Shoply 之後會根據庫存推導供應狀態(quantity > 0),並儲存 total_inventory 供管理列表使用。
  • source 用來命名產品目錄連接(不一定是平台)。請使用穩定名稱,例如 woocommerce-main。允許字符:小寫字母、數字、底線及連字號;最多 64 個字符。於管理後台表單建立的產品,預設 source 為 admin。
  • 產品識別由 store、source 及 external ID 的組合構成。批次及單一 POST upsert 屬於完整取代,並非 patch:省略的可選欄位會被清除。部分更新請使用 PATCH。
  • 批次包含 1–50 個產品,且請求總大小最多為 2,000,000 bytes。每個產品經驗證後的 JSON 上限為 128,000 bytes,且最多可有 250 個 variants。
  • 價格建議使用十進位字串。貨幣必須是三個大寫字母代碼。
  • 產品及圖片 URL 必須為 HTTP(S)。匯入程序不會替你抓取那些 URL。
  • 可使用公開 metafields 儲存可搜尋的產品規格(SiteChat 對應 Shopify 產品 metafields 的概念)。值必須為純字串。舊版 attributes 可作為別名使用。私人產品 metadata 已不再支援。
  • draft 及 archived 產品不會納入下一次已發佈索引。已發佈但售罄的產品仍會保留在索引中,並附帶供應狀態。
  • 手動集合會儲存標題、描述、狀態,以及產品成員清單(source + external_id)。此版本不支援智慧/規則型集合。

成功回應範例

json
{ "results": [ { "external_id": "123", "product_id": "sitechat_product::woocommerce-main::<sha256-of-external-id>", "status": "stored" } ], "index_status": "pending", "index_revision": 1 }

Shoply 會在寫入前驗證整個請求。HTTP 200 仍可能列出部分 failed 結果,並帶有 error: "storage_error"。請檢查每一項結果,並重試失敗的產品。若 index_status 為 request_failed,表示儲存成功但未排程索引工作——亦請重新提交那些已儲存的產品。

Python 範例

python
import json import os import requests store_key = os.environ["SHOPLY_STORE_KEY"] headers = { "Authorization": json.dumps({ "store_key": store_key, "store_owner_api_secrete": os.environ["SHOPLY_STORE_OWNER_API_SECRETE"], }) } response = requests.post( "https://api.shoplyai.ai/merchant/products/batch", params={"store_key": store_key}, headers=headers, json={ "source": "custom", "products": [{ "external_id": "123", "title": "Trail shoes", "url": "https://example.com/products/trail-shoes", "currency": "USD", "price": "49.95", "available": True, }], }, timeout=60, ) response.raise_for_status() result = response.json() failed = [item["external_id"] for item in result["results"] if item["status"] != "stored"] if failed: raise RuntimeError(f"Products need retry: {failed}") if result["index_status"] == "request_failed": raise RuntimeError("Products saved, but retry the batch to request indexing")

如何驗證已匯入的產品?

GET https://api.shoplyai.ai/merchant/products?store_key=YOUR_SITECHAT_STORE_KEY&source=woocommerce-main&external_id=123

使用相同的 Authorization header。回應會包含 schema_version、updated_at、index_status 及正規化後的 product。缺少記錄時會回傳 HTTP 404。

當背景索引器發佈重建結果後,每個產品的讀取狀態會變成 indexed、excluded(用於 draft 或 archived 產品)或 limit_exceeded。管理列表請使用 GET /merchant/products/list。可透過 DELETE /merchant/products 進行軟封存(或將 status 設為 archived / draft),以令產品不會出現在下一次已發佈索引中;此版本不提供硬刪除。

python
record = requests.get( "https://api.shoplyai.ai/merchant/products", params={ "store_key": store_key, "source": "woocommerce-main", "external_id": "123", }, headers=headers, timeout=30, ) record.raise_for_status() print(record.json()["index_status"], record.json()["product"]["title"])

如何安全更新 Variants 或 Metafields?

如果 PATCH 包含 variants、metafields 或舊版 attributes 欄位,請先透過 GET 讀取產品。根據該回應建立修改內容,並在 PATCH body 中附上其頂層 updated_at 值作為 expected_updated_at。清除 variants 或 metafields 時亦適用。

python
current_response = requests.get( "https://api.shoplyai.ai/merchant/products", params={"store_key": store_key, "source": "woocommerce-main", "external_id": "123"}, headers=headers, timeout=30, ) current_response.raise_for_status() current = current_response.json() updated_metafields = {**current["product"].get("metafields", {}), "material": "Leather"} response = requests.patch( "https://api.shoplyai.ai/merchant/products", params={"store_key": store_key}, headers=headers, json={ "source": "woocommerce-main", "external_id": "123", "expected_updated_at": current["updated_at"], "metafields": updated_metafields, }, timeout=30, ) response.raise_for_status()

HTTP 409 表示版本缺失,或另一個更新已更改該產品。請先讀取最新產品,重新合併你想套用的變更後再重試。不要把新的版本附加到舊的 variants 清單上:那樣可能會覆寫較新的庫存數值。

現有整合若在沒有版本的情況下 PATCH 這些欄位,必須更新。只更新純量欄位的 PATCH 請求、專用庫存調整,以及透過 POST 或批次匯入進行的完整取代,均不需要此欄位。不過,完整取代仍會取代整個產品。

我可以上傳產品圖片嗎?

可以。若圖片已存在於持久公開的 HTTPS URL,請將該 URL 放入產品的 images 清單,或變體的 image 欄位中。公開的 S3 HTTPS URL 可用。原始 s3:// 路徑及短效簽署 URL 則不可。

如要讓 Shoply 代為託管檔案,請從你的後端上傳原始圖片位元組:

text
POST https://api.shoplyai.ai/merchant/products/images?store_key=YOUR_SITECHAT_STORE_KEY Content-Type: image/png

請傳送原始檔案位元組,而不是 JSON、base64 或 multipart form data。支援 JPEG、PNG 及 WebP,大小上限為 10 MiB 及 2,000 萬像素。不支援動畫圖片。Shoply 會將圖片轉換為 WebP,並移除內嵌 metadata。

python
with open("trail-shoes.png", "rb") as image_file: response = requests.post( "https://api.shoplyai.ai/merchant/products/images", params={"store_key": store_key}, headers={**headers, "Content-Type": "image/png"}, data=image_file, timeout=60, ) response.raise_for_status() image_url = response.json()["url"]

HTTP 201 會回傳 url、content_type、size_bytes、width 及 height。單獨上傳圖片並不會將其附加到產品,也不會要求建立索引。請把回傳的 URL 放入完整產品資料中,然後再次透過 /merchant/products/batch 提交。

同一帳戶再次上傳相同圖片時,會重用其 URL。已變更的圖片則會取得新 URL。此版本不提供圖片刪除端點。

產品何時會出現在聊天及搜尋中?

成功批次儲存後,Shoply 會要求背景重建索引。在工作程序發佈新索引之前,回應會顯示 index_status: "pending"。系統不保證固定完成時間。

  • 已發佈產品會同時進入產品搜尋,以及 SiteChat 對話所使用的知識。
  • Draft 及 archived 產品會在下一次重建時被排除。
  • 若未排程索引(index_status: "request_failed"),請重新提交那些已成功儲存的產品批次。

我應預期哪些錯誤?

HTTP status含義
403secret 缺失、無效、已過期或已撤銷;商店錯誤;或非 SiteChat 帳戶
404所請求的已匯入產品不存在
413請求或圖片超出大小限制
415圖片上傳使用了不支援的 Content-Type
422欄位無效、ID 重複、動畫或過大圖片,或超出模型限制
503暫時性儲存失敗

Secrets 會在 90 天 後過期。請在到期前於 Settings → Store owner API secret 建立替代 secret,並撤銷任何你不再需要的 secret。同一 secret 亦可呼叫 Merchant API guide 中記載的分析、對話及知識端點。

如需整合協助,請聯絡 Shoply AI。