Skip to content

Commit 1e6b0f4

Browse files
author
Richard Gigan
committed
fix(FilePicker) : correction for Bing search image api endpoint #1256
1 parent 3478d79 commit 1e6b0f4

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

src/services/FilesSearchService.ts

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { BaseComponentContext } from '@microsoft/sp-component-base';
2-
import { SPHttpClient } from "@microsoft/sp-http";
2+
import { SPHttpClient, HttpClientResponse } from "@microsoft/sp-http";
33
import { ISearchResult, BingQuerySearchParams, IRecentFile } from "./FilesSearchService.types";
44
import { find } from "office-ui-fabric-react/lib/Utilities";
55
import { GeneralHelper } from "../common/utilities/GeneralHelper";
@@ -143,11 +143,14 @@ export class FilesSearchService {
143143
}
144144

145145
// Submit the request
146-
const apiUrl: string = `https://www.bingapis.com/api/v7/images/search?appid=${this.bingAPIKey}&traffictype=Internal_monitor&q=${encodeURIComponent(query)}&count=${maxResults}&aspect=${aspect}&maxFileSize=${maxFileSize}&size=${size}&mkt=en-US&license=${license}`;
146+
const apiUrl: string = `https://api.bing.microsoft.com/v7.0/images/search?q=${encodeURIComponent(query)}&count=${maxResults}&aspect=${aspect}&maxFileSize=${maxFileSize}&size=${size}&mkt=en-US&license=${license}`;
147147

148-
const searchDataResponse: any = await this.context.httpClient.get(apiUrl, SPHttpClient.configurations.v1, {
148+
const searchDataResponse: HttpClientResponse = await this.context.httpClient.get(apiUrl, SPHttpClient.configurations.v1, {
149149
method: 'GET',
150-
mode: 'cors'
150+
mode: 'cors',
151+
headers: {
152+
'Ocp-Apim-Subscription-Key': this.bingAPIKey,
153+
}
151154
});
152155

153156
if (!searchDataResponse || !searchDataResponse.ok) {

0 commit comments

Comments
 (0)