I am trying to call search REST apis from an spfx webpart, but I am getting this:

GET http://servername/_api/search/query?querytext=%27*%27

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.


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


Microsoft.SharePoint.Client.Odata.ODataSerializeUtility.ConvertKeyValueToODataValue(String key, Object value, ProxyContext proxyContext)

any idea?

  • Have you tried with out encode url like ${this.context.pageContext.web.absoluteUrl}/_api/search/query?querytext='*' May 27, 2018 at 15:49
  • Hi, yes I did same result. May 27, 2018 at 15:53
  • Does it work in the browser? May 28, 2018 at 12:09
  • @MatthewMcDermott yes it works in the browser, but not from code. May 29, 2018 at 16:28
  • can you share the network panel info from your browser?
    – Arut
    May 29, 2018 at 20:09

1 Answer 1


You need add SelectProperties like as 'Title' or other and it will work from code.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.