Sample REST API Call from external site
Here is a sample REST API call using jQuery. This is for accessing the API from an external site (not your community site). It took me a long time to get the syntax right (with the help of Lithium Customer Support), so I wanted to share it here.
//Authenticate
$.post("https://yourcommunity.com/yourcommunityid/restapi/vc/authentication/sessions/login", { "user.login": 'username', "user.password": 'password'}, function(document,err,responseData) {
xml = responseData.responseText;
xmlDoc = $.parseXML( xml );
xml = $( xmlDoc );
sessionKey = xml.find( "value" ).text();
});
//Get Info
$.post('https://yourcommunity.com/yourcommunityid/restapi/vc/boards/id/force/threads/latest', { "restapi.session_key": sessionKey}, function(document,err,responseData){
xml = responseData.responseText;
xmlDoc = $.parseXML( xml ),
xml = $( xmlDoc ),
xml.find("thread").each(function(){
var thread_title = $(this).find("title").text();
$("ul.featured_topics").append("<li>" + thread_title + "</li>")
});
});
Note: To make rest api calls from external domains, you must ask Lithium support to add them to a safe list.