The best websites provide just enough information, delivered just when the user wants it.
When users search for a keyword or phrase on your website, you may want the website to display relevant search results for all sources – articles, blog posts, etc. If your company is using Zimbra (Telligent) Community, you may want results from your Zimbra community included.
Relevant search results from your Zimbra community can be incorporated into your website’s search results by taking advantage of Zimbra’s RESTful Web Services. REST (REpresentational State Transfer) is an approach for building application services that make resources available via a URL. A RESTful Web Service is a set of services that are implemented over HTTP using REST principles.
Zimbra’s RESTful Web Services use HTTP methods such as GET, POST, PUT, and DELETE. GET requests are used to request a list of entities or to show details for one entity. The GET method is used with Zimbra’s search result REST endpoint to return a list of content relevant to a search request. The search request results can be returned in Xml or json format.
The first step towards crafting your search request is to create a Web Client which includes the REST user token in the header. The REST user token consists of the user name of a community user with appropriate access rights and the API key for the community user. In the example below, we create a variable using the user name “johndoe” because he has administrative access rights to our Zimbra community. Consult Zimbra documentation if you do not know where to find the API key.
The next step is to build the URL for your request. The format of the URL is: [Zimbra community URL] + “api.ashx/v2/search.xml?query=[query string]”. If you want to receive the results in json rather than Xml, replace “search.xml” with “search.json”. Assuming the Zimbra community URL is http://mycompany.com/community and we are searching for content that contains the word “dog”, the URL for our request looks like:
Our last step is to request a response containing relevant results as follows:
Because we requested the response in Xml format, we then parse the response as follows:
To verify your Zimbra search is returning the results it should, log into your Zimbra community and enter the same search word or phrase in the search field.
Since Zimbra returns all items that meet the search criteria, i.e. images, posts, replies, comments – you may want to filter the results before displaying them on your web page. The ContentType node indicates what type of content the result contains:
Check out Zimbra’s RESTful API documentation to see more options for sharing information between your community and your website.