Enhance Your E-commerce Experience with Google Shopping Product Search API

The Google Shopping Product Search API provides developers with powerful tools to integrate product search capabilities into their applications. By leveraging various cognitive actions, such as retrieving product details, offers, and reviews, developers can create a seamless shopping experience that enhances user engagement and boosts sales. With its real-time data and comprehensive filtering options, this API simplifies the process of finding the right products for users, making it an essential resource for e-commerce platforms and applications.
Prerequisites
To get started with the Google Shopping Product Search API, you'll need an API key and a basic understanding of making API calls. This will allow you to authenticate your requests and access the various functionalities offered by the API.
Retrieve Product Reviews with Pagination
The "Retrieve Product Reviews with Pagination" action allows developers to fetch all product reviews from the new Google Shopping layout while supporting pagination and scrolling. This is particularly useful for applications that need to display extensive user feedback for products, ensuring users can make informed purchasing decisions based on diverse opinions.
Input Requirements
The input for this action includes:
productId: A complex identifier string for the product.limit: Specifies the maximum number of reviews to retrieve (default is 10).cursor: A string used for pagination to fetch the next set of results (default is an empty string).rating: Filter results based on numerical ratings.country: Specifies the country code for filtering results (default is 'us').language: Specifies the language for the results (default is 'en').sortOrder: Defines the order of the results, with options for "MOST_RELEVANT" or "MOST_RECENT".
Expected Output
The expected output will include:
data: Contains the cursor for pagination and an array of reviews.- Each review will provide details such as rating, review ID, review date, review text, author, and source.
Use Cases for this Specific Action
This action is beneficial in scenarios such as:
- E-commerce platforms that want to showcase user reviews to enhance product credibility.
- Applications that require in-depth analysis of customer feedback for market research.
- Integrating review data into a shopping assistant bot to provide personalized recommendations based on user preferences.
```python
import requests
import json
# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"
action_id = "2b6c9f49-5d12-4e98-be43-72cde5413bb5" # Action ID for: Retrieve Product Reviews with Pagination
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"limit": 10,
"country": "us",
"language": "en",
"productId": "catalogid:8425421641323327810,gpcid:1261873578657646759,headlineOfferDocid:6367138647863486978,rds:PC_1261873578657646759|PROD_PC_1261873578657646759,imageDocid:17958223083723421156,mid:576462516936404275,pvt:hg,pvf:",
"sortOrder": "MOST_RELEVANT"
}
headers = {
"Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
"Content-Type": "application/json",
# Add any other required headers for the Cognitive Actions API
}
# Prepare the request body for the hypothetical execution endpoint
request_body = {
"action_id": action_id,
"inputs": payload
}
print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")
try:
response = requests.post(
COGNITIVE_ACTIONS_EXECUTE_URL,
headers=headers,
json=request_body
)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
result = response.json()
print("Action executed successfully. Result:")
print(json.dumps(result, indent=2))
except requests.exceptions.RequestException as e:
print(f"Error executing action {action_id}: {e}")
if e.response is not None:
print(f"Response status: {e.response.status_code}")
try:
print(f"Response body: {e.response.json()}")
except json.JSONDecodeError:
print(f"Response body (non-JSON): {e.response.text}")
print("------------------------------------------------")
## Fetch Store Reviews
The "Fetch Store Reviews" action enables developers to retrieve all reviews for a specific store or merchant, with support for pagination, filtering by star ratings, review periods, and sorting criteria. This is crucial for businesses aiming to monitor their online reputation and understand customer sentiments.
### Input Requirements
The input parameters for this action include:
- `storeDomain`: The domain of the store to query reviews from.
- `language`: Specifies the language for the query results (default is 'en').
- `starRating`: Filter for specific star ratings (e.g., "FIVE_STARS").
- `countryCode`: The country code for the domain being queried (default is 'us').
- `resultLimit`: The maximum number of results to return (default is 10).
- `reviewPeriod`: The time frame for reviews to be considered (up to two years).
- `sortCriteria`: The criteria to sort reviews by, such as "MOST_HELPFUL".
### Expected Output
The output will include:
- `data`: Contains cursor information and an array of reviews for the specified store.
- Each review will include the store rating, number of reviews, and individual review details.
### Use Cases for this Specific Action
This action is useful for:
- Businesses that want to analyze customer feedback and ratings to improve service quality.
- Applications that consolidate information from multiple merchants to help users make informed shopping choices.
- Monitoring competitors' reviews to gain insights into market trends and customer preferences.
import requests
import json
# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"
action_id = "89f0cd5a-a5f8-457f-b675-99024f8f828b" # Action ID for: Fetch Store Reviews
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"language": "en",
"starRating": "ALL",
"countryCode": "us",
"resultLimit": 10,
"storeDomain": "amazon.com",
"reviewPeriod": "ALL",
"sortCriteria": "MOST_HELPFUL"
}
headers = {
"Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
"Content-Type": "application/json",
# Add any other required headers for the Cognitive Actions API
}
# Prepare the request body for the hypothetical execution endpoint
request_body = {
"action_id": action_id,
"inputs": payload
}
print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")
try:
response = requests.post(
COGNITIVE_ACTIONS_EXECUTE_URL,
headers=headers,
json=request_body
)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
result = response.json()
print("Action executed successfully. Result:")
print(json.dumps(result, indent=2))
except requests.exceptions.RequestException as e:
print(f"Error executing action {action_id}: {e}")
if e.response is not None:
print(f"Response status: {e.response.status_code}")
try:
print(f"Response body: {e.response.json()}")
except json.JSONDecodeError:
print(f"Response body (non-JSON): {e.response.text}")
print("------------------------------------------------")
## Fetch Product Details
The "Fetch Product Details" action retrieves comprehensive information about a product using its unique product ID. This includes reviews, photos, specifications, and more from Google Shopping.
### Input Requirements
The inputs for this action consist of:
- `productId`: A unique identifier for the product.
- `country`: The country code for the product request (default is 'us').
- `language`: The language code for the product response (default is 'en').
### Expected Output
The output will provide:
- `data`: Contains detailed product information, including price, specifications, reviews, and images.
- The product rating and number of offers will also be included.
### Use Cases for this Specific Action
This action is ideal for:
- E-commerce sites that need to display detailed product information to users.
- Price comparison tools that aggregate product details from various sources.
- Applications that need to provide users with rich content, such as images and specifications, to enhance their shopping experience.
import requests
import json
# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"
action_id = "977b7f14-db8f-43b7-aa73-a337b6fce01f" # Action ID for: Fetch Product Details
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"country": "us",
"language": "en",
"productId": "catalogid:8425421641323327810,gpcid:1261873578657646759,headlineOfferDocid:6367138647863486978,rds:PC_1261873578657646759|PROD_PC_1261873578657646759,imageDocid:17958223083723421156,mid:576462516936404275,pvt:hg,pvf:"
}
headers = {
"Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
"Content-Type": "application/json",
# Add any other required headers for the Cognitive Actions API
}
# Prepare the request body for the hypothetical execution endpoint
request_body = {
"action_id": action_id,
"inputs": payload
}
print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")
try:
response = requests.post(
COGNITIVE_ACTIONS_EXECUTE_URL,
headers=headers,
json=request_body
)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
result = response.json()
print("Action executed successfully. Result:")
print(json.dumps(result, indent=2))
except requests.exceptions.RequestException as e:
print(f"Error executing action {action_id}: {e}")
if e.response is not None:
print(f"Response status: {e.response.status_code}")
try:
print(f"Response body: {e.response.json()}")
except json.JSONDecodeError:
print(f"Response body (non-JSON): {e.response.text}")
print("------------------------------------------------")
## Retrieve Product Offers
The "Retrieve Product Offers" action allows developers to fetch all available offers for a specific product from the new Google Shopping layout. This is designed to support countries where the new layout is active and provides real-time updates.
### Input Requirements
The inputs include:
- `productIdentifier`: A complex string that identifies the product.
- `page`: The page number to be retrieved (default is 1).
- `country`: The country code representing the user's country (default is 'us').
- `language`: The language code indicating the user's language preference (default is 'en').
### Expected Output
The expected output includes:
- `data`: Contains current offers for the specified product, including pricing, store information, and shipping details.
- Each offer will include original price, sale price, and any applicable discounts.
### Use Cases for this Specific Action
This action is valuable for:
- Price comparison websites that need to display competitive offers for users.
- E-commerce platforms that want to showcase multiple seller options for a single product.
- Applications focused on deal hunting, helping users find the best prices available.
import requests
import json
# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"
action_id = "a8cc760c-5309-4030-9d84-069793d5272b" # Action ID for: Retrieve Product Offers
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"page": 1,
"country": "us",
"language": "en",
"productIdentifier": "catalogid:15554707778408471208,gpcid:6219277726645206819,headlineOfferDocid:8835386203856143595,rds:PC_15478400683365031707|PROD_PC_15478400683365031707,imageDocid:10653897321817113741,mid:576462815432560445,pvt:hg,pvf:"
}
headers = {
"Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
"Content-Type": "application/json",
# Add any other required headers for the Cognitive Actions API
}
# Prepare the request body for the hypothetical execution endpoint
request_body = {
"action_id": action_id,
"inputs": payload
}
print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")
try:
response = requests.post(
COGNITIVE_ACTIONS_EXECUTE_URL,
headers=headers,
json=request_body
)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
result = response.json()
print("Action executed successfully. Result:")
print(json.dumps(result, indent=2))
except requests.exceptions.RequestException as e:
print(f"Error executing action {action_id}: {e}")
if e.response is not None:
print(f"Response status: {e.response.status_code}")
try:
print(f"Response body: {e.response.json()}")
except json.JSONDecodeError:
print(f"Response body (non-JSON): {e.response.text}")
print("------------------------------------------------")
## Search Product Deals on Google Shopping
The "Search Product Deals on Google Shopping" action enables users to search for product deals with comprehensive filtering options, including pagination, price range, and product condition.
### Input Requirements
The inputs required are:
- `query`: The search term used to query products.
- `page`: Specifies the page number for paginated results (default is 1).
- `limit`: The maximum number of items per page (default is 10).
- Additional filters for price range, product condition, and more.
### Expected Output
The output will include:
- `data`: Contains filtered product results based on the specified query and parameters.
- Each product will include details like title, price, and available offers.
### Use Cases for this Specific Action
This action is beneficial for:
- Users looking for specific products on sale, allowing them to find the best deals quickly.
- Retail applications that aggregate product offerings, making it easier for users to shop across multiple platforms.
- Any e-commerce solution aiming to enhance the shopping experience through efficient product discovery.
import requests
import json
# Replace with your actual Cognitive Actions API key and endpoint
# Ensure your environment securely handles the API key
COGNITIVE_ACTIONS_API_KEY = "YOUR_COGNITIVE_ACTIONS_API_KEY"
# This endpoint URL is hypothetical and should be documented for users
COGNITIVE_ACTIONS_EXECUTE_URL = "https://api.cognitiveactions.com/actions/execute"
action_id = "e00d1e49-33e3-4ed5-84c0-73617b8ab2d1" # Action ID for: Search Product Deals on Google Shopping
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"page": 1,
"limit": 10,
"query": "Laptop",
"sortBy": "BEST_MATCH",
"country": "us",
"language": "en",
"productCondition": "ANY"
}
headers = {
"Authorization": f"Bearer {COGNITIVE_ACTIONS_API_KEY}",
"Content-Type": "application/json",
# Add any other required headers for the Cognitive Actions API
}
# Prepare the request body for the hypothetical execution endpoint
request_body = {
"action_id": action_id,
"inputs": payload
}
print(f"--- Calling Cognitive Action: {action.name or action_id} ---")
print(f"Endpoint: {COGNITIVE_ACTIONS_EXECUTE_URL}")
print(f"Action ID: {action_id}")
print("Payload being sent:")
print(json.dumps(request_body, indent=2))
print("------------------------------------------------")
try:
response = requests.post(
COGNITIVE_ACTIONS_EXECUTE_URL,
headers=headers,
json=request_body
)
response.raise_for_status() # Raise an exception for bad status codes (4xx or 5xx)
result = response.json()
print("Action executed successfully. Result:")
print(json.dumps(result, indent=2))
except requests.exceptions.RequestException as e:
print(f"Error executing action {action_id}: {e}")
if e.response is not None:
print(f"Response status: {e.response.status_code}")
try:
print(f"Response body: {e.response.json()}")
except json.JSONDecodeError:
print(f"Response body (non-JSON): {e.response.text}")
print("------------------------------------------------")
## Conclusion
The Google Shopping Product Search API offers developers a robust suite of cognitive actions to enhance e-commerce applications. By leveraging these actions, businesses can provide users with detailed product information, comprehensive reviews, and real-time offers, ultimately improving the shopping experience. As e-commerce continues to evolve, integrating these capabilities will be crucial for staying competitive and meeting customer expectations. Start exploring these actions today to elevate your application!