Results 1 to 2 of 2

Thread: [Javascript API] How to call webservices ?

Hybrid View

  1. #1
    Join Date
    Jul 2012
    Rep Power

    Default [SOLVED] How to call external webservices ?


    I can't find any good documentation about how to call webservices in javascript.

    I found API entries for sendRequest and AjxCallback but neither shows a code example about how to call webservices using those (if they're all that's needed).

    I also found this RSS Zimlet tutorial Develop an example RSS Zimlet - Zimbra :: Wiki but it doesn't explain enough the webservice part.

    Any suggestion really appreciated.
    Last edited by ychaouche; 09-10-2012 at 02:42 PM.

  2. #2
    Join Date
    Jul 2012
    Rep Power


    After a few days of battling with it... Now I know it works : you simply call the standard sendRequest method that is already implmented in the ZmZimletBase class.

    This is a complete working example that will show in a dialog the last entries of the RSS feed you set in the source code (this.feed_url, in the constructor).

    The most interresting parts of this code is the sendRequest function call in the singleClick handler and the callback function. All the rest is extra code to handle the display.

    So basically, all you need to do is call this.sendRequest giving it the following arguments :

    - requestString : if you need to pass in some request paramters, it should go here. For example "q=h&s=2043" will generate a url like "";
    - URL : the actual url you want to call, the sendRequest method automatically prefixes it with the proxy URL;
    - requestHeaders : this can be null;
    - a callback created via new AjxCallback() : this is just a wrapper around the function you want to call AFTER your ajax call returns. AjxCallback takes one, two or three arguments.

    o One argument : the function to call;
    o Two arguments : the object to bind "this" to when calling the function and the function itself
    o Three arguments : the object to bind "this" to, the function to call, and the arguments to pass to that function, third argument is always an array.

    The function you define as callback will always get at least one argument, which is the XML response from the Ajax request. If an error occurs, sendRequest handles it for you so you don't need to bother (an error dialog opens).

    yrss = function(){
        //this.feed_url = "";
        this.feed_url = "";
        this._callback = AjxCallback(this,this.callback);
        this.dialog = this._createDialog(); // Créer un dialog réutilisable
    yrss.prototype = new ZmZimletBase();
    yrss.prototype.contructor = yrss;
    yrss.prototype._createDialog = function(){
        // le dialog que nous allons utiliser
        var _dialog = appCtxt.getMsgDialog();
        // petite helper function;
        _dialog.setInfo = function(msg) {
    	// "this" inside this function is bound to this.dialog
        _dialog.showInfo = function(msg){
        return _dialog;
    yrss.prototype.singleClicked = function() {
        this.sendRequest("",this.feed_url,null,new AjxCallback(this,this.callback));
    _response = null;
    yrss.prototype.callback = function(response){
        _response = response;
        var html 	    = "";
        var item 	    = null;
        var description = null;
        var date        = null;
        var link        = null;
        var title       = null;
        var items       = response.xml.getElementsByTagName("item");
        for (var i=0;i<items.length;i++){
    	item           = items[i];
    	item.get_value = get_value;
    	description    = item.get_value("description");
    	date           = item.get_value("pubDate");
    	link           = item.get_value("link");
    	title          = item.get_value("title");
    	html          += "<em>"+date+"</em> <a target='_blank' href='"+link+"'>"+title+"</a><br/>"
    // helper function
    get_value = function(node_name){
        // get the value of a single leaf node;
        return this.getElementsByTagName(node_name)[0].firstChild.nodeValue;
    it's a panel zimlet

    <zimlet name="yrss" version="0.1" description="Exemple d'appels de webservice en REST">
      <zimletPanelItem icon="rss-icon" label="Y!Rss">
    Last edited by ychaouche; 09-11-2012 at 08:44 AM.

Similar Threads

  1. Click-to-call
    By deborahxxx in forum Installation Help
    Replies: 0
    Last Post: 03-26-2011, 02:46 PM
  2. How to call a normal javascript in the zimlet?
    By anuradha_mihsra in forum Zimlets
    Replies: 1
    Last Post: 01-19-2009, 06:43 AM
  3. can't call with skype ?
    By Urs in forum Zimlets
    Replies: 5
    Last Post: 03-11-2008, 08:58 AM
  4. Transaction support for WebServices ?
    By marinew in forum Developers
    Replies: 0
    Last Post: 01-25-2008, 05:32 AM
  5. administration by webservices
    By ghand11 in forum Administrators
    Replies: 0
    Last Post: 08-06-2007, 01:02 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts