Forum Discussion

qinglau's avatar
qinglau
Mentor
14 years ago

Implementing federated search using RESETAPI

Hi All, 

 

I am a newbie in Lithium Reset API call. After I read the implementing federated search via RESET API ,, it states that the response will be XML format. I am wondering whether I can get reponse on JSON. Because we are using RightNow host, the simplexml disabled in RN's PHP binary. 

 

My question is that, does the response has to be XML or can covert to JSON?

 

Another option will be use YUI javascript to read XML? BUt I am not have much knowledge in this field.

 

 

Any suggestions are welcome.

 

 

Cheers,
Qing

7 Replies

  • AdamN's avatar
    AdamN
    Khoros Oracle
    14 years ago

    Hi Qing,

     

    It is possible to get the response as a JSON object. To do so, you will want to append the following query string paramter to your request:

     

    xslt=json.xsl


    For example, to get the JSON object for a message you can use the following call:

    http://<your community url>/<your community id>/restapi/vc/messages/id/2776?xslt=json.xsl

    I hope this helps!

  • qinglau's avatar
    qinglau
    Mentor
    14 years ago

    Hello Guys,


    Thanks all the help so far. We have kind of prove of concept of Federated search in RightNow page. 

     

    In order to complete the Function, I would like to know the return JSON object length. Does Lithium has a standard way to get "length" of JSON object, or i have to create a Function by myself, like:

     

    Function countProperties(obj) {
      var prop;
      var propCount = 0;
      
      for (prop in obj) {
        propCount++;
      }
      return propCount;
    }

     

     

    Thanks.

     

     

  • qinglau's avatar
    qinglau
    Mentor
    14 years ago
    Hello Guys,

    I have found that RightNow has a standard JSON.parse function. So, I can convert JSON into arrays, and get the length

    like
    var decodedStr = RightNow.JSON.parse(o.responseText);
    var newdata=decodedStr.response
    var length= newdata.messages.message.length;

    Thanks
  • qinglau's avatar
    qinglau
    Mentor
    14 years ago

    Hello All,

     

    I have some follow up questions.

     

    1.  Is there any ways for bring back only "accepted solution" response as a JSON object?

     

    According to the post here, it explain that it will need to threadID to make other calls. Like:

     

    http://<your community domain path>/restapi/vc/threads/id/thread_id .

     

    We would like avoid these complex implementation in RightNow end and also do not want increase RESETAPI page views.  BT has a perfect implementation in this case: http://bt.custhelp.com/app/home

     

    2. Get lastest "Accepted Solutions" VIA JSON object.

     

    Can we get the accepted solutions response as a JSON object, not XML

    http://lithosphere.lithium.com/t5/Customer-Connection-Private/Accepted-Solutions-via-REST/td-p/18648

     

    If yes, how the URL should look like?

     

    Thanks,

     

    Qing Liu

  • AdamN's avatar
    AdamN
    Khoros Oracle
    14 years ago

    Hi Qing,

     

    I'd suggest taking a look at the solutions/recent method on the Community object. I think this will give you what you're looking for. Here what the call looks like:

    <your base community URL>/restapi/vc/solutions/recent

     

    To get it as a JSON object, append the query string parameter:

    xslt=json.xsl

     

    So putting it all together, it would look like:

    <your base community URL>/restapi/vc/solutions/recent?xslt=json.xsl

     

    I hope this helps! Let me know if this didn't answer your questions.