rate(props: TRateProps): Promise<TResponseStatus | undefined>¶
The rate
is an asynchronous method which allows to rate a given product.
Input parameters¶
props¶
props
is an object of the TRateProps
type which contains the following fields:
productId
-string
an ID of the product we want to raterating
-number
a number represents between 1 and 5 representing the rating we want to add to a given productchallenge
-string
the Recaptcha value sent if Recaptcha is configured and active in the shop. Read more about Recaptcha V3 in the Recaptcha API documentation page
Returned value¶
A returned value has a type of Promise<TResponseStatus | undefined>
. Find out more about TResponseStatus type here.
Event Bus events¶
This API method dispatches the following events with the Event Bus:
- FlashMessengerApi.addFlashMessage - when handling messages that come from a server
- FlashMessengerApi.addFlashMessages - when handling messages that come from a server
Example¶
In this example we make a RateAndReviewApi
call to rate the given product.
useStorefront((storefront) => {
const rateAndReviewApi = await storefront.getApi('rateAndReviewApi');
await rateAndReviewApi.rate({ productId: "145", rating: 5, challenge: "xYz" });
});