Code Monkey home page Code Monkey logo

zimbra-client's Introduction

zimbra-client

Overview

zimbra-client is a Node.js module that implements a SOAP client for Zimbra SOAP API

Features

So far this module supports 5 methods

  • getAdminAuthToken
  • createAccount
  • adminRequest
  • createDomain
  • getUserAuthToken
  • getFolder
  • getCalendars
  • searchAppointments
  • getMessage

Usage

Following example demonstrates creating a new Zimbra account using zimbra-client. In this example, the code assumes Zimbra is running on localhost, admin username is "admin" and admin password is "test123"

Example 1: Creating a new account

zimbra = require("zimbra-client");
zimbra.getAuthToken("localhost", "admin", "test123",
    function(err, authToken) {
        if(err != null) {
            console.log(err.message);
        }
        zimbra.createAccount("localhost",{sn:"Solovyev",givenName:"Greg",displayName:"Greg Solovyev",password:"test123",name:"[email protected]"},authToken,
            function(err1,accountObj) {
                if(err1 != null) {
                    if(err1.code == "account.ACCOUNT_EXISTS") {
                        console.log("an account with this name already exists");
                    } else {
                        console.log(err1.message);
                    }
                } else {
                    console.log("new account ID" + accountObj.id);
                }
            }
        );
    })

Example 2: Creating a domain

zimbra = require("zimbra-client");
zimbra.getAuthToken("localhost", "admin", "test123",
    function(err, authToken) {
        if(err != null) {
            console.log(err.message);
        } else {
            zimbra.createDomain("localhost", "gregs-mbp2.local", {description:"test domain"}, authToken,
                function (err1, respObj) {
                    if (err1 != null) {
                        if (err1.code == "account.DOMAIN_EXISTS") {
                            console.log("Domain with this name already exists");
                        } else {
                            console.log(err1.message);
                        }
                    } else {
                        console.log("response object: " + JSON.stringify(respObj));
                    }
                });
        }
    });

Example 3: Sending a custom admin SOAP request

zimbra = require("zimbra-client");
zimbra.getAuthToken("localhost", "admin", "test123",
    function(err, authToken) {
        if(err != null) {
            console.log(err.message);
        } else {
        zimbra.adminRequest("localhost", "GetAllAdminAccountsRequest", {}, authToken,
            function (err1, respObj) {
                if(err1 != null) {
                    console.log(err1.message);
                } else {
                    console.log("response object: " + JSON.stringify(respObj));
                }
            });
       }
    });

Example 4: Chain domain and account creation

var ZIMBRA_HOST = "localhost";
var ADMIN_LOGIN = "admin";
var ADMIN_PWD = "test123";
var domain = "testdomain.com";
var userEmail = "[email protected]";
zimbra = require("zimbra-client");
//get an authtoken
zimbra.getAuthToken(ZIMBRA_HOST, ADMIN_LOGIN, ADMIN_PWD,
function(err, authToken) {
    if(err != null) {
        console.log(err.message);
    } else {
        //create a damain using authtoken passed on by getAuthToken
        zimbra.createDomain(ZIMBRA_HOST, domain, {description:"test domain"}, authToken,
            function (err1, respObj) {
                if (err1 != null) {
                    if (err1.code == "account.DOMAIN_EXISTS") {
                        console.log("Domain with this name already exists");
                    } else {
                        console.log(err1.message);
                    }
                } else {
                    console.log("Created domain: " + respObj.name);
                    //create an account using the same authtoken passed on buy getAuthToken
                    createAccount(ZIMBRA_HOST,{sn:"Solovyev",givenName:"Greg",displayName:"Greg Solovyev",password:"test123",name:userEmail},authToken,
                        function(err1,accountObj) {
                            if(err1 != null) {
                                if(err1.code == "account.ACCOUNT_EXISTS") {
                                    console.log("an account with this name already exists");
                                } else
                                {
                                    console.log(err1.message);
                                }
                            } else {
                                console.log("new account ID" + accountObj.id);
                            }
                        }
                    );
                }
            });
    }
});

License

zimbra-client is licensed under Apache 2. See LICENSE.txt

zimbra-client's People

Contributors

ajsb85 avatar grishick avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.