I am trying to call search REST apis from an spfx webpart, but I am getting this:
My code looks like this:
let query = `${this.context.pageContext.web.absoluteUrl}/_api/search/query?querytext=%27*%27`
this.context.spHttpClient.get(query, SPHttpClient.configuration.v1)
.then(response: SPHttpClientResponse) => { console.log(response) })
.catch(error => { console.log(error) })
I am testing the webpart using the workbench under _layouts, and I can verify that the query is valid, and I could paste it in browser and see the results, it just doesn't work from code.
Update:
I had a look at the logs (am using sp 2016 feature pack 2). and I saw this in the logs after I try to load my webpart:
Parent=Request (GET:http://server/_api/search/query?querytext='*') System.NullReferenceException: Object Reference not set to an instance of an object
at
Microsoft.SharePoint.Client.Odata.ODataSerializeUtility.ConvertKeyValueToODataValue(String key, Object value, ProxyContext proxyContext)
any idea?
${this.context.pageContext.web.absoluteUrl}/_api/search/query?querytext='*'