Skip to content

Product Review API #9570

@okorshenko

Description

@okorshenko

Overview

Currently, Magento 2 does not provide the REST API for the Reviews Extension of the products. In scope of this task we would implement WebAPI for product reviews and integrate review API into existing core modules

Resources

Resource Request method Permissions Payload Response Implementation Description
/V1/reviews/:id GET Guest, Customer, Admin \Magento\Review\Api\Data\ReviewInterface \Magento\Review\Api\ReviewRepositoryInterface::get Get one review
/V1/reviews/:id PUT Admin \Magento\Review\Api\Data\ReviewInterface \Magento\Review\Api\ReviewRepositoryInterface::save Update review
/V1/reviews/:id DELETE Admin \Magento\Review\Api\ReviewRepositoryInterface::deleteById Delete review
/V1/reviews/ POST Guest, Customer, Admin \Magento\Review\Api\Data\ReviewInterface \Magento\Review\Api\Data\ReviewInterface \Magento\Review\Api\ReviewRepositoryInterface::save Create review
/V1/reviews/ GET Admin \Magento\Framework\Api\SearchCriteriaInterface \Magento\Review\Api\Data\ReviewInterface[] \Magento\Review\Api\ReviewRepositoryInterface::getList Search reviews
/V1/products/:sku/reviews GET Guest, Customer, Admin \Magento\Review\Api\Data\ReviewInterface[] \Magento\Review\Api\ReviewManagementInterface::getProductReviews Get product reviews
/V1/customers/me/reviews GET Customer \Magento\Review\Api\Data\ReviewInterface[] \Magento\Review\Api\ReviewManagementInterface::getCustomerReviews Get reviews created by current customer

Interfaces

\Magento\Review\Api\ReviewRepositoryInterface

namespace Magento\Review\Api;

interface ReviewRepositoryInterface
{
/**
* Save review.
*
* @param \Magento\Review\Api\Data\ReviewInterface $review
* @return \Magento\Review\Api\Data\ReviewInterface
* @throws \Magento\Framework\Exception\CouldNotSaveException
*/
public function save(\Magento\Review\Api\Data\ReviewInterface $review);

/**
 * Get review by id.
 *
 * @param int $id
 * @return \Magento\Review\Api\Data\ReviewInterface
 * @throws \Magento\Framework\Exception\NoSuchEntityException
 */
public function get($id);

/**
 * Delete review.
 *
 * @param \Magento\Review\Api\Data\ReviewInterface $review
 * @return bool
 * @throws \Magento\Framework\Exception\CouldNotDeleteException
 */
public function delete(\Magento\Review\Api\Data\ReviewInterface $review);

/**
 * Delete review by id.
 *
 * @param int $id
 * @return bool
 * @throws \Magento\Framework\Exception\CouldNotDeleteException
 */
public function deleteById($id);


/**
 * Lists the review items that match specified search criteria.
 *
 * @param \Magento\Framework\Api\SearchCriteria $searchCriteria
 * @return \Magento\Review\Api\Data\ReviewSearchResultInterface
 */
public function getList(\Magento\Framework\Api\SearchCriteria $searchCriteria);

}

\Magento\Review\Api\ReviewManagementInterface

namespace Magento\Review\Api;

interface ReviewManagementInterface
{
/**
* Get customer's reviews.
*
* @param int $customerId
* @return ReviewInterface[]
*/
public function getCustomerReviews($customerId);

/**
 * Get product reviews.
 *
 * @param string $sku
 * @return ReviewInterface[]
 */
public function getProductReviews($sku);

}

\Magento\Review\Api\Data\ReviewInterface

namespace Magento\Review\Api\Data;
 
interface ReviewInterface
{
    /**
     * Get review id.
     *
     * @return int
     /
    public function getId();
 
    /
*
     * Get Review title.
     *
     * @return string
     /
    public function getTitle();
 
    /
*
     * Get Review detail.
     *
     * @return string
     /
    public function getDetail();
 
    /
*
     * Get author nickname.
     *
     * @return string
     /
    public function getNickname();
 
    /
*
     * Get customer id.
     *
     * @return int|null
     /
    public function getCustomerId();
 
    /
*
     * Get review ratings.
     *
     * @return RatingInterface[]
     /
    public function getRatings();
 
    /
*
     * Get review entity type.
     *
     * @return string
     /
    public function getReviewEntity();
 
    /
*
     * Get reviewer type.
     * Possible values: 1 - Customer, 2 - Guest, 3 - Administrator.
     *
     * @return int
     /
    public function getReviewType();
 
    /
*
     * Get review status.
     * Possible values: 1 - Approved, 2 - Pending, 3 - Not Approved.
     *
     * @return int
     /
    public function getReviewStatus();
 
    /
*
     * Set review id.
     *
     * @param int $value
     * @return void
     /
    public function setId($value);
 
    /
*
     * Set Review title.
     *
     * @param string $value
     * @return void
     /
    public function setTitle($value);
 
    /
*
     * Set Review detail.
     *
     * @param void $value
     * @return void
     /
    public function setDetail($value);
 
    /
*
     * Set author nickname.
     *
     * @param string $value
     * @return void
     /
    public function setNickname($value);
 
    /
*
     * Set customer id.
     *
     * @param int|null $value
     * @return void
     /
    public function setCustomerId($value);
 
    /
*
     * Set review ratings.
     *
     * @param RatingInterface[] $value
     * @return void
     /
    public function setRatings($value);
 
    /
*
     * Set review entity type.
     *
     * @param string $value
     * @return void
     /
    public function setReviewEntity($value);
 
    /
*
     * Set review status.
     * Possible values: 1 - Approved, 2 - Pending, 3 - Not Approved.
     *
     * @param int $value
     * @return void
     /
    public function setReviewStatus($value);
 
    /
*
     * Set reviewer type.
     * Possible values: 1 - Customer, 2 - Guest, 3 - Administrator.
     *
     * @param int $value
     * @return string
     */
    public function setReviewType($value);
}

\Magento\Review\Api\Data\RatingInterface

namespace Magento\Review\Api\Data;

interface RatingInterface
{
/**
* Get rating id.
*
* @return int|null
*/
public function getId();

/**
 * Get review id.
 *
 * @return int
 */
public function getReviewId();

/**
 * Get rating code.
 *
 * @return string
 */
public function getAttributeCode();

/**
 * Get rating value.
 *
 * @return int
 */
public function getValue();

/**
 * Set rating id.
 *
 * @param int|null $value
 * @return void
 */
public function setId($value);

/**
 * Set review id.
 *
 * @param int $value
 * @return void
 */
public function setReviewId($value);

/**
 * Set rating code.
 *
 * @param string $value
 * @return void
 */
public function setAttributeCode($value);

/**
 * Set rating value.
 *
 * @param int $value
 * @return void
 */
public function setValue($value);

}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions