Difference between revisions of "Login and manipulate Zimbra account with Perl"

(Adding Unsupported template, Article Footer, and Category)
Line 1: Line 1:
 +
{{Unsupported}}
 +
 
== Intro ==
 
== Intro ==
  
Line 136: Line 138:
 
And that's pretty much it. When you call a method like my $var = $zs->createAppt() the SOAP response from the server is returned.
 
And that's pretty much it. When you call a method like my $var = $zs->createAppt() the SOAP response from the server is returned.
 
So you need to parse out the variables you need like the invId and folderId. I know the createAppt response is a XmlElement Object, but I'm not sure about the larger responses like getAppointment. I believe however they are XmlElement or XmlDocument. I'm not really sure though. Once I find out I will update this Wiki
 
So you need to parse out the variables you need like the invId and folderId. I know the createAppt response is a XmlElement Object, but I'm not sure about the larger responses like getAppointment. I believe however they are XmlElement or XmlDocument. I'm not really sure though. Once I find out I will update this Wiki
 +
 +
 +
{{Article Footer|Unknown|10/25/2007}}
 +
 +
[[Category:Administration]]

Revision as of 21:59, 26 September 2008


Intro

I hacked together this small API to manipulate a Zimbra account using Perl. If you've been trying to find a Zimbra SOAP API for Perl you've probably ran into the scripts located at Zimbra Scripts

And as of now this module ZimbraSession.pm is the closest thing to an API for Zimbra SOAP. To obtain the module you need to download the attachment on the Forum post I originally put up which is here: ZimbraSession.pm.txt

The file is .txt so just rename it to .pm and it will be good to go.


How to Use the API

If you are familiar with Perl then using this module is nothing new. It works like every other perl module you use on a day to day. For those not that comfortable with Perl here you go.

First thing you need to download the following Perl Modules from zimbra.svn.sourcefourge.net

Soap.pm Soap11.pm Soap12.pm SuddsException.pm XmlElement.pm XmlDoc.pm

And you need to get ZimbraSession.pm from the form post. The link to it is above.

First thing before you start writing your code you need to save all the Zimbra modules into a folder and put them somewhere you will remember. I prefer /usr/local/src/Zimbra/

Now it's time to write your script.

Below is quick example script. All the methods return the SOAP response from the server.

  1. !/usr/bin/perl -w

Holds Soap.pm, Soap11, Soap12 Sudds.., XmlDoc, XmlElement, and ZimbraSession

use lib '/usr/local/src/Zimbra/';

use ZimbraSession;


All these methods return the SOAP response from the server.


To begin you need to initialize your session. This method basically
creates a browser so you can communicate with Zimbra. Once you have your
Zimbra session initialized you can pretty much do whatever you want.
You can create a new session for as many users as you like.

my $zs = ZimbraSession->new(

                            {name => 'Display Name', login => 'username'},
                            'password',
                            'http://yourhost.net/service/soap/'
                           );


Right now this only creates Calendars, because that's all I needed, but it can easily be modifed to create folders. You just need to figure out the correct 'view' and edit it in the method. you can then add a parameter like $zs->createFolder($folder_name, $view);

my $folder = $zs->createFolder($folder_name);


Create New Appointment


To create a new appointment first set up your attendees. You don't need to include the logged in user's info. It will be added automatically.

my $attendees = [

                {name => 'Matt Foley', email => 'mfoley@email.com'},
                {name => 'Bill Brasky', email => 'bbrasky@email.com'}
               ]; # List of attendees to invite to an appointment


For now this will only set an appointment in your default Calendar. These are not recurring appointments like the createAppt.pl script

my $appointment = $zs->createAppt(

                                  'Subject', 'Location',
                                  , # Show as
                                  , # Calendar
                                  'Start Time',
                                  'End Time',
                                  , # Recuring
                                  $attendees,
                                  'Plain Text Message',
                                  "HTML Message",
                                  
                                 );


Retrieve an Appointment


You can retrieve the entire appointment by using the getAppt method.

my $appointment = $zs->getAppt($apptId);


Retrieve Appointment Summaries


This will retrieve the summaries of all the appointments.

my $summaries = $zs->getApptSummaries($start_time, $end_time);


Modify an Appointment


my $modified_appt = $zs->modifyAppt(

                                    $invId, $mode, $end_time,
                                    $subject, $message, $location,
                                    $current_attendees, $new_attendees
                                   );


Cancel Appointment


my $cancel_appointment = $zs->cancelAppt($invId, $subject, $message, $attendees);


Delete Folder


I dont think you can use the folder name here. The folder id is returned in the respone from createFolder();

my $deleted_folder = $zs->deleteFolder($folder_id);

And that's pretty much it. When you call a method like my $var = $zs->createAppt() the SOAP response from the server is returned. So you need to parse out the variables you need like the invId and folderId. I know the createAppt response is a XmlElement Object, but I'm not sure about the larger responses like getAppointment. I believe however they are XmlElement or XmlDocument. I'm not really sure though. Once I find out I will update this Wiki


Verified Against: Unknown Date Created: 10/25/2007
Article ID: https://wiki.zimbra.com/index.php?title=Login_and_manipulate_Zimbra_account_with_Perl Date Modified: 2008-09-26



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