2

I have successfully install this module Reviews/Rating I call this url="/V1/review/mine/post" method="POST".I don't know what data is passed in body of this URL.

3

1 Answer 1

1

If you inspect the module code etc/webapi.xml you will see following code

<route url="/V1/review/mine/post" method="POST">
    <service class="Ipragmatech\Ipreview\Api\ReviewInterface" method="writeReviews"/>
    <resources>
        <resource ref="self" />
    </resources>
    <data>
        <parameter name="customer_id" force="true">%customer_id%</parameter>
    </data>
</route>

And API signature in \Ipreview\Api\ReviewInterface

 /**
     * Added review and rating for the product.
     * @param int $productId
     * @param string $title
     * @param string $nickname
     * @param string $detail
     * @param Ipragmatech\Ipreview\Api\Data\RatingInterface[] $ratingData
     * @param int $customer_id
     * @param int $store_id
     * @return boolean
     *
     */
    public function writeReviews(
        $productId,
        $nickname,
        $title,
        $detail,
        $ratingData,
        $customer_id = null,
        $storeId
    );

So whenever you are setting ref as self the data will be taken from the token passed as bearer token and data node below it specify which data has to be taken form the the token . In above case it is customer ID , it also can be token . $customer_id will be taken from token and rest of the params can be passed in below body format

{
            "productId": "10",
            "nickname": "Mann",
            "title": "Cool, Nice product",
            "detail": "This is nice product. I recommended this product.",
            "ratingData": [{
                "rating_id": "3",
                "ratingCode": "price",
                "ratingValue": "5"
            }, {
                "rating_id": "4",
                "ratingCode": "Rating",
                "ratingValue": "2"
            }],
            "storeId": "1"
         }
4
  • I will pass this data as following: {"productId":"8","nickname":"lovely","title":"Nice Product","detail":"This is nice product","ratingData":[{"ratingValue":"2"}],"storeId":"1"}.But its showing error :[{"status":false,"message":"We can't post your review right now. SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'value' cannot be null, query was: INSERT INTO rating_option_vote (option_id, review_id, percent, value, remote_ip, remote_ip_long, customer_id, entity_pk_value, rating_id) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?)"}]. Commented May 10, 2018 at 8:15
  • @LovelySetia updated the answer , Please accept the answer if it works for you Commented May 10, 2018 at 8:59
  • it is throwing the same error for me too, what code changes needs to be done?
    – sahana
    Commented Sep 26, 2018 at 5:51
  • is that plugin is support for the Magento 2.3.0 Commented Jul 4, 2019 at 8:01

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.