如何為 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 有哪些?

API方法功能說明
/merchant/products/batchPOST在單一請求中建立或完整取代最多 50 筆商品
/merchant/productsPOST建立或完整取代單一商品
/merchant/productsGETsourceexternal_id 讀取一筆已匯入商品
/merchant/productsPATCH部分更新單一商品(read-merge-write)
/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 權杖不能呼叫這些路由。

建立或輪替 owner secret 的方式與其他 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 查詢參數必須與標頭相符。請僅將 owner secrets 儲存在伺服器端環境變數中——絕不要放在 storefront script、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 個字元。在管理後台中建立的商品,其預設 source 為 admin
  • 商品識別是由 store、source 與 external ID 的組合構成。批次與單一 POST upsert 都是完整取代,不是 patch:省略的選用欄位會被清除。若要進行部分更新,請使用 PATCH
  • 批次請求包含 1–50 筆商品,且請求大小最多 2,000,000 bytes。每筆商品驗證後的 JSON 限制為 128,000 bytes,且最多 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