Bazaarvoice

Implementation

The bazaarvoice.service.ts file contains the implementation of all the bazaarvoice apis

Methods

The main methods doing actual api calls are lsited below refer - bazaarvoice.service.ts and bazaarvoice.store.ts

Note - we are not cosuming bazaarvoice endpoints directly, instead we are using the proxy provided through Apigee.

  1. getProductReviews
  2. getFilteredProductReviews
  3. getQuestionsAnswers
  4. submitReviewfeedback
  5. uploadPhoto
  6. uploadVideo
//----------------------------------- upload photo-----------------------------------------------//
 async uploadPhoto(file: File): Promise<any> {
    const end_point = `${API_ENDPOINTS.UPLOAD_PHOTO}`;
    const runtimeConfig = useRuntimeConfig();
    const query = {
      ApiVersion: this.api_version,
      ContentType: "review",
    };

    try {

      const formData = new FormData();
      formData.append("photo", file);

      const response = await useAjaxServer(
        `${runtimeConfig.public.bazaarvoiceApiUrl+end_point}?${this.queryBuilder(query)}`,
        {
          method: "post",
          params: formData,
        }
      );

      return response.Photo;
    } catch (err) {
      let errorMeta = { query, file, bazaarVoiceServiceError: true}

      customClientErrorHandler(
        err,
        'medium',
        'Bazaarvoice Service Error - trying to submit product reviews using submitProductReview()',
        errorMeta
      );
      throw err;
    }
  }

GetProductReviews

The params passed to this method determine the details of the reviews that are fetched. passing Comments, Questions, Authors, in includes gives us the question, comments along with auther details

Similarly passing Reviews in stats gives us the reviews stats detail that we show at the top of reviews section in PDP


//-------------------------- getProductReviews --------------------------//
async getProductReviews(product_id: number): Promise<any> {
    const runtimeConfig = useRuntimeConfig();
    const end_point = `${API_ENDPOINTS.REVIEWS}`;
    const query: Query = {
      apiVersion: this.api_version,
      Filter: `ProductId:${product_id}`,
      FilteredStats: "Reviews",
      Filter_Reviews: "contentlocale:eq:en_US,en_FR,en_PH,en_GB,en_GB",
      Stats: "Reviews",
      Include:"Products,Comments,Questions,Authors",
      Limit: 50
    };

    try {
      const response = await useAjaxServer(runtimeConfig.public.bazaarvoiceApiUrl+end_point, {
        query,         
    });

      if (response.HasErrors) {
        let errorMeta = {productId: product_id, query, bazaarVoiceServiceError: true}

        customClientErrorHandler(
          response.HasErrors,
          'medium',
          'Bazaarvoice Service Error - trying to fetch product reviews using getProductReviews()',
          errorMeta
        );
        return;
      }

      const productReviewsArray = response?.Results ?? [];

      if (productReviewsArray.length === 0) {
        return {
          productReviewsArray: [],
          numberOfReviews: 0,
          averageOverallRating: 0,
          secondaryRatingsAverages: {},
          secondaryRatingsAveragesOrder: [],
          reviewsWithPhotos: [],
        };
      }

   const productData = response?.Includes?.Products?.[product_id]?.FilteredReviewStatistics ?? {};

      const mappedReviews = await this.mapReviews(productReviewsArray, product_id);

      return {
        numberOfReviews: response?.TotalResults ?? 0,
        averageOverallRating: productData.AverageOverallRating,
        secondaryRatingsAverages: productData.SecondaryRatingsAverages,
        secondaryRatingsAveragesOrder:
          productData.SecondaryRatingsAveragesOrder,
        ratingDistribution: productData.RatingDistribution,
        qaStaticstics: response.Includes?.Products?.[product_id].QAStatistics,
        reviewsWithPhotos: this.filterReviewsWithPhotos(mappedReviews),
        totalReviews: response.TotalResults,
      };
    } catch (error) {
      let errorMeta = {productId: product_id, query, bazaarVoiceServiceError: true}

      customClientErrorHandler(
        error,
        'medium',
        'Bazaarvoice Service Error - trying to fetch filtered product reviews using getFilteredProductReviews()',
        errorMeta
      );
      throw error;
    }
  }

Copyright © 2026