Broadleaf Microservices
  • v1.0.0-latest-prod

Ratings

Ratings allow users to give an indication of their satisfaction or the quality of a product. A rating summary is displayed on the top of the product detail page (PDP), while the rating breakdown and paginated list of ratings & reviews are at the bottom of the PDP. By default, only authenticated/logged-in users are allowed to leave ratings on PDPs.

List Ratings By Product Id

Operation

RatingsClient#listRatingsByProductId(productId, options);

Parameters

Parameter Type Required? Description

productId

string

The product id to retrieve rating details for

options

PageableClientCallOptions

Options passed to the HTTP request call to customize the pagination request configuration.

Response

This function returns a Page of Rating Details.

Example

Example of retrieving a page of rating details by a product id
const ratingDetails: Page<RatingDetail> = await ratingsClient.listRatingsByProductId(productId, {
  page: 0,
  size: 5,
  sort: "initialReviewDate,DESC"
});

console.log(ratingDetails);

List Ratings By Variant Id

Operation

RatingsClient#listRatingsByVariantId(productId, variantId, options);

Parameters

Parameter Type Required? Description

productId

string

The product id to retrieve rating details for

variantId

string

The variant id of the product

options

PageableClientCallOptions

Options passed to the HTTP request call to customize the pagination request configuration.

Response

This function returns a Page of Rating Details.

Example

Example of retrieving a page of rating details by a variant id
const ratingDetails: Page<RatingDetail> = await ratingsClient.listRatingsByVariantId(productId, variantId, {
  page: 0,
  size: 5,
  sort: "initialReviewDate,DESC"
});

console.log(ratingDetails);

Get Rating Detail

Operation

RatingsClient#getRatingDetail(detailId, options);

Parameters

Parameter Type Required? Description

detailId

string

The rating detail ID to fetch

options

ClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a Rating Detail.

Example

Example of retrieving a rating detail by detail id
const ratingDetail: RatingDetail = await ratingsClient.getRatingDetail(detailId);

console.log(ratingDetail);

List Customer Ratings

Operation

RatingsClient#listCustomerRatingDetails(customerId, options);

Parameters

Parameter Type Required? Description

customerId

string

The customer id to retrieve rating details for

options

PageableClientCallOptions

Options passed to the HTTP request call to customize the pagination request configuration.

Response

This function returns a Page of Rating Details.

Example

Example of retrieving a page of rating details by a customer id
const ratingDetails: Page<RatingDetail> = await ratingsClient.listCustomerRatingDetails(customerId, {
  page: 0,
  size: 5,
  sort: "initialReviewDate,DESC"
});

console.log(ratingDetails);

Submit Product Rating

Operation

RatingsClient#submitProductRating(productId, ratingRequest, options);

Parameters

Parameter Type Required? Description

productId

string

The product id to submit a rating for

ratingRequest

Rating Request

The rating information to be submitted and saved

options

ClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a Rating Detail.

Example

Example of submitting a rating detail by product id
const ratingDetail: RatingDetail = await ratingsClient.submitProductRating(productId, {
  rating: 4,
  customerId: "customer1",
  customerName: "Customer 1",
  reviewTitle: "Okay",
  review: "It was okay",
  ratingTargetId: "product1"
});

console.log(ratingDetail);

Submit Variant Rating

Operation

RatingsClient#submitVariantRating(productId, variantId, ratingRequest, options);

Parameters

Parameter Type Required? Description

productId

string

The product id to submit a rating for

variantId

string

The variant id to submit a rating for

ratingRequest

Rating Request

The rating information to be submitted and saved

options

ClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a Rating Detail.

Example

Example of submitting a rating detail by variant id
const ratingDetail: RatingDetail = await ratingsClient.submitVariantRating(productId, variantId, {
  rating: 4,
  customerId: "customer1",
  customerName: "Customer 1",
  reviewTitle: "Okay",
  review: "It was okay",
  ratingTargetId: "variant1"
});

console.log(ratingDetail);

Update Customer Rating

Operation

RatingsClient#updateCustomerRating(customerId, detailId, ratingRequest, options);

Parameters

Parameter Type Required? Description

customerId

string

The customer id of the author of the rating detail to update

detailId

string

The detail id of the rating detail to update

ratingRequest

Rating Request

The rating information to be updated and saved

options

ClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a Rating Detail.

Example

Example of updating a rating detail by customer id and detail id
const ratingDetail: RatingDetail = await ratingsClient.updateCustomerRating(customerId, detailId, {
  rating: 2,
  customerId: "customer1",
  customerName: "Customer 1",
  reviewTitle: "Changed my mind, it's bad",
  review: "x(",
  ratingTargetId: "variant1"
});

console.log(ratingDetail);

Delete Customer Rating

Operation

RatingsClient#deleteCustomerRating(customerId, detailId, options);

Parameters

Parameter Type Required? Description

customerId

string

The customer id of the author of the rating detail to delete

detailId

string

The detail id of the rating detail to delete

options

ClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns nothing.

Example

Example of deleting a rating detail by customer id and detail id
await ratingsClient.deleteCustomerRating(customerId, detailId);

Get Rating Summary By Product Id

Operation

RatingsClient#getRatingSummaryByProductId(productId, options);

Parameters

Parameter Type Required? Description

productId

string

The product id to retrieve the rating summary for

options

ClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a Rating Summary.

Example

Example of retrieving a rating summary by a product id
const ratingSummary: RatingSummary = await ratingsClient.getRatingSummaryByProductId(productId);

console.log(ratingSummary);

Get Rating Summary By Variant Id

Operation

RatingsClient#getRatingSummaryByVariantId(productId, variantId, options);

Parameters

Parameter Type Required? Description

productId

string

The product id to retrieve the rating summary for

variantId

string

The variant id to retrieve the rating summary for

options

ClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a Rating Summary.

Example

Example of retrieving a rating summary by a variant id
const ratingSummary: RatingSummary = await ratingsClient.getRatingSummaryByVariantId(productId, variantId);

console.log(ratingSummary);

List Rating Summary By Target Id

Operation

RatingsClient#listRatingSummaryByTargetIds(targetIds, options);

Parameters

Parameter Type Required? Description

targetIds

Array<string>

The target ids for the rating summaries to fetch

options

ClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a list of Rating Summaries.

Example

Example of retrieving a list of rating summaries by a list of target ids
const ratingSummaries: Array<RatingSummary> = await ratingsClient.listRatingSummaryByTargetIds(["product1", "product2", "variant1"]);

console.log(ratingSummaries);

List Rating Counts and Percentages

Operation

RatingsClient#listRatingCountAndPercentage(productId, options);

Parameters

Parameter Type Required? Description

productId

string

The id of the product to retrieve the rating counts and percentages for

options

ClientCallOptions

Options passed to the HTTP request call to customize the request configuration.

Response

This function returns a list of Rating Counts and Percentages.

Example

Example of retrieving a list of rating counts and percentages by a product id
const ratingCountsAndPercentages: Array<RatingCountAndPercentage> = await ratingsClient.listRatingCountAndPercentage(productId);

console.log(ratingCountsAndPercentages);