返回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 实时网站上产品的链接。

还需要帮助?

我们的支持团队随时为你提供协助。

联系支持