0

How I query magento 2 to get the ratings for the particular product. Any one can help me.

2 Answers 2

0

Assuming you are familiar with the graphQL queries that need to be used to retrieve data, and how Magento includes them using custom gql.js files (e.g. productFullDetail.gql.js), you could use the following query to retrieve product reviews:

query getProductReviews(
        $sku: String!
    ) {
        products(filter: { sku: { eq: $sku } }) {
            items {
                review_count
                rating_summary
                reviews {
                    items {
                        average_rating
                        summary
                        text
                        created_at
                        nickname
                    }
                }
            }
        }
    }

and just use the sku variable to switch between products:

{  
  "sku": "24-MB01"
}
4
  • Thanks for the response.Its work fine
    – Mahesh1343
    Commented Jun 14, 2021 at 6:04
  • How do we get the review filter by store id and except reviews that has the status of pending.
    – Mahesh1343
    Commented Oct 21, 2021 at 13:24
  • You cannot do that out-of-the-box with Magento's products query, because you can only filter using product attributes (not review attributes). So you would need a custom implementation with a custom resolver where you can input a product sku and the 'pending' status for example. Commented Oct 22, 2021 at 14:47
  • Thanks for the info
    – Mahesh1343
    Commented Oct 23, 2021 at 5:19
0

Please following API for getting product reviews.

{
    reviewsList(
        product_id:57573,
        pageSize:10,
        currentPage:1
    ){
        items {
            review_id
            title
            rating_summary
            images
            detail
            nickname
            created_at
        }
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.