Integrating Shopify's Public Search API as a Custom Tool To Recommend The Right Product
This guide outlines how to leverage Shopify's simple, open search API to create a custom tool for product lookups. This method avoids the complexity of building a private Shopify app.
1. The Shopify Search API Endpoint
Instead of using a complex internal API, you can use a publicly accessible endpoint designed for search suggestions. This endpoint requires no authentication.
URL Structure
\\\`
https://{your_store_domain}/search/suggest.json
\\\`
You must append query parameters to specify your search.
Key Parameters
- q: The search term (the product name you're looking for)
- resources[type]: Set to \
product\to search only for products - resources[options][fields]: A comma-separated list of fields to search (title, body, vendor, variants)
- resources[limit]: (Optional) Number to limit returned results (e.g., 10)
- resources[options][unavailable_products]: (Optional) Set to show or hide out-of-stock products
Example Requests
Get a general list of 10 products:
\\\`
https://{your_store_domain}/search/suggest.json?resources[type]=product&resources[options][fields]=title,body&resources[limit]=10
\\\`
Search for a specific term like "gel":
\\\`
https://{your_store_domain}/search/suggest.json?q=gel&resources[type]=product&resources[options][fields]=title,body
\\\`
2. Understanding the API Response
The API returns a JSON object with results in a \products\ array. Key fields include:
- title: The product name
- price: The product price
- image: URL to the product's featured image
- url: Important - A relative URL (e.g., /products/aloe-vera-gel). Must be appended to the store domain
- vendor: The brand or vendor
- body: The product description
- variants: Information about different product versions
3. Creating the Custom Tool
Configure this in your ABC Sales AI custom tool interface:
- Create a New Tool:
- Name: Shopify_Product_Search
- Description: Searches for products in the Shopify store and provides information and links
- Set up the API Action:
- Method: GET
- URL: \https://{your_store_domain}/search/suggest.json?resources[type]=product&resources[options][fields]=title,body&resources[limit]=10\
- Replace \{your_store_domain}\ with the actual Shopify domain
- Parameters:
- Name: q
- Description: search query to use when searching for products
- Type: String
- Location: Query
- Required: YES
- Authentication: Select None (this is a public API)
4. Handling the Output: Constructing Product Links
The API returns relative URLs. Add this instruction to your AI's system prompt:
_"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."_
Example:
- Base URL: \
https://www.example-store.com\ - Relative url: \
/products/super-aloe-gel\ - Final Link: \
https://www.example-store.com/products/super-aloe-gel\