Alokai
You are reading the documentation for SDK v2, which is no longer the latest version. Switch to current

deleteProductReview

Method deleting a product review.

This method sends a POST request to the deleteReview endpoint of the Vue Storefront API Middleware. In turn, it deletes a review from commercetools by sending a request to its GraphQL API. The default GraphQL query used by this method can be found here.

You might also want to see the getProductReviews and addProductReview methods.

Vue Storefont ships with a built-in mechanism ensuring reviews belonging to authenticated users can only be deleted by their authors. The method will throw an error when used to delete a review added by another user.

Signature

export declare function deleteProductReview<Res extends PartialDeleteReviewResponse = DeleteReviewResponse>(
	params: DeleteReviewParams,
	options?: MethodOptions<CustomQuery<"deleteReview">>
): Promise<Res>;

Parameters

NameRequiredTypeDescription
paramsRequiredDeleteReviewParamsParameter object which can be used with this method. Refer to its type definition to learn about possible properties.
optionsOptionalMethodOptions<CustomQuery<"deleteReview">>Options that can be passed to additionally configure the request or customize the logic in a plugin.

Returns

Returns a representation of the DeleteReviewResponse.

Referenced Types

Examples

Deleting a product review.

import { sdk } from '~/sdk.config.ts';

const { review } = await sdk.commerce.deleteProductReview({
  id: 'c9e9a3c8-547f-4bc0-907d-4805423e803b',
  version: 1
});

Creating a custom GraphQL query for the method in middleware.config.js.

module.exports = {
  integrations: {
    ct: {
      // ...
      customQueries: {
        'delete-product-review-custom-query': ({ query, variables, metadata }) => ({
           variables: Object.assign(variables, metadata?.variables),
           query: `
             mutation deleteReview($id: String, $version: Long!) {
               review: deleteReview(id: $id, version: $version) {
                 ${metadata?.fields}
               }
             }
           `
        }),
      }
    }
  }
};

Deleting a product review and selecting response fields using the custom GraphQL query from the previous example. Notice how we are using the type parameter to overwrite the default response interface.

import { sdk } from '~/sdk.config.ts';

type CustomDeleteReviewResponse = {
  review: {
    id: string;
    version: number;
  }
};

const { review } = await sdk.commerce.deleteProductReview<CustomDeleteReviewResponse>({
  id: 'c9e9a3c8-547f-4bc0-907d-4805423e803b',
  version: 1
}, {
  customQuery: {
    deleteReview: 'delete-product-review-custom-query',
    metadata: { fields: 'id,version' }
  }
});

On this page