1

can we query SOSL using REST API? As we can do with SOQL like this : /services/data/v37.0/query/?q=

2 Answers 2

6

Yes you can do SOSL query using REST Api.

The api would be - /services/data/v37.0/search/?q=SOSL search string

The SOSL search string needs to be URL encoded.

Here is a link for more details - SOSL Search using REST API

Here is an way how you can make a successful REST API call.

String salesforceHost = System.Url.getSalesforceBaseURL().toExternalForm();

String url =  salesforceHost + '/services/data/v37.0/search/?q='+EncodingUtil.urlEncode('FIND {Joe Smith} IN Name Fields RETURNING lead', 'UTF-8'); // use your own SOSL statement

HttpRequest req = new HttpRequest();

req.setMethod('GET');
req.setEndpoint(url);
req.setHeader('Content-type', 'application/json');
req.setHeader('Authorization', 'OAuth ' + UserInfo.getSessionId());

Http http = new Http();

HTTPResponse res = http.send(req);
System.debug('res'+res.getbody());
2
0

Thanks all.. BUt I found solution for that also /services/data/v37.0/ParametrisedSearch/?q= isTest

1
  • Can you add details on this. Just one liner won't help others having same issue.
    – Reshma
    Mar 1, 2017 at 9:39

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .