zimbra-api / soap-api

Zimbra SOAP client in PHP language
BSD 3-Clause "New" or "Revised" License
62 stars 48 forks source link

Need documentation for the method "createAppointment" #11

Closed anardil closed 7 years ago

anardil commented 7 years ago

Hello,

Very nice work. I tried to find some documentations to use each method but I found nothing. Is it planned to have a documentation for each method? Because it's very hard to start something.

Thx.

anardil commented 7 years ago

Hello,

Can you just give me an example to use the method "createAppointment"?

It will be kind. Thank you.

anardil commented 7 years ago

@nguyennv

I looked the Tests classes and I tried something.

$account = new \Zimbra\Struct\AccountSelector(\Zimbra\Enum\AccountBy::NAME(), '**'); $api = \Zimbra\Mail\MailFactory::instance('https://****_/service/soap'); $api->auth($account, '_***');

$mid = uniqid(); $part = "hello"; $id = uniqid(); $path = "hello"; $ct = "hello"; $content = "hello"; $ci = uniqid(); $name = "hello"; $value = "hello"; $aid = uniqid(); $method = "hello"; $address = "hello"; $personal = "hello"; $stdname = "hello"; $dayname = "hello"; $fr = "hello"; $origid = uniqid(); $idnt = "hello"; $su = "hello"; $irt = "hello"; $l = "hello"; $f = "hello"; $compNum = mt_rand(1, 100); $ver = mt_rand(1, 100); $mon = mt_rand(1, 12); $hour = mt_rand(0, 23); $min = mt_rand(0, 59); $sec = mt_rand(0, 59); $stdoff = mt_rand(1, 10); $dayoff = mt_rand(1, 10); $standard = new \Zimbra\Struct\TzOnsetInfo($mon, $hour, $min, $sec); $daylight = new \Zimbra\Struct\TzOnsetInfo($mon, $hour, $min, $sec); $header = new \Zimbra\Mail\Struct\Header($name, $value); $tz = new \Zimbra\Mail\Struct\CalTZInfo( $id, $stdoff, $dayoff, $standard, $daylight, $stdname, $dayname );

$m = new Msg( $content, null, null, null, $fr, $aid, $origid, ReplyType::REPLIED(), $idnt, $su, $irt, $l, $f, [$header], [], [$tz] );

$api->createAppointment($m);

But I have an error in return. Fatal error: Uncaught GuzzleHttp\Exception\ServerException: Server error response [url] https://***********/service/soap [status code] 500 [reason phrase] Server Error in ..

Can you help me, please ?

Thx

nguyennv commented 7 years ago

Hi anardil, This is example code I've used for appointment creating

<?php

require 'vendor/autoload.php';

use Zimbra\Enum\AccountBy;
use Zimbra\Enum\AddressType;
use Zimbra\Enum\AlarmAction;
use Zimbra\Enum\FreeBusyStatus;
use Zimbra\Enum\InviteStatus;
use Zimbra\Enum\InviteClass;
use Zimbra\Enum\ParticipationStatus;
use Zimbra\Enum\Transparency;

use Zimbra\Mail\MailFactory;
use Zimbra\Mail\Struct\AlarmInfo;
use Zimbra\Mail\Struct\AlarmTriggerInfo;
use Zimbra\Mail\Struct\CalendarAttendee;
use Zimbra\Mail\Struct\CalOrganizer;
use Zimbra\Mail\Struct\DtTimeInfo;
use Zimbra\Mail\Struct\DurationInfo;
use Zimbra\Mail\Struct\EmailAddrInfo;
use Zimbra\Mail\Struct\InvitationInfo;
use Zimbra\Mail\Struct\InviteComponent;
use Zimbra\Mail\Struct\MimePartInfo;
use Zimbra\Mail\Struct\Msg;

use Zimbra\Struct\AccountSelector;

$api = MailFactory::instance('https://mail.securemail.vn/service/soap');
try {
    $account = new AccountSelector(AccountBy::NAME(), 'nguyennv@iwayvietnam.com');
    $api->auth($account, 'password');

    $trigger = new AlarmTriggerInfo();
    $trigger->setRelative(new DurationInfo(true, null, null, null, 5, null, 'START'));
    $alarm = new AlarmInfo(AlarmAction::DISPLAY(), $trigger);

    $comp = new InviteComponent();
    $comp->setName('Meet celebrities for free')
        ->setLocation('My home')
        ->setFreeBusy(FreeBusyStatus::FREE())
        ->setStatus(InviteStatus::COMPLETED())
        ->setCalClass(InviteClass::PUB())
        ->setTransparency(Transparency::OPAQUE())
        ->setIsAllDay(false)
        ->setIsDraft(false)
        ->addAttendee(new CalendarAttendee('nguyennv1981@gmail.com', null, 'Nguyen Van'))
        ->addAttendee(new CalendarAttendee('nguyennv1981@yahoo.com', null, 'Van Nguyen'))
        ->setOrganizer(new CalOrganizer('nguyennv@iwayvietnam.com', null, 'Nguyen Van Nguyen'))
        ->setDtStart(new DtTimeInfo('20160930T160000', 'Asia/Saigon'))
        ->setDtEnd(new DtTimeInfo('20160930T170000', 'Asia/Saigon'))
        ->addAlarm($alarm);

    $inv = new InvitationInfo();
    $inv->setInviteComponent($comp);

    $mp = new MimePartInfo(null, 'multipart/alternative');
    $mp->addMimePart(new MimePartInfo(null, 'text/plain', 'Meet celebrities for free'));

    $msg = new Msg();
    $msg->setSubject('Meet celebrities for free')
        ->setFolderId('10')
        ->addEmail(new EmailAddrInfo('nguyennv1981@gmail.com', AddressType::TO(), 'Nguyen Van'))
        ->addEmail(new EmailAddrInfo('nguyennv1981@yahoo.com', AddressType::TO(), 'Van Nguyen'))
        ->setInvite($inv)
        ->setMimePart($mp);
    $result = $api->createAppointment($msg);
    var_dump($result);
}
catch(Exception $ex) {
    $client = $api->getClient();
    echo $client->lastResponse();
}

Hope this help

anardil commented 7 years ago

Hello @nguyennv

Fantastic ! I can see the appointment in my personal calendar. :)

Now I have 2 questions : 1). Is it possible to create the appointment from the instance \Zimbra\Admin\AdminFactory::instance without to know the password of each account ? 2). I have several shared calendars, is it possible to create an appointment on a specific shared calendar ?

Thanks again for your help.

nguyennv commented 7 years ago

Hi anardil

  1. You can't create the appointment from the instance \Zimbra\Admin\AdminFactory::instance
  2. Each calendar is a folder and you know the folder id and set it to message by method setFolderId of Msg class.
anardil commented 7 years ago

Hi @nguyennv,

Thanks for your reply.

1). Is there another way of authentication that can authenticate to an account without knowing the password. Because I have lots of accounts and my customers can change their own password.

2). How can I know the folder id of existing calendars?

Thank you.

anardil commented 7 years ago

@nguyennv

For the first question I used the preAuth method and it works. Now I'm waiting for your reply about the second question.

Thank you for your help.

nguyennv commented 7 years ago

Hi anardil, You can get the list of folder by using method getFolder of the api without parameters or pass "view" parameter with "appointment" value for calendar folder listing. Ex:

    $result = $api->getFolder(null, null, 'appointment');
    var_dump($result);
omercicek01 commented 7 years ago

My name is omer I want use change account password On the zimbra admin account Please help me

undert03 commented 6 years ago

@nguyennv

How would you do this with delegate authority. Like auth as admin but setup appointment for another user and have it on their calendar.

rpmesta395 commented 3 years ago

My name is omer I want use change account password On the zimbra admin account Please help me

$api->changePassword($account, $oldPassword, $newpassword, $virtualHost);