Skip to main content

getReviews()

getReviews(params?): Promise<ErrorResult | SuccessResult<ReviewsSdkDto>>

Retrieves reviews for a specific product or all shop reviews with filtering and pagination options.

Parameters​

ParameterTypeDescription
params?GetReviewsParamsSdkDto(Optional) Parameters object for filtering and pagination

Returns​

Promise<ErrorResult | SuccessResult<ReviewsSdkDto>>

Promise that resolves to a success result with an array of reviews or rejects with an error

Example​

Ensure the SDK and the ReviewsSdk module are ready.

function onSdkReady() {
const moduleName = window.gw.sdk.common.constants.modules.REVIEWS;
window.gw.sdk.runIfModuleReady(moduleName, () => {
// Get reviews for a specific product with pagination
window.gw.sdk.reviews.methods.getReviews({
productId: 123,
perPage: 10,
offset: 0
})
.then((response) => {
console.log('Product reviews:', response.result);
})
.catch(console.error);

// Get shop reviews with filters
window.gw.sdk.reviews.methods.getReviews({
onlyShopReviews: true,
onlyWithMedia: true,
lowestRating: 4
})
.then((response) => {
console.log('Filtered shop reviews:', response.result);
})
.catch(console.error);

// Get reviews with no filters
window.gw.sdk.reviews.methods.getReviews()
.then((response) => {
console.log('Reviews:', response.result.items);
console.log('Total:', response.result.totalCount);
})
.catch(console.error);
});
}

if (window.gw && window.gw.sdk) {
onSdkReady();
} else {
document.addEventListener("gwSdkReady", onSdkReady);
}