如何為 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 頁面亦可使用你已登入的管理員存取權杖來呼叫這些端點。Shopify 商店會繼續透過 Shopify 同步產品目錄資料;這些上載路由只適用於未有同步 Magento 產品目錄的 SiteChat 帳戶。

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

有哪些 API 可用?

APIMethod作用
/merchant/products/batchPOST在單一請求中建立或完整取代最多 50 個商品
/merchant/productsPOST建立或完整取代一個商品
/merchant/productsGET依據 sourceexternal_id 讀取一個已匯入的商品
/merchant/productsPATCH局部更新一個商品(讀取-合併-寫入)
/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 商店金鑰(包括任何 *.myshopify.com 網域)會被拒絕。
  • 驗證必須使用有效的店主 API 密鑰,或用於請求中完全相同 store_key 的 SiteChat 管理員存取權杖。
  • Shopify Admin API 權杖不能呼叫這些路由。

建立或輪換店主密鑰的方式與其他 Merchant API 整合相同:How to Use the Shoply Merchant API。在 SiteChat 管理控制台中,開啟 Product Catalog 即可管理商品、集合及庫存,或匯入 CSV 或 Excel 檔案,而無需自行管理密鑰。

驗證如何運作?

從伺服器連接器

透過 HTTPS 由受信任的後端呼叫 API。把 JSON 字串放在 Authorization 標頭中:

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 權杖。

從 SiteChat 管理後台

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

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

access_token 可作為 admin_auth_token 的別名。

store_key 查詢參數必須與標頭相符。店主密鑰只應保存在伺服器端環境變數中——切勿放在前台腳本、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_idtitleurlcurrencypriceavailablestatus 預設為 published
  • 選擇性庫存:在商品或變體上將 tracks_inventory 設為 true,並提供非負數的 quantity。之後 Shoply 會根據庫存推導供應狀態(quantity > 0),並儲存 total_inventory 供管理清單使用。
  • source 用來命名產品目錄連接(不一定是平台)。請使用穩定名稱,例如 woocommerce-main。允許字元:小寫英文字母、數字、底線及連字號;最多 64 個字元。在管理後台以表單建立的商品,預設 sourceadmin
  • 商品身分由商店、source 及 external ID 的組合決定。批次與單一 POST upsert 都是完整取代,而不是 patch:省略的選填欄位會被清除。局部更新請使用 PATCH
  • 批次可包含 1–50 個商品,且請求總大小最多為 2,000,000 位元組。每個商品經驗證後的 JSON 上限為 128,000 位元組,且最多可有 250 個變體。
  • 價格建議使用十進位字串。貨幣需為三個英文字母的大寫代碼。
  • 商品及圖片 URL 必須為 HTTP(S)。匯入程序不會替你抓取這些 URL。
  • 以公開 metafields 儲存可搜尋的商品規格(即 SiteChat 對應 Shopify 商品 metafields 的方式)。其值必須為純字串。舊版 attributes 可作為別名使用。私人商品 metadata 已不再支援。
  • draftarchived 商品不會納入下一次已發佈索引。已發佈但售罄的商品仍會保留在索引中,並附帶供應狀態。
  • 手動集合會儲存標題、描述、狀態,以及商品成員清單(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_statusrequest_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 標頭。回應會包含 schema_versionupdated_atindex_status 及標準化後的 product。找不到記錄時會回傳 HTTP 404

當背景索引器發佈重建後,每個商品的讀回狀態會變為 indexedexcluded(適用於 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"])

我可以上載商品圖片嗎?

可以。若圖片已存在於持久有效的公開 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 MiB2,000 萬像素。不支援動態圖片。Shoply 會將圖片轉換為 WebP,並移除嵌入的中繼資料。

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 會回傳 urlcontent_typesize_byteswidthheight。單獨上載圖片不會將其附加到商品,也不會要求建立索引。請把回傳的 URL 放入完整商品資料中,再經 /merchant/products/batch 重新提交。

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

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

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

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

我應預期哪些錯誤?

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

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

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