Google Shopping Merchant Reviews API client library for managing merchant and product reviews
—
Comprehensive type system for the Google Shopping Merchant Reviews API including review objects, attributes, status information, and all request/response types.
Main data structures representing merchant and product reviews.
class MerchantReview:
"""
Represents a merchant review.
Attributes:
name: Resource identifier format: accounts/{account}/merchantReviews/{merchantReview}
merchant_review_id: User-provided unique ID for the review
merchant_review_attributes: Review attributes and content
custom_attributes: Additional custom attributes
data_source: Primary data source (output only)
merchant_review_status: Review status and validation info (output only)
"""
name: str
merchant_review_id: str
merchant_review_attributes: MerchantReviewAttributes
custom_attributes: MutableSequence[CustomAttribute]
data_source: str # Output only
merchant_review_status: MerchantReviewStatus # Output only
class ProductReview:
"""
Represents a product review.
Attributes:
name: Resource identifier format: accounts/{account}/productReviews/{productReview}
product_review_id: Permanent unique identifier for the review
product_review_attributes: Review attributes and content
custom_attributes: Additional custom attributes
data_source: Primary data source (output only)
product_review_status: Review status and validation info (output only)
"""
name: str
product_review_id: str
product_review_attributes: ProductReviewAttributes
custom_attributes: MutableSequence[CustomAttribute]
data_source: str # Output only
product_review_status: ProductReviewStatus # Output onlyDetailed attributes for merchant reviews including rating, content, and reviewer information.
class MerchantReviewAttributes:
"""
Attributes of a merchant review.
All fields are optional unless marked as required.
"""
merchant_id: str # Required: Unique and stable merchant identifier
merchant_display_name: str # Human-readable merchant display name
merchant_link: str # URL to merchant's main website
merchant_rating_link: str # URL to rating landing page
min_rating: int # Minimum possible rating number
max_rating: int # Maximum possible rating number
rating: float # Reviewer's overall rating of the merchant
title: str # Title of the review
content: str # Required: Freeform review text content
reviewer_id: str # Permanent unique reviewer identifier
reviewer_username: str # Display name of the reviewer
is_anonymous: bool # Whether the reviewer chooses to remain anonymous
collection_method: CollectionMethod # Method used to collect the review
review_time: Timestamp # Required: When the review was written (RFC 3339)
review_language: str # BCP-47 language code of the review
review_country: str # ISO 3166-1 Alpha-2 country code
class CollectionMethod(Enum):
"""Method used to collect the review."""
COLLECTION_METHOD_UNSPECIFIED = 0
MERCHANT_UNSOLICITED = 1 # Unsolicited review from merchant
POINT_OF_SALE = 2 # Review collected at point of sale
AFTER_FULFILLMENT = 3 # Review collected after order fulfillment
class MerchantReviewStatus:
"""
Status of the merchant review and any validation issues.
All fields are output only.
"""
destination_statuses: MutableSequence[MerchantReviewDestinationStatus] # Output only
item_level_issues: MutableSequence[MerchantReviewItemLevelIssue] # Output only
create_time: Timestamp # Output only: Creation date (ISO 8601)
last_update_time: Timestamp # Output only: Last update date (ISO 8601)
class MerchantReviewDestinationStatus:
"""Status for a specific destination."""
reporting_context: ReportingContext.ReportingContextEnum
class MerchantReviewItemLevelIssue:
"""Issue found with the merchant review."""
code: str # Issue code
severity: Severity # Issue severity level
resolution: str # Resolution status
attribute: str # Affected attribute
reporting_context: ReportingContext.ReportingContextEnum
description: str # Human-readable description
detail: str # Additional details
documentation: str # Link to documentation
class Severity(Enum):
"""Severity level of the issue."""
SEVERITY_UNSPECIFIED = 0
NOT_IMPACTED = 1 # Item not impacted
DISAPPROVED = 2 # Item disapprovedDetailed attributes for product reviews including product identification, rating, and reviewer information.
class ProductReviewAttributes:
"""
Attributes of a product review.
All fields are optional unless marked as required.
"""
aggregator_name: str # Name of the review aggregator
subclient_name: str # Name of the review subclient
publisher_name: str # Name of the review publisher
publisher_favicon: str # Link to the publisher's favicon (16x16 pixels)
reviewer_id: str # Permanent unique reviewer identifier
reviewer_is_anonymous: bool # Whether reviewer chooses to remain anonymous
reviewer_username: str # Display name of the reviewer
review_language: str # BCP-47 language code of the review
review_country: str # ISO 3166-1 Alpha-2 country code
review_time: Timestamp # Required: When review was written (RFC 3339)
title: str # Title of the review
content: str # Review text content
pros: MutableSequence[str] # Advantages based on reviewer opinion
cons: MutableSequence[str] # Disadvantages based on reviewer opinion
review_link: ReviewLink # URI to the review landing page
reviewer_image_links: MutableSequence[str] # URIs to reviewer images
min_rating: int # Minimum possible rating
max_rating: int # Maximum possible rating
rating: float # Reviewer's overall rating of the product
product_names: MutableSequence[str] # Descriptive product names
product_links: MutableSequence[str] # URIs to the reviewed products
asins: MutableSequence[str] # Amazon Standard Identification Numbers
gtins: MutableSequence[str] # Global Trade Item Numbers
mpns: MutableSequence[str] # Manufacturer Part Numbers
skus: MutableSequence[str] # Stock Keeping Units
brands: MutableSequence[str] # Brand names of the products
is_spam: bool # Whether the review is marked as spam
is_verified_purchase: bool # Whether the purchase is verified
is_incentivized_review: bool # Whether the review is incentivized
collection_method: CollectionMethod # Method used to collect review
transaction_id: str # Permanent unique transaction identifier
class CollectionMethod(Enum):
"""Method used to collect the review."""
COLLECTION_METHOD_UNSPECIFIED = 0
UNSOLICITED = 1 # Unsolicited review
POST_FULFILLMENT = 2 # Review collected after fulfillment
class ReviewLink:
"""Link to the review landing page."""
type_: ReviewLink.Type # Type of the review link
link: str # URI to the review
class Type(Enum):
"""Type of review link."""
TYPE_UNSPECIFIED = 0
SINGLETON = 1 # Link to a single review
GROUP = 2 # Link to a group of reviews
class ProductReviewStatus:
"""
Status of the product review and any validation issues.
All fields are output only.
"""
destination_statuses: MutableSequence[ProductReviewDestinationStatus] # Output only
item_level_issues: MutableSequence[ProductReviewItemLevelIssue] # Output only
create_time: Timestamp # Output only: Creation date (ISO 8601)
last_update_time: Timestamp # Output only: Last update date (ISO 8601)
class ProductReviewDestinationStatus:
"""Status for a specific destination."""
reporting_context: ReportingContext.ReportingContextEnum
class ProductReviewItemLevelIssue:
"""Issue found with the product review."""
code: str # Issue code
severity: Severity # Issue severity level
resolution: str # Resolution status
attribute: str # Affected attribute
reporting_context: ReportingContext.ReportingContextEnum
description: str # Human-readable description
detail: str # Additional details
documentation: str # Link to documentation
class Severity(Enum):
"""Severity level of the issue."""
SEVERITY_UNSPECIFIED = 0
NOT_IMPACTED = 1 # Item not impacted
DISAPPROVED = 2 # Item disapprovedAll request and response message types for API operations.
# Merchant Review Request Types
class GetMerchantReviewRequest:
"""Request to get a merchant review."""
name: str # Required: Resource name format: accounts/{account}/merchantReviews/{merchantReview}
class DeleteMerchantReviewRequest:
"""Request to delete a merchant review."""
name: str # Required: Resource name format: accounts/{account}/merchantReviews/{merchantReview}
class ListMerchantReviewsRequest:
"""Request to list merchant reviews."""
parent: str # Required: Parent resource format: accounts/{account}
page_size: int # Optional: Maximum number of results (up to 1000)
page_token: str # Optional: Page token for pagination
class InsertMerchantReviewRequest:
"""Request to insert a merchant review."""
parent: str # Required: Parent resource format: accounts/{account}
merchant_review: MerchantReview # Required: The merchant review to insert
data_source: str # Required: Data source format: accounts/{account}/dataSources/{datasource}
class ListMerchantReviewsResponse:
"""Response containing merchant reviews."""
merchant_reviews: MutableSequence[MerchantReview] # The merchant reviews
next_page_token: str # Token for retrieving the next page
@property
def raw_page(self) -> ListMerchantReviewsResponse:
"""Returns the raw page for pager support."""
# Product Review Request Types
class GetProductReviewRequest:
"""Request to get a product review."""
name: str # Required: Resource name format: accounts/{account}/productReviews/{productReview}
class DeleteProductReviewRequest:
"""Request to delete a product review."""
name: str # Required: Resource name format: accounts/{account}/productReviews/{productReview}
class ListProductReviewsRequest:
"""Request to list product reviews."""
parent: str # Required: Parent resource format: accounts/{account}
page_size: int # Optional: Maximum number of results per page
page_token: str # Optional: Page token for pagination
class InsertProductReviewRequest:
"""Request to insert a product review."""
parent: str # Required: Parent resource format: accounts/{account}
product_review: ProductReview # Required: The product review to insert
data_source: str # Required: Data source format: accounts/{account}/dataSources/{datasource}
class ListProductReviewsResponse:
"""Response containing product reviews."""
product_reviews: MutableSequence[ProductReview] # The product reviews
next_page_token: str # Token for retrieving the next page
@property
def raw_page(self) -> ListProductReviewsResponse:
"""Returns the raw page for pager support."""Common types used across the API.
class CustomAttribute:
"""Custom attribute for reviews."""
name: str # Attribute name
value: str # Attribute value
class ReportingContext:
"""Context for reporting."""
class ReportingContextEnum(Enum):
"""Reporting context enumeration."""
REPORTING_CONTEXT_ENUM_UNSPECIFIED = 0
SHOPPING_ADS = 1 # Shopping ads context
DISCOVERY_ADS = 2 # Discovery ads context
DEMAND_GEN_ADS = 3 # Demand generation ads context
DEMAND_GEN_ADS_DISCOVER_SURFACE = 4 # Demand generation ads discover surface
VIDEO_ADS = 5 # Video ads context
DISPLAY_ADS = 6 # Display ads context
LOCAL_INVENTORY_ADS = 7 # Local inventory ads context
VEHICLE_INVENTORY_ADS = 8 # Vehicle inventory ads context
FREE_LISTINGS = 9 # Free listings context
FREE_LOCAL_LISTINGS = 10 # Free local listings context
FREE_LOCAL_VEHICLE_LISTINGS = 11 # Free local vehicle listings context
YOUTUBE_SHOPPING = 12 # YouTube shopping context
CLOUD_RETAIL = 13 # Cloud retail context
LOCAL_CLOUD_RETAIL = 14 # Local cloud retail context
PRODUCT_REVIEWS = 15 # Product reviews context
MERCHANT_REVIEWS = 16 # Merchant reviews context
# Common protobuf types
class Timestamp:
"""Timestamp in RFC 3339 format."""
def FromSeconds(self, seconds: int) -> None:
"""Set timestamp from seconds since epoch."""
def ToSeconds(self) -> int:
"""Get timestamp as seconds since epoch."""
def FromDatetime(self, dt: datetime) -> None:
"""Set timestamp from datetime object."""
def ToDatetime(self) -> datetime:
"""Get timestamp as datetime object."""
# Type aliases for clarity
MutableSequence = List # Mutable sequence typefrom google.shopping.merchant_reviews import (
MerchantReview,
MerchantReviewAttributes
)
from google.protobuf.timestamp_pb2 import Timestamp
import time
# Create merchant review attributes
attributes = MerchantReviewAttributes()
attributes.merchant_id = "merchant-123"
attributes.merchant_display_name = "Best Electronics Store"
attributes.content = "Excellent customer service and fast delivery!"
attributes.rating = 4.8
attributes.min_rating = 1
attributes.max_rating = 5
attributes.reviewer_username = "satisfied_customer"
attributes.reviewer_id = "reviewer-456"
attributes.collection_method = MerchantReviewAttributes.CollectionMethod.AFTER_FULFILLMENT
# Set review time
review_time = Timestamp()
review_time.FromSeconds(int(time.time()))
attributes.review_time = review_time
# Create the merchant review
review = MerchantReview()
review.merchant_review_id = "review-789"
review.merchant_review_attributes = attributes
print(f"Created review with rating: {review.merchant_review_attributes.rating}")from google.shopping.merchant_reviews import (
ProductReview,
ProductReviewAttributes
)
# Create comprehensive product review attributes
attributes = ProductReviewAttributes()
attributes.reviewer_username = "tech_reviewer"
attributes.reviewer_id = "tech-reviewer-123"
attributes.title = "Amazing headphones with great sound quality"
attributes.content = "These headphones deliver exceptional audio quality with deep bass and clear highs..."
attributes.rating = 4.5
attributes.min_rating = 1
attributes.max_rating = 5
# Add product identification
attributes.product_names.extend(["Wireless Bluetooth Headphones", "Model WBH-2024"])
attributes.gtins.append("1234567890123")
attributes.brands.append("AudioTech")
attributes.mpns.append("WBH-2024-BLK")
# Add pros and cons
attributes.pros.extend([
"Excellent sound quality",
"Long battery life",
"Comfortable fit"
])
attributes.cons.extend([
"Could be more affordable",
"Limited color options"
])
# Set flags
attributes.is_verified_purchase = True
attributes.is_spam = False
attributes.collection_method = ProductReviewAttributes.CollectionMethod.POST_FULFILLMENT
# Set review time
review_time = Timestamp()
review_time.FromSeconds(int(time.time() - 86400)) # 1 day ago
attributes.review_time = review_time
# Create the product review
review = ProductReview()
review.product_review_id = "product-review-456"
review.product_review_attributes = attributes
print(f"Created product review for: {review.product_review_attributes.product_names[0]}")
print(f"Rating: {review.product_review_attributes.rating}")# Check merchant review status
merchant_review = client.get_merchant_review(name="accounts/123/merchantReviews/review-789")
if merchant_review.merchant_review_status:
status = merchant_review.merchant_review_status
print(f"Review created: {status.create_time}")
print(f"Last updated: {status.last_update_time}")
# Check for issues
if status.item_level_issues:
print("Issues found:")
for issue in status.item_level_issues:
print(f"- {issue.code}: {issue.description}")
if issue.severity == MerchantReviewStatus.MerchantReviewItemLevelIssue.Severity.DISAPPROVED:
print(" Warning: Review is disapproved!")
# Check product review status
product_review = client.get_product_review(name="accounts/123/productReviews/product-review-456")
if product_review.product_review_status:
status = product_review.product_review_status
print(f"Product review created: {status.create_time}")
# Check destination statuses
for dest_status in status.destination_statuses:
print(f"Destination context: {dest_status.reporting_context}")Install with Tessl CLI
npx tessl i tessl/pypi-google-shopping-merchant-reviews