[SOLVED] Create an appointment with SOAP API PHP

Have a great idea for extending Zimbra? Share ideas, ask questions, contribute, and get feedback.
jbeauviche
Posts: 2
Joined: Wed Sep 07, 2016 4:27 pm

[SOLVED] Create an appointment with SOAP API PHP

Postby jbeauviche » Wed Sep 07, 2016 4:54 pm

Hello all,

I'm new with Zimbra and I started to use the library found in Github => https://github.com/zimbra-api/zimbra-api.
I tried to found some documentations to use this library to create an appointment but I didn't found anything.
I can just do that basic thing :

Code: Select all

$api = \Zimbra\Admin\AdminFactory::instance('https://localhost:7071/service/admin/soap');
$api->auth('username', 'password');
$account = new \Zimbra\Struct\AccountSelector(\Zimbra\Enum\AccountBy::NAME(), 'username');
$accountInfo = $api->getAccountInfo($account);


I looked directly in the code the method "createAppointment" but the comment about this method is chinesee for me :)

Code: Select all

    /**
     * This is the API to create a new Appointment, optionally sending out meeting Invitations to other people.
     *
     * @param  Msg $m Message
     * @param  bool $echo If specified, the created appointment is echoed back in the response as if a GetMsgRequest was made
     * @param  int $max Maximum inlined length
     * @param  bool $html Set if want HTML included in echoing
     * @param  bool $neuter Set if want "neuter" set for echoed response
     * @param  bool $forcesend If set, ignore smtp 550 errors when sending the notification to attendees.
     * @return mix
     */
    public function createAppointment(
        Msg $m = null,
        $echo = null,
        $max = null,
        $html = null,
        $neuter = null,
        $forcesend = null
    )
    {
        $request = new \Zimbra\Mail\Request\CreateAppointment(
            $m,
            $echo,
            $max,
            $html,
            $neuter,
            $forcesend
        );
        return $this->getClient()->doRequest($request);
    }



Does there anyone who has an example for this method?

Thank you.
Last edited by jbeauviche on Fri Sep 09, 2016 12:48 pm, edited 1 time in total.


jbeauviche
Posts: 2
Joined: Wed Sep 07, 2016 4:27 pm

Re: Create an appointment with SOAP API PHP

Postby jbeauviche » Fri Sep 09, 2016 12:47 pm

Hello,

I asked my question to the author of the library and he replied me :)
Here is the solution :

Code: Select all

<?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();
}


And here the discussions => https://github.com/zimbra-api/zimbra-api/issues/11

Hope that helps someonelse.

Return to “Developers”

Who is online

Users browsing this forum: No registered users and 2 guests