Sep 07 2016 07:39 AM
I am trying to build a search-driven app using the new SharePoint Framework. Whenever I use the built-in HTTP client, I get a 500 error for search. The same GET request runs fine in the same browser session. I've run through SP framework tutorials on GitHub and the list requests work fine (in the same app) but search continues to return a 500 error.
Any pointers?
Here's a sample of my function trying to call search...
protected get searchHttpClientOptions(): IHttpClientOptions {
return {
headers: {
'Accept': 'application/json;odata=verbose',
'Content-Type': 'application/json;odata=verbose'
}
};
}
private _getSearchResults(): Promise<SPResults> { const httpOptions: IHttpClientOptions = this.searchHttpClientOptions; return this.context.httpClient.get(this.context.pageContext.web.absoluteUrl + `/_api/search/query?querytext='the'`, httpOptions) .then((response: Response) => { return response.json(); }); }
Sep 08 2016 07:42 AM
Have you tried this code from Chris O'Brien?
http://www.sharepointnutsandbolts.com/2016/08/async-rest-calls-promises-httpclient-jquery.html
seems that you need some kind of workaround when calling search API
// workaround for httpClient/search API issue.. headers: { "odata-version": "" }}
Seems not required if you use jQuery AJAX...
Let us know if it works.