Login and manipulate Zimbra account with Perl: Difference between revisions
(Adding Unsupported template, Article Footer, and Category) |
No edit summary |
||
(5 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{Unsupported}} | {{Archive}}{{Unsupported}} | ||
=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 [http://zimbra.svn.sourceforge.net/viewvc/zimbra/trunk/ZimbraServer/src/perl/soap/ Zimbra Scripts] | 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 [http://zimbra.svn.sourceforge.net/viewvc/zimbra/trunk/ZimbraServer/src/perl/soap/ 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: [http://www.zimbra.com/forums/attachments/developers/1147d1193323577-perl-module-simplify-soap-access-zimbra-zimbrasession.pm.txt ZimbraSession.pm.txt] | 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: [http://www.zimbra.com/forums/attachments/developers/1147d1193323577-perl-module-simplify-soap-access-zimbra-zimbrasession.pm.txt ZimbraSession.pm.txt] (the original forum post is [http://www.zimbra.com/forums/developers/12382-perl-module-simplify-soap-access-zimbra.html here]). | ||
The file is .txt so just rename it to .pm and it will be good to go. | 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. | |||
If you are familiar with Perl then using this module is nothing new. It works like every other | |||
For those not that comfortable with Perl here you go. | For those not that comfortable with Perl here you go. | ||
First thing you need to download the following Perl Modules from [http://zimbra.svn.sourceforge.net/viewvc/zimbra/trunk/ZimbraServer/src/perl/soap/ zimbra.svn.sourcefourge.net] | First thing you need to download the following Perl Modules from [http://zimbra.svn.sourceforge.net/viewvc/zimbra/trunk/ZimbraServer/src/perl/soap/ zimbra.svn.sourcefourge.net]: | ||
Soap.pm | *Soap.pm | ||
Soap11.pm | *Soap11.pm | ||
Soap12.pm | *Soap12.pm | ||
SuddsException.pm | *SuddsException.pm | ||
*XmlDoc.pm | |||
*XmlElement.pm | |||
And you need to get ZimbraSession.pm from the form post. The link to it is above. | 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 | 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/. | ||
somewhere you will remember. I prefer /usr/local/src/Zimbra/ | |||
Now it's time to write your script. | Now it's time to write your script. | ||
Below is quick example script. All the methods return the SOAP response from the server. | Below is a quick example script. All the methods return the SOAP response from the server. | ||
use ZimbraSession; | #!/usr/bin/perl -w | ||
<br> | |||
#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( | |||
my $zs = ZimbraSession->new( | |||
{name => 'Display Name', login => 'username'}, | {name => 'Display Name', login => 'username'}, | ||
'password', | 'password', | ||
Line 57: | Line 50: | ||
); | ); | ||
Right now this only creates Calendars, because that's all I needed, but it can easily be modified to | |||
Right now this only creates Calendars, because that's all I needed, but it can easily be | |||
create folders. You just need to figure out the correct 'view' and edit it in the method. | 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); | you can then add a parameter like $zs->createFolder($folder_name, $view); | ||
my $folder = $zs->createFolder($folder_name); | 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 | 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. | logged in user's info. It will be added automatically. | ||
my $attendees = [ | my $attendees = [ | ||
{name => 'Matt Foley', email => 'mfoley@email.com'}, | {name => 'Matt Foley', email => 'mfoley@email.com'}, | ||
{name => 'Bill Brasky', email => 'bbrasky@email.com'} | {name => 'Bill Brasky', email => 'bbrasky@email.com'} | ||
]; # List of attendees to invite to an appointment | ]; # List of attendees to invite to an appointment | ||
For now this will only set an appointment in your default Calendar. | For now this will only set an appointment in your default Calendar. | ||
These are not recurring appointments like the createAppt.pl script | These are not recurring appointments like the createAppt.pl script | ||
my $appointment = $zs->createAppt( | my $appointment = $zs->createAppt( | ||
'Subject', 'Location', | 'Subject', 'Location', | ||
'', # Show as | '', # Show as | ||
Line 87: | Line 75: | ||
'Start Time', | 'Start Time', | ||
'End Time', | 'End Time', | ||
'', # | '', # Recurring | ||
$attendees, | $attendees, | ||
'Plain Text Message', | 'Plain Text Message', | ||
Line 94: | Line 82: | ||
); | ); | ||
==Retrieve an Appointment== | |||
Retrieve an Appointment | |||
You can retrieve the entire appointment by using the getAppt method. | You can retrieve the entire appointment by using the getAppt method. | ||
my $appointment = $zs->getAppt($apptId); | my $appointment = $zs->getAppt($apptId); | ||
==Retrieve Appointment Summaries== | |||
This will retrieve the summaries of all the appointments. | This will retrieve the summaries of all the appointments. | ||
my $summaries = $zs->getApptSummaries($start_time, $end_time); | my $summaries = $zs->getApptSummaries($start_time, $end_time); | ||
==Modify an Appointment== | |||
my $modified_appt = $zs->modifyAppt( | |||
my $modified_appt = $zs->modifyAppt( | |||
$invId, $mode, $end_time, | $invId, $mode, $end_time, | ||
$subject, $message, $location, | $subject, $message, $location, | ||
Line 120: | Line 102: | ||
); | ); | ||
==Cancel Appointment== | |||
my $cancel_appointment = $zs->cancelAppt($invId, $subject, $message, $attendees); | |||
==Delete Folder== | |||
I don't think you can use the folder name here. | |||
The folder id is returned in the response 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. | |||
---- | |||
[[User:Rosch|Rosch]] 16:02, 28 October 2011 (PDT) | |||
{{Article Footer|Unknown|10/25/2007}} | {{Article Footer|Unknown|10/25/2007}} | ||
[[Category:Administration]] | [[Category:Administration]] | ||
[[Category:Calendar]] | |||
[[Category:SOAP]] |
Latest revision as of 19:46, 25 March 2015
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 original forum post is here).
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
- XmlDoc.pm
- XmlElement.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 a quick example script. All the methods return the SOAP response from the server.
#!/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 modified 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', , # Recurring $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 don't think you can use the folder name here. The folder id is returned in the response 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.
Rosch 16:02, 28 October 2011 (PDT)