Gravatar for

Question by Lautaro Bonetto, Aug 6, 2014 6:26 PM

Could I request JSON data on Front-end server from outside of JS Search interface?

Hi. The search page of my project is implemented using JS Framework of Coveo. We have a Front-End server that provide us the indexed data on JSON format.

When the search page renders the items on the HTML, other async JS functions are triggered to fill some pending data. We're taking an ID data on the rendered items and we're querying the JSON of the Front-End server again for other extra data.

To do this, we're using a regular AJAX qurey by JQuery. Like this one:

var exampleData = [];
function RetrieveSubBrands() {
    return $.ajax({
        type: 'GET',
        crossDomain: true,
        url: 'http://localhost:8080/Coveo/Rest/',
        data: { 'aq': '(@syscollection=="TestCollection")' },
        dataType: 'jsonp',
        success: function (jsonData) {
            $.each(jsonData.results, function (i, item) {
                exampleData[i] = {
                    Image: item.raw.image,
        error: function () {
            alert('Error loading data from Coveo');

I'm pretty sure that there is a way to do this easily using the Coveo JS Framework, but I didn't find a place with some example about how to do this. I should retrieve more data from Coveo without change the main search that the user did.

Please, could you provide me an example about how to do this in that way?


1 Reply
Gravatar for

Answer by olamothe, Aug 6, 2014 6:57 PM

Here is a general setup that should help you get going.

First, keep a reference to your Coveo Search Endpoint object that you created at the initialization of your page. To keep things simple, i'll put every variable in the global scope of the page. Obviously you could scope your stuff as you see fit :

var myEndpoint = new Coveo.Rest.SearchEndpoint({
    restUri : '',

Coveo.Rest.SearchEndpoint.endpoints["default"] = myEndpoint;

Now we could use the endpoint object to do something like this

var queryBuilder = new Coveo.Ui.QueryBuilder();

Check for all the info about this object Here we'll just add an advanced expression, but you could use it to build a very complicated query.

var query =;
var deferred =; 

The search method returns a jquery deferred object

          The parameters reponse and all it's properties are documented here 

          So you could loop on response.results, for example.
      //handle failures
Gravatar for

Comment by Lautaro Bonetto, Aug 6, 2014 7:02 PM

Thanks! This will help me alot.

Ask a question