Difference between revisions of "ZCS 6.0:Zimlet Developers Guide:Examples:SOAP API Basics"

(New page: {| cellspacing="0" cellpadding="5" style="border: 1px solid rgb(153, 153, 170); margin: 0pt 0.5em 0.5em 0pt; float: none; background-color: rgb(249, 249, 255);" |[[Image:zdg-6-menu-icon-zi...)
Line 139: Line 139:
{| cellspacing="0" cellpadding="5" border="1"
{| cellspacing="0" cellpadding="5" border="1"
|Zimlet Package
|Zimlet Package
|[http://files.zimbra.com/docs/zimlet/zcs/6.0/examples/com_zimbra_example_soap/com_zimbra_example_soap.zip com_zimbra_example_simpletab.zip]
|[http://files.zimbra.com/docs/zimlet/zcs/6.0/examples/com_zimbra_example_soap/com_zimbra_example_soap.zip com_zimbra_example_soap.zip]
== Useful Links ==
== Useful Links ==

Revision as of 06:37, 18 February 2010

Zdg-6-menu-icon-zimbra.jpg Introduction Zdg-6-menu-icon-green-flag.png Getting Started Zdg-6-menu-icon-terminal.png Dev Environment Setup Zdg-6-menu-icon-gear.png Developing Zimlets Zdg-6-menu-icon-advanced.jpg Advanced Concepts Zdg-6-menu-icon-library.jpg API Specifications Zdg-6-menu-icon-checkbox.jpg Example Zimlets


This zimlet shows the basics for calling the Zimbra SOAP API from a zimlet. The zimlet shows calling the <GetAccountInfoRequest> SOAP command using the XML format and the JSON format.

Definition File

<zimlet name="com_zimbra_example_soap" version="1.0" description="Example SOAP request/response">
  <zimletPanelItem label="Example SOAP Request/Response" icon="zimbraIcon">
  <toolTipText>Right-click for menu options</toolTipText>
      <menuItem label="Submit SOAP Request (XML)" icon="zimbraIcon" id="menuId_soap_request_xml"/>
      <menuItem label="Submit SOAP Request (JSON)" icon="zimbraIcon" id="menuId_soap_request_json"/>

Handler Object

This code snippet from the Zimlet Handler Object shows creating the SOAP request (in XML format) and submitting that request asynchronously to the server. The callback method is called when the response returns.

 * Submits a SOAP request in XML format.
 * <GetAccountInfoRequest xmlns="urn:zimbraAccount">
 *     <account by="name">user1</account>
 * </GetAccountInfoRequest>
 * @private
com_zimbra_example_soap_HandlerObject.prototype._submitSOAPRequestXML =
function() {
    var soapDoc = AjxSoapDoc.create("GetAccountInfoRequest", "urn:zimbraAccount");

    var accountNode = soapDoc.set("account", appCtxt.getUsername());
    accountNode.setAttribute("by", "name");
    var params = {
		soapDoc: soapDoc,
		asyncMode: true,
		callback: (new AjxCallback(this, this._handleSOAPResponseXML)),
		errorCallback: (new AjxCallback(this, this._handleSOAPErrorResponseXML))


This code snippet from the Zimlet Handler Object shows creating the SOAP request (in JSON format) and submitting that request asynchronously. The callback method is called when the response returns.

 * Submits a SOAP request in JSON format.
 * GetAccountInfoRequest: {
 *   _jsns: "urn:zimbraAccount",
 *   account: {
 *     _content: "user1",
 *     by: "name"
 *    }
 * }
 * @private
com_zimbra_example_soap_HandlerObject.prototype._submitSOAPRequestJSON =
function() {

    var jsonObj = {GetAccountInfoRequest:{_jsns:"urn:zimbraAccount"}};
    var	request = jsonObj.GetAccountInfoRequest;
    request.account = {_content: appCtxt.getUsername(), by: "name"};
    var params = {
		callback: (new AjxCallback(this, this._handleSOAPResponseJSON)),
		errorCallback: (new AjxCallback(this, this._handleSOAPErrorResponseJSON))
    return appCtxt.getAppController().sendRequest(params);

This section of code shows reading information from the SOAP result and response.

 * Handles the SOAP response.
 * @param	{ZmCsfeResult}		result		the result
 * @private
com_zimbra_example_soap_HandlerObject.prototype._handleSOAPResponseXML =
function(result) {

    if (result.isException()) {
	// do something with exception
	var exception = result.getException();		
    // do something with response (in JSON format)
    var response = result.getResponse().GetAccountInfoResponse;

    var name = response.name;
    var soapURL = response.publicURL;
    var soapURL = response.soapURL;
    var zimbraId = result.getResponse().GetAccountInfoResponse._attrs.zimbraId;
    var zimbraMailHost = result.getResponse().GetAccountInfoResponse._attrs.zimbraMailHost;

    appCtxt.setStatusMsg("GetAccountInfoResponse (XML) success - "+name);	


Zimlet Package com_zimbra_example_soap.zip

Useful Links

Verified Against: Zimbra Collaboration Suite 6.0 Date Created: 2/15/2010
Article ID: https://wiki.zimbra.com/index.php?title=ZCS_6.0:Zimlet_Developers_Guide:Examples:SOAP_API_Basics Date Modified: 2010-02-18

Try Zimbra

Try Zimbra Collaboration with a 60-day free trial.
Get it now »

Want to get involved?

You can contribute in the Community, Wiki, Code, or development of Zimlets.
Find out more. »

Looking for a Video?

Visit our YouTube channel to get the latest webinars, technology news, product overviews, and so much more.
Go to the YouTube channel »

Jump to: navigation, search