Closed v-jaswel closed 5 years ago
Thanks for the bug report. I have routed to the appropriate team for follow-up.
The library needs be re-generated using the latest version of the code generator which should fix the problem with the baseuri
The library has been re-generated as part of #4955 and a new version has been published where this issue has been fixed
Thanks for working with Microsoft on GitHub! Tell us how you feel about your experience using the reactions on this comment.
Describe the bug CustomSearchClientContext (https://github.com/Azure/azure-sdk-for-js/blob/master/sdk/cognitiveservices/cognitiveservices-customsearch/src/customSearchClientContext.ts) does not set the base URI correctly (see line 42), so calls to the service fail.
To Reproduce Steps to reproduce the behavior:
const search = require('@azure/cognitiveservices-customsearch'); const auth = require("@azure/ms-rest-js");
if (!process.env.CUSTOM_SEARCH_SUBSCRIPTION_KEY) { throw 'Please set/export the following environment variable: CUSTOM_SEARCH_SUBSCRIPTION_KEY'; } let subscription_key = process.env.CUSTOM_SEARCH_SUBSCRIPTION_KEY;
/* For more information, see:
let query = 'xbox';
let credentials = new auth.ApiKeyCredentials({ inHeader: { 'Ocp-Apim-Subscription-Key': subscription_key } }); let client = new search.CustomSearchClient(credentials);
client.customInstance.search(instance_ID, query, function (err, result, request, response) { if (err) { console.log(err); } else { console.log(result.queryContext.originalQuery); console.log(result.webPages.value); } });
{ Error: Resource not found at new RestError (C:\Users\\node_modules\@azure\cognitiveservices-customsearch\node_modules\@azure\ms-rest-js\dist\msRest.node.js:1399:28)
at C:\Users\\node_modules\@azure\cognitiveservices-customsearch\node_modules\@azure\ms-rest-js\dist\msRest.node.js:2494:37
at process._tickCallback (internal/process/next_tick.js:68:7)
code: '404',
statusCode: 404,
request:
WebResource {
streamResponseBody: false,
url:
'https://api.cognitive.microsoft.com/search?customConfig=3b906310-44ac-40c8-b4d6-37194e2f8119&mkt=en-us&q=xbox',
method: 'GET',
headers: HttpHeaders { _headersMap: [Object] },
body: undefined,
query: undefined,
formData: undefined,
withCredentials: false,
abortSignal: undefined,
timeout: 0,
onUploadProgress: undefined,
onDownloadProgress: undefined,
proxySettings: undefined,
operationSpec:
{ httpMethod: 'GET',
path: 'search',
urlParameters: [Array],
queryParameters: [Array],
headerParameters: [Array],
responses: [Object],
serializer: [Serializer] } },
response:
{ body: '{"error":{"code":"404","message": "Resource not found"}}',
headers: HttpHeaders { _headersMap: [Object] },
status: 404 },
body:
{ _type: 'ErrorResponse',
error: { code: '404', message: 'Resource not found' } } }
[ { _type: 'WebPage', id: 'https://api.cognitive.microsoft.com/api/v7/#WebPages.0', name: 'Xbox Gaming Consoles: Xbox One X, Xbox One S, Gaming ...', url: 'https://www.microsoft.com/en-us/store/b/xbox', displayUrl: 'https://www.microsoft.com/en-us/store/b/xbox', snippet: ...
_this.baseUri = "{Endpoint}";
_this.baseUri = "{Endpoint}/bingcustomsearch/v7.0;