joshbalfour / node-cognitive-services

Microsoft® Cognitive Services SDK for Node.JS
https://www.microsoft.com/cognitive-services
MIT License
105 stars 45 forks source link

filterQueryParams not taken into account in bingVideoSearchV7 #80

Closed i4i4n closed 2 years ago

i4i4n commented 3 years ago

Expected Behavior

The following code

new bingVideoSearchV7({apiKey: "MY_KEY"})
      .search({
        parameters: {
          q: "some search",
          freshness: "Day",
        },
      });

should fetch relevant video results "discovered within the last 24 hours" because of the freshness parameter value.

Actual Behavior

The request fails with the message "Parameter "freshness" could not be found in the list of supported parameters", although the parameter is in the list of valid parameters.

Relevant Code

The bug seems to come from

var operation = {
      "path": "bing/v7.0/videos/search",
      "method": "GET",
      "headers": this.headers,
      "parameters": this.parameters.filter(function (p) {
             return p.name == 'cc' || p.name == 'count' || p.name == 'id' || p.name == 'mkt' || p.name == 'offset' || p.name == 'q' || p.name == 'safeSearch' || p.name == 'setLang' || p.name == 'textDecorations' || p.name == 'textFormat';
      }).concat(this.queryStringParams)
};

where queryStringParams is concatenated instead of filterQueryParams like in bingImageSearchV7 where the filter parameters work well.

Possible solution

var operation = {
      "path": "bing/v7.0/videos/search",
      "method": "GET",
      "headers": this.headers,
      "parameters": this.parameters.filter(function (p) {
             return p.name == 'cc' || p.name == 'count' || p.name == 'id' || p.name == 'mkt' || p.name == 'offset' || p.name == 'q' || p.name == 'safeSearch' || p.name == 'setLang' || p.name == 'textDecorations' || p.name == 'textFormat';
      }).concat(this.filterQueryParams)
};

Specifications

miparnisari commented 2 years ago

Thanks @i4nch1k ! Fixed in 1.2.6.