返回AI 工具與自訂工具

將 Shopify 公開搜尋 API 整合為自訂工具以推薦合適的產品


本指南介紹如何利用 Shopify 簡單、開放的搜尋 API 來建立一個用於查詢產品的自訂工具。這種方法避免了建構 Shopify 私有應用的複雜性。


1. Shopify 搜尋 API 端點


你無需使用複雜的內部 API,而是可以使用一個專為搜尋建議設計的公開可存取端點。該端點無需身分驗證。


URL 結構


\\\`

https://{your_store_domain}/search/suggest.json

\\\`


你必須附加查詢參數來指定你的搜尋內容。


關鍵參數


  • q:搜尋詞(你要查找的產品名稱)
  • resources[type]:設為 \product\ 以僅搜尋產品
  • resources[options][fields]:以逗號分隔的搜尋欄位列表(title、body、vendor、variants)
  • resources[limit]:(選填)限制返回結果數量的數字(例如 10)
  • resources[options][unavailable_products]:(選填)設定是否顯示缺貨產品

請求範例


取得 10 個產品的通用列表:

\\\`

https://{your_store_domain}/search/suggest.json?resources[type]=product&resources[options][fields]=title,body&resources[limit]=10

\\\`


搜尋特定詞條,例如 "gel":

\\\`

https://{your_store_domain}/search/suggest.json?q=gel&resources[type]=product&resources[options][fields]=title,body

\\\`




2. 理解 API 回應


該 API 返回一個 JSON 物件,結果包含在 \products\ 陣列中。關鍵欄位包括:


  • title:產品名稱
  • price:產品價格
  • image:產品主圖的 URL
  • url重要 —— 這是一個相對 URL(例如 /products/aloe-vera-gel)。必須將其附加到店鋪網域之後
  • vendor:品牌或供應商
  • body:產品描述
  • variants:關於不同產品版本的資訊



3. 建立自訂工具


在你的 ABC Sales AI 自訂工具介面中進行如下設定:


  1. 建立新工具:

- Name: Shopify_Product_Search

- Description: Searches for products in the Shopify store and provides information and links


  1. 設定 API 操作:

- Method: GET

- URL: \https://{your_store_domain}/search/suggest.json?resources[type]=product&resources[options][fields]=title,body&resources[limit]=10\

- 將 \{your_store_domain}\ 替換為實際的 Shopify 網域


  1. 參數:

- Name: q

- Description: search query to use when searching for products

- Type: String

- Location: Query

- Required: YES


  1. 身分驗證: 選擇 None(這是一個公開 API)



4. 處理輸出:建構產品連結


該 API 返回的是相對 URL。請將以下指令加入你的 AI 系統提示詞中:


_"When the user asks for a product, use the 'Shopify_Product_Search' tool. To create product links, use the base URL https://{your_store_public_domain} and append the url value returned by the tool."_


範例:


  • 基礎 URL:\https://www.example-store.com\
  • 相對 url:\/products/super-aloe-gel\
  • 最終連結:\https://www.example-store.com/products/super-aloe-gel\

💡
專業提示: 這能確保使用者收到一個可直接點擊、指向 Shopify 即時網站上產品的連結。

還需要幫助?

我們的支援團隊隨時為你提供協助。

聯絡支援