0
# Merchant Reviews Management
1
2
Complete functionality for managing merchant reviews through the Google Shopping Merchant Reviews API. This service enables CRUD operations on merchant reviews, including creation, retrieval, listing with pagination, and deletion.
3
4
## Capabilities
5
6
### Client Initialization
7
8
Create merchant reviews service clients with authentication and configuration options.
9
10
```python { .api }
11
class MerchantReviewsServiceClient:
12
def __init__(
13
self,
14
*,
15
credentials: Optional[ga_credentials.Credentials] = None,
16
transport: Optional[Union[str, MerchantReviewsServiceTransport, Callable]] = None,
17
client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None,
18
client_info: gapic_v1.client_info.ClientInfo = None
19
):
20
"""
21
Initialize the merchant reviews service client.
22
23
Args:
24
credentials: Google authentication credentials
25
transport: Transport to use for communication ('grpc', 'grpc_asyncio', 'rest', or transport instance)
26
client_options: Client configuration options
27
client_info: Client information for user agent
28
"""
29
30
class MerchantReviewsServiceAsyncClient:
31
def __init__(
32
self,
33
*,
34
credentials: Optional[ga_credentials.Credentials] = None,
35
transport: Optional[Union[str, MerchantReviewsServiceTransport, Callable]] = None,
36
client_options: Optional[Union[client_options_lib.ClientOptions, dict]] = None,
37
client_info: gapic_v1.client_info.ClientInfo = None
38
):
39
"""
40
Initialize the async merchant reviews service client.
41
42
Args:
43
credentials: Google authentication credentials
44
transport: Transport to use for communication ('grpc_asyncio' or transport instance)
45
client_options: Client configuration options
46
client_info: Client information for user agent
47
"""
48
```
49
50
### Getting Individual Reviews
51
52
Retrieve a specific merchant review by its resource name.
53
54
```python { .api }
55
def get_merchant_review(
56
self,
57
request: Optional[Union[GetMerchantReviewRequest, dict]] = None,
58
*,
59
name: Optional[str] = None,
60
retry = gapic_v1.method.DEFAULT,
61
timeout = gapic_v1.method.DEFAULT,
62
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
63
) -> MerchantReview:
64
"""
65
Gets a merchant review.
66
67
Args:
68
request: The request object or dict containing the request fields
69
name: Required. Resource name format: accounts/{account}/merchantReviews/{merchantReview}
70
retry: Retry configuration for the request
71
timeout: Timeout for the request in seconds
72
metadata: Additional metadata for the request
73
74
Returns:
75
MerchantReview: The requested merchant review
76
77
Raises:
78
google.api_core.exceptions.NotFound: If the review is not found
79
google.api_core.exceptions.PermissionDenied: If access is denied
80
"""
81
82
async def get_merchant_review(
83
self,
84
request: Optional[Union[GetMerchantReviewRequest, dict]] = None,
85
*,
86
name: Optional[str] = None,
87
retry = gapic_v1.method.DEFAULT,
88
timeout = gapic_v1.method.DEFAULT,
89
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
90
) -> MerchantReview:
91
"""Async version of get_merchant_review."""
92
```
93
94
### Listing Reviews with Pagination
95
96
List merchant reviews for an account with automatic pagination support.
97
98
```python { .api }
99
def list_merchant_reviews(
100
self,
101
request: Optional[Union[ListMerchantReviewsRequest, dict]] = None,
102
*,
103
parent: Optional[str] = None,
104
retry = gapic_v1.method.DEFAULT,
105
timeout = gapic_v1.method.DEFAULT,
106
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
107
) -> ListMerchantReviewsPager:
108
"""
109
Lists merchant reviews for an account.
110
111
Args:
112
request: The request object or dict containing the request fields
113
parent: Required. Parent resource format: accounts/{account}
114
retry: Retry configuration for the request
115
timeout: Timeout for the request in seconds
116
metadata: Additional metadata for the request
117
118
Returns:
119
ListMerchantReviewsPager: Pager for iterating through reviews
120
121
Raises:
122
google.api_core.exceptions.InvalidArgument: If parent format is invalid
123
google.api_core.exceptions.PermissionDenied: If access is denied
124
"""
125
126
async def list_merchant_reviews(
127
self,
128
request: Optional[Union[ListMerchantReviewsRequest, dict]] = None,
129
*,
130
parent: Optional[str] = None,
131
retry = gapic_v1.method.DEFAULT,
132
timeout = gapic_v1.method.DEFAULT,
133
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
134
) -> ListMerchantReviewsAsyncPager:
135
"""Async version of list_merchant_reviews."""
136
```
137
138
### Inserting Reviews
139
140
Insert or replace a merchant review.
141
142
```python { .api }
143
def insert_merchant_review(
144
self,
145
request: Optional[Union[InsertMerchantReviewRequest, dict]] = None,
146
*,
147
retry = gapic_v1.method.DEFAULT,
148
timeout = gapic_v1.method.DEFAULT,
149
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
150
) -> MerchantReview:
151
"""
152
Inserts or replaces a merchant review.
153
154
Args:
155
request: The request object containing parent, merchant_review, and data_source
156
retry: Retry configuration for the request
157
timeout: Timeout for the request in seconds
158
metadata: Additional metadata for the request
159
160
Returns:
161
MerchantReview: The inserted merchant review
162
163
Raises:
164
google.api_core.exceptions.InvalidArgument: If request data is invalid
165
google.api_core.exceptions.PermissionDenied: If access is denied
166
"""
167
168
async def insert_merchant_review(
169
self,
170
request: Optional[Union[InsertMerchantReviewRequest, dict]] = None,
171
*,
172
retry = gapic_v1.method.DEFAULT,
173
timeout = gapic_v1.method.DEFAULT,
174
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
175
) -> MerchantReview:
176
"""Async version of insert_merchant_review."""
177
```
178
179
### Deleting Reviews
180
181
Delete a merchant review permanently.
182
183
```python { .api }
184
def delete_merchant_review(
185
self,
186
request: Optional[Union[DeleteMerchantReviewRequest, dict]] = None,
187
*,
188
name: Optional[str] = None,
189
retry = gapic_v1.method.DEFAULT,
190
timeout = gapic_v1.method.DEFAULT,
191
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
192
) -> None:
193
"""
194
Deletes a merchant review.
195
196
Args:
197
request: The request object or dict containing the request fields
198
name: Required. Resource name format: accounts/{account}/merchantReviews/{merchantReview}
199
retry: Retry configuration for the request
200
timeout: Timeout for the request in seconds
201
metadata: Additional metadata for the request
202
203
Raises:
204
google.api_core.exceptions.NotFound: If the review is not found
205
google.api_core.exceptions.PermissionDenied: If access is denied
206
"""
207
208
async def delete_merchant_review(
209
self,
210
request: Optional[Union[DeleteMerchantReviewRequest, dict]] = None,
211
*,
212
name: Optional[str] = None,
213
retry = gapic_v1.method.DEFAULT,
214
timeout = gapic_v1.method.DEFAULT,
215
metadata: Sequence[Tuple[str, Union[str, bytes]]] = ()
216
) -> None:
217
"""Async version of delete_merchant_review."""
218
```
219
220
### Helper Methods
221
222
Resource path construction and parsing utilities.
223
224
```python { .api }
225
@classmethod
226
def merchant_review_path(cls, account: str, name: str) -> str:
227
"""
228
Returns a fully-qualified merchant review string.
229
230
Args:
231
account: Account ID
232
name: Merchant review name/ID
233
234
Returns:
235
str: Resource path in format accounts/{account}/merchantReviews/{merchantReview}
236
"""
237
238
@classmethod
239
def parse_merchant_review_path(cls, path: str) -> Dict[str, str]:
240
"""
241
Parses a merchant review path.
242
243
Args:
244
path: Merchant review resource path
245
246
Returns:
247
Dict[str, str]: Dictionary with 'account' and 'merchant_review' keys
248
249
Raises:
250
ValueError: If path format is invalid
251
"""
252
253
@classmethod
254
def from_service_account_file(
255
cls,
256
filename: str,
257
*args,
258
**kwargs
259
) -> MerchantReviewsServiceClient:
260
"""
261
Creates a client from a service account file.
262
263
Args:
264
filename: Path to service account JSON file
265
*args: Additional arguments to pass to constructor
266
**kwargs: Additional keyword arguments to pass to constructor
267
268
Returns:
269
MerchantReviewsServiceClient: Configured client instance
270
"""
271
272
@classmethod
273
def from_service_account_info(
274
cls,
275
info: dict,
276
*args,
277
**kwargs
278
) -> MerchantReviewsServiceClient:
279
"""
280
Creates a client from service account info.
281
282
Args:
283
info: Service account info dictionary
284
*args: Additional arguments to pass to constructor
285
**kwargs: Additional keyword arguments to pass to constructor
286
287
Returns:
288
MerchantReviewsServiceClient: Configured client instance
289
"""
290
```
291
292
## Usage Examples
293
294
### Basic Review Management
295
296
```python
297
from google.shopping.merchant_reviews import (
298
MerchantReviewsServiceClient,
299
MerchantReview,
300
MerchantReviewAttributes,
301
InsertMerchantReviewRequest
302
)
303
from google.auth import default
304
from google.protobuf.timestamp_pb2 import Timestamp
305
import time
306
307
# Initialize client
308
credentials, project = default()
309
client = MerchantReviewsServiceClient(credentials=credentials)
310
311
# Create a new merchant review
312
review_attributes = MerchantReviewAttributes(
313
merchant_id="your-merchant-id",
314
merchant_display_name="Your Business Name",
315
content="Great service and fast delivery!",
316
rating=5.0,
317
min_rating=1,
318
max_rating=5,
319
reviewer_username="satisfied_customer",
320
reviewer_id="reviewer123",
321
collection_method=MerchantReviewAttributes.CollectionMethod.AFTER_FULFILLMENT
322
)
323
324
# Set review time
325
review_time = Timestamp()
326
review_time.FromSeconds(int(time.time()))
327
review_attributes.review_time = review_time
328
329
merchant_review = MerchantReview(
330
merchant_review_id="review-12345",
331
merchant_review_attributes=review_attributes
332
)
333
334
# Insert the review
335
request = InsertMerchantReviewRequest(
336
parent="accounts/your-account-id",
337
merchant_review=merchant_review,
338
data_source="accounts/your-account-id/dataSources/your-datasource-id"
339
)
340
341
result = client.insert_merchant_review(request=request)
342
print(f"Inserted review: {result.name}")
343
344
# List reviews
345
reviews = client.list_merchant_reviews(parent="accounts/your-account-id")
346
for review in reviews:
347
print(f"Review ID: {review.merchant_review_id}")
348
print(f"Rating: {review.merchant_review_attributes.rating}")
349
350
# Get specific review
351
review_name = f"accounts/your-account-id/merchantReviews/review-12345"
352
specific_review = client.get_merchant_review(name=review_name)
353
print(f"Retrieved review rating: {specific_review.merchant_review_attributes.rating}")
354
355
# Delete review
356
client.delete_merchant_review(name=review_name)
357
print("Review deleted")
358
```
359
360
### Async Operations
361
362
```python
363
import asyncio
364
from google.shopping.merchant_reviews import MerchantReviewsServiceAsyncClient
365
366
async def manage_reviews_async():
367
# Initialize async client
368
client = MerchantReviewsServiceAsyncClient()
369
370
# List reviews asynchronously
371
reviews = await client.list_merchant_reviews(
372
parent="accounts/your-account-id"
373
)
374
375
# Iterate through reviews
376
async for review in reviews:
377
print(f"Review ID: {review.merchant_review_id}")
378
if review.merchant_review_attributes.rating < 3.0:
379
# Handle low-rated reviews
380
print(f"Low rating detected: {review.merchant_review_attributes.rating}")
381
382
# Run async function
383
asyncio.run(manage_reviews_async())
384
```
385
386
### Pagination Handling
387
388
```python
389
# Handle pagination manually
390
parent = "accounts/your-account-id"
391
request = ListMerchantReviewsRequest(
392
parent=parent,
393
page_size=100 # Process 100 reviews at a time
394
)
395
396
while True:
397
response = client.list_merchant_reviews(request=request)
398
399
# Process current page
400
for review in response.merchant_reviews:
401
print(f"Processing review: {review.merchant_review_id}")
402
403
# Check if there are more pages
404
if not response.next_page_token:
405
break
406
407
# Set up request for next page
408
request.page_token = response.next_page_token
409
410
# Or use the pager (recommended)
411
pager = client.list_merchant_reviews(parent=parent)
412
for review in pager:
413
print(f"Review ID: {review.merchant_review_id}")
414
```
415
416
## Types
417
418
```python { .api }
419
# Request types
420
class GetMerchantReviewRequest:
421
name: str # Required: accounts/{account}/merchantReviews/{merchantReview}
422
423
class DeleteMerchantReviewRequest:
424
name: str # Required: accounts/{account}/merchantReviews/{merchantReview}
425
426
class ListMerchantReviewsRequest:
427
parent: str # Required: accounts/{account}
428
page_size: int # Optional: max 1000
429
page_token: str # Optional: pagination token
430
431
class InsertMerchantReviewRequest:
432
parent: str # Required: accounts/{account}
433
merchant_review: MerchantReview # Required: review to insert
434
data_source: str # Required: accounts/{account}/dataSources/{datasource}
435
436
# Response types
437
class ListMerchantReviewsResponse:
438
merchant_reviews: MutableSequence[MerchantReview]
439
next_page_token: str
440
@property
441
def raw_page(self) -> ListMerchantReviewsResponse: ...
442
```