<br />

This tutorial shows you how to list, return, reply, and delete a review. The
Google My Business API provides you with the ability to work with review data to
perform the following operations:

- [List all reviews](https://developers.google.com/my-business/content/review-data#list-all-reviews).
- [Get a specific review](https://developers.google.com/my-business/content/review-data#get-a-specific-review).
- [Get reviews from multiple locations](https://developers.google.com/my-business/content/review-data#get-reviews-from-multiple-locations).
- [Reply to a review](https://developers.google.com/my-business/content/review-data#reply-to-a-review).
- [Delete a review reply](https://developers.google.com/my-business/content/review-data#delete-a-review-reply).

## Before you begin

Before you use the Google My Business API, you need to register your
application and obtain OAuth 2.0 credentials. For details on how to get started
with the Google My Business API, see
[Basic setup](https://developers.google.com/my-business/content/basic-setup).

## List all reviews

List all reviews of a location to audit reviews in bulk. Use the
[accounts.locations.reviews.list](https://developers.google.com/my-business/reference/rest/v4/accounts.locations.reviews/list)
API to return all of the reviews associated with a location.

To return all reviews associated with a location, use the following:
HTTP

```
GET
https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews
```
Java

The following function uses `Mybusiness.Accounts.Locations.Reviews.List`.

```java
/**
 * Returns a list of reviews.
 * @param locationName Name of the location to retrieve reviews for.
 * @return List<Reviews> A list of reviews.
 * @throws Exception
 */
public static List<Review> listReviews(String locationName) throws Exception {
  Mybusiness.Accounts.Locations.Reviews.List reviewsList =
    mybusiness.accounts().locations().reviews().list(locationName);
  ListReviewsResponse response = reviewsList.execute();
  List<Reviews> reviews = response.getReviews();

  for (Reviews review : reviews) {
    System.out.println(review.toPrettyString());
  }
  return reviews;
}
```

## Get a specific review

Return a specific review by name. Use the
[accounts.locations.reviews.get](https://developers.google.com/my-business/reference/rest/v4/accounts.locations.reviews/get)
API to return a specific review associated with a location.

> [!NOTE]
> **Note:** `accounts.locations.reviews.get` doesn't currently return the [reviewReplyState](https://developers.google.com/my-business/reference/rest/v4/accounts.locations.reviews#ReviewReply) or [policyViolation](https://developers.google.com/my-business/reference/rest/v4/accounts.locations.reviews#PolicyViolation) fields of a review reply. To retrieve these fields, use [accounts.locations.reviews.list](https://developers.google.com/my-business/reference/rest/v4/accounts.locations.reviews/list) or [accounts.locations.batchGetReviews](https://developers.google.com/my-business/reference/rest/v4/accounts.locations/batchGetReviews).

To return a specific review, use the following:
HTTP

```
GET
https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews/{reviewId}
```
Java

The following function uses `Mybusiness.Accounts.Locations.Reviews.Get`.

```java
/**
 * Demonstrates getting a review by name.
 * @param reviewName The name (resource path) of the review to retrieve.
 * @return Account The requested review.
 */
private static Review getReview(String reviewName) throws Exception {
  Mybusiness.Accounts.Locations.Reviews.Get review =
      mybusiness.accounts().locations().reviews().get(reviewName);
  Review response = review.execute();

  return response;
}
```

### Additional data

The Java Client Library gives you access to additional field data for review
instances. Use the following methods to return additional data about reviews:

- `getReviewId()`
- `getComment()`
- `getReviewer()`
- `getStarRating()`
- `getCreateTime()`
- `getReviewReply()`

## Get reviews from multiple locations

Get reviews from multiple locations. Use the
[accounts.locations.batchGetReviews](https://developers.google.com/my-business/reference/rest/v4/accounts.locations/batchGetReviews)
API to return reviews from multiple locations in a single request.

To return reviews from multiple locations, use the following:
HTTP

<br />

```
POST
https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations:batchGetReviews

{
  "locationNames": [
    string
  ],
  "pageSize": number,
  "pageToken": string,
  "orderBy": string,
  "ignoreRatingOnlyReviews": boolean
}
```

<br />

<br />

## Reply to a review

> [!NOTE]
> **Important:** In order to use this functionality, you need to ensure that your G Suite Organization Administrator has enabled Google Search and/or Google Maps as services for your account, along with Business Profile. If you experience any issues, contact your Administrator. To learn more, see [Who is my administrator?](https://support.google.com/a/answer/6208960), [Control who can access G Suite and Google services](https://support.google.com/a/answer/182442), and [Apply policies to different users](https://support.google.com/a/topic/1227584).

Reply to a specific review, or create a new reply if one doesn't exist. Use the
[accounts.locations.reviews.updateReply](https://developers.google.com/my-business/reference/rest/v4/accounts.locations.reviews/updateReply)
API to reply to a specific review associated with a location.

To reply to a specific review, use the following:
HTTP

```
PUT
https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews/{reviewId}/reply

{
  "comment": "Thank you for visiting our business!"
}
```
Java

The following function uses `Mybusiness.accounts.locations.reviews.reply`.

```java
/*
 * Updates the reply for a location review.
 * If a review does not exist, creates a new one.
 * @param reviewName Name of the review being responded to.
 * @param comment A string containing the review response body.
 * @throws IOException
 */
private static Reply reply(String reviewName, String comment) throws IOException {

  MyBusiness.Accounts.Locations.Reviews.Reply reply =
    mybusiness().accounts().locations().reviews().reply(reviewName, comment);

  Reply response  = reply.execute();

  return response;
}
```

## Delete a review reply

Delete a reply to a specific review. Use the
[accounts.locations.reviews.deleteReply](https://developers.google.com/my-business/reference/rest/v4/accounts.locations.reviews/deleteReply)
API to delete a reply to a specific review associated with a location.

To delete a specific reply to a review, use the following:
HTTP

```
DELETE
https://mybusiness.googleapis.com/v4/accounts/{accountId}/locations/{locationId}/reviews/{reviewId}/reply
```
Java

The following function uses `Mybusiness.Accounts.Locations.Reviews.DeleteReply`.

```java
/**
 * Demonstrates deleting a review reply by name.
 * @param reviewName The name (resource path) of the review reply to delete.
 * @return Account The requested review.
 */
private static DeleteReply deleteReply(String reviewName) throws Exception {
  Mybusiness.Accounts.Locations.Reviews.DeleteReply toDelete =
      mybusiness.accounts().locations().reviews().deleteReply(reviewName);
  DeleteReply response = toDelete.execute();

  return response;
}
```