Gravatar for divyadevi.devara@gmail.com

Question by divya, Nov 12, 2015 6:59 PM

Coveo Search API call

Hi,

With the new package upgrade of coveo, we have an AttachedResult object being inserted on attach of results. We are adding more fields to the same object in a trigger. To do this, we need other information of the result object. So we need to do an API call to coveo and get that specific result. Ex : https://cs12.salesforce.com/08730000000l3I9AAI This is the Result Url in the Attached Result object. 08730000000l3I9AAI is the ID I have to query for the result from Coveo. Is it really possible to do rest API call from trigger with the ID we have? If so, What all parameters I need to do a rest API call to get one result per Id. CoveoSolutions.CoveoGlobal.generateSearchToken(); This gives the search token. (Please confirm if this is right) What End point URL I need to set. Could you please provide an example..

Thanks and Regards, Divya

1 Reply
Gravatar for mlaporte@coveo.com

Answer by Martin Laporte, Nov 13, 2015 4:51 AM

For a Cloud deployment, the url to execute the query is https://cloudplatform.coveo.com/rest/search. You can pass the query either as a JSON body or through the query string. For example, in your case:

https://cloudplatform.coveo.com/rest/search?q=@sfid=08730000000l3I9AAI

would return the single result with the ID you mentionned.

Of course, you also need to authenticate yourself to the Cloud Platform. Search Tokens indeed are a way to do this, but I'm not sure how that'll behave in a trigger, but it certainly worth trying out. Otherwise you could obtain an API key for your Cloud index, but you'll need to ask our support to enable that particular feature for you. But do try with a search token first.

To pass the search token, the easiest way is to use a query string argument:

https://cloudplatform.coveo.com/rest/search?q=@sfid=08730000000l3I9AAI&access_token=your_search_token.

Gravatar for divyadevi.devara@gmail.com

Comment by divya, Nov 17, 2015 6:19 PM

Thankyou so much. It worked. I am able to get the response.

Thanks and Regards, Divya

Gravatar for divyadevi.devara@gmail.com

Comment by divya, Nov 19, 2015 3:17 PM

Hi,

Thanks for the help. I am able to get the single result per Id passed in request. But for Articles, we have around 19 results in response for each Id. I tried to filter it by passing language parameter. Still I got 19 results. Below is the url. https://cloudplatform.coveo.com/rest/search?q%3D%40sfid%3DkA1V00000005KqqKAE&language=fi&access_token=searchtoken

or https://cloudplatform.coveo.com/rest/search?q%3D%40sfid%3DkA1V00000005KqqKAE&lang=fi&access_token=searchtoken

I tried with below encoded url also. https://cloudplatform.coveo.com/rest/search?q%3D%40sfid%3DkA1V00000005KqqKAE%26language%3Dfi&access_token=searchtoken No results if I try this encoded url.

Please tell me if i am missing anything in the request for Articles.

Thanks and Regards, Divya

Gravatar for mlaporte@coveo.com

Comment by Martin Laporte, Nov 20, 2015 3:31 AM

Filtering by language would have to be done using a field expression in the q argument, something like @sflanguage==foo. Check the results you are receiving for the proper field names and values. The language passed through a separate query string argument doesn't filter results, it's only used to alter ranking and a few other purposes.

Gravatar for divyadevi.devara@gmail.com

Comment by divya, Nov 20, 2015 2:07 PM

Hi,

Here I need to get single result based on sfid and sflanguage. Is it possible to give 2 query parameters. I tried different ways like q=@sfid=ID&@sflanguage=foo q=@sfid=ID&ssflanguage=foo q=@sfid=ID:@sflanguage=foo etc. I am not successful in all these trials.

And In querying for articles I have one more issue. In Articles, AttachedResult url is like https://org62--csgqa1.cs12.my.salesforce.com/kA1V00000005KJh?lang=es The Id in the url is only 15 characters. But in the request url if I pass the same Id, I am not getting any result. If I give 18 character ID (kA1V00000005KJhKAM) then only I am getting 19 results. Is there any way to get single result using the 15 char ID and lang (kA1V00000005KJh?lang=es) which are available in the url. Please help.

Thanks and Regards, Divya

Gravatar for mlaporte@coveo.com

Comment by Martin Laporte, Nov 23, 2015 7:45 AM

The @sflanguage==x part of the query should be specified as part of the q query string argument:

…?q=@sfid=ID @sflanguage==foo

Gravatar for divyadevi.devara@gmail.com

Comment by divya, Nov 24, 2015 6:38 PM

Thankyou so much. Everything is working fine. I am able to get a single result for articles.

Ask a question