Enhance Your E-commerce Platform with Real Time Product Search and Reviews

The Real Time Product Search and Reviews API is a powerful tool designed for developers looking to integrate seamless product search and comprehensive review functionalities into their e-commerce platforms. This API leverages the vast data from Google Shopping to provide real-time product information and user reviews, significantly enhancing the shopping experience for customers.
By incorporating this API, developers can enable features such as detailed product searches with filtering options, access to extensive product reviews, and ratings that help customers make informed purchasing decisions. This not only streamlines the shopping process but also boosts customer satisfaction and trust in the platform.
Prerequisites
To utilize the Real Time Product Search and Reviews API, you will need an API key and a basic understanding of making API calls.
Fetch Product Reviews
The Fetch Product Reviews action retrieves all product reviews while supporting pagination through cursor and limit parameters. By tapping into reliable data from Google Shopping, this action provides extensive information about product reviews, allowing users to gauge the quality and performance of products easily.
Input Requirements:
productIdentifier: The unique identifier of the product being queried.limit: The maximum number of results to return (default is 10).cursor: Used for pagination to retrieve the next set of results.rating: The rating score given by the user, typically ranging from 1 to 5.country: The ISO 3166-1 alpha-2 country code representing the user's region (default is 'us').language: The ISO 639-1 language code for the user's language preference (default is 'en').
Expected Output: The action returns a status, the product rating, an array of reviews, and insights about the reviews such as common themes and issues highlighted by users.
Use Cases:
- E-commerce Platforms: Enhance product detail pages with user-generated content and insights, helping potential buyers make informed decisions.
- Market Research: Analyze customer sentiments and feedback on products to adjust marketing strategies and inventory.
- Customer Support: Provide quick access to product reviews for customer service representatives to assist customers with queries.
```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 = "01f49b28-1cdf-4a29-98e6-f0fb28469bfd" # Action ID for: Fetch Product Reviews
# 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",
"productIdentifier": "11577822456427762145"
}
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("------------------------------------------------")
## Perform Google Shopping Search
The **Perform Google Shopping Search** action enables users to search for products on Google Shopping, offering options for pagination and filtering based on various criteria like price, store, and product condition. This action utilizes the latest Google Shopping US UI, ensuring comprehensive and reliable search results.
**Input Requirements:**
- `query`: The search term used to look up products (default is 'Nike shoes').
- `limit`: Specifies the maximum number of results to return (default is 10).
- `sortBy`: Determines how the results should be ordered (options: BEST_MATCH, LOWEST_PRICE, HIGHEST_PRICE).
- `stores`: Filters results by specific stores, provided as a comma-separated list of store names.
- `language`: Specifies the language in which the results are returned (default is 'en').
- Additional filters such as `onSale`, `maxPrice`, `minPrice`, and `productCondition` can also be applied.
**Expected Output:**
The action returns a list of products matching the search criteria, along with relevant filters that can be applied to narrow down results further.
**Use Cases:**
- **Product Comparison Tools**: Allow users to compare prices from multiple retailers to find the best deals.
- **Dynamic E-commerce Listings**: Automatically populate product listings on your website based on real-time availability and pricing from Google Shopping.
- **Personalized Shopping Experiences**: Implement advanced filtering options to enhance user experience based on preferences and past behavior.
```plaintext
```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 = "9d0c6751-24ca-449a-ac8d-1bf6b3d2ff45" # Action ID for: Perform Google Shopping Search
# Construct the exact input payload based on the action's requirements
# This example uses the predefined example_input for this action:
payload = {
"limit": 10,
"query": "Nike shoes",
"sortBy": "BEST_MATCH",
"language": "en",
"pageNumber": 1,
"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("------------------------------------------------")
## Retrieve Store Reviews with Pagination
The **Retrieve Store Reviews with Pagination** action allows developers to fetch all reviews for specific stores or merchants, supporting pagination to manage large datasets effectively. This action provides filtering options such as rating, country, duration, language, and ordering to tailor the review results to specific needs.
**Input Requirements:**
- `commerceDomain`: The domain of the e-commerce site to filter results by (default is 'amazon.com').
- `limit`: The maximum number of results to return (default is 10).
- `cursor`: A pagination token used to fetch the next set of results.
- `rating`: Filter results by rating (options include ALL, FIVE_STARS, FOUR_STARS, etc.).
- `country`: The country code to filter results by (default is 'us').
- `duration`: Filter results based on their duration, such as ALL, ONE_YEAR, or TWO_YEARS.
- `language`: The language code for the results (default is 'en').
- `ordering`: Defines the order of the results (options include MOST_HELPFUL or MOST_RECENT).
**Expected Output:**
The action returns a status, the store rating, the number of reviews, and an array of reviews based on the specified filters.
**Use Cases:**
- **Reputation Management**: Monitor and manage store reviews to maintain a positive brand image.
- **Consumer Insights**: Gather insights from reviews to understand customer satisfaction and areas for improvement.
- **Enhanced User Experience**: Provide users with access to up-to-date reviews, helping them make informed decisions when shopping.
```plaintext
```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 = "ed340749-1b45-457a-ae53-e9d159442837" # Action ID for: Retrieve Store 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,
"rating": "ALL",
"country": "us",
"duration": "ALL",
"language": "en",
"ordering": "MOST_HELPFUL",
"commerceDomain": "amazon.com"
}
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 Real Time Product Search and Reviews API offers developers a robust set of tools to enhance e-commerce platforms. By integrating features like product searches, review fetching, and store review retrieval, developers can significantly improve the user experience, increase customer satisfaction, and gain valuable insights into market trends.
To get started, ensure you have your API key ready and explore how each action can be utilized to meet your specific business needs.