php-ews icon indicating copy to clipboard operation
php-ews copied to clipboard

create contact error - soapfault exception

Open manuelbraeuer opened this issue 8 years ago • 4 comments

hi,

i tried to create a new contact as you do it within your example, but i am running in this error

thank you manuel

Fatal error: Uncaught SoapFault exception: [a:ErrorInvalidRequest] Id must be non-empty. in /var/www/html/garethp-php-ews/src/API/NTLMSoapClient.php:118 Stack trace: #0 /var/www/html/garethp-php-ews/src/API/NTLMSoapClient.php(118): SoapClient->__call('CreateItem', Array) #1 /var/www/html/garethp-php-ews/src/API/ExchangeWebServices/MiddlewareFactory.php(18): garethp\ews\API\NTLMSoapClient->__call('CreateItem', Array) #2 /var/www/html/garethp-php-ews/src/API/ExchangeWebServices.php(497): garethp\ews\API\ExchangeWebServices->garethp\ews\API\ExchangeWebServices\{closure}(Object(garethp\ews\API\MiddlewareRequest), Object(Closure)) #3 /var/www/html/garethp-php-ews/src/API/ExchangeWebServices/MiddlewareFactory.php(32): garethp\ews\API\ExchangeWebServices->garethp\ews\API\{closure}(Object(garethp\ews\API\MiddlewareRequest)) #4 /var/www/html/garethp-php- in /var/www/html/garethp-php-ews/src/API/NTLMSoapClient.php on line 118

manuelbraeuer avatar May 27 '17 12:05 manuelbraeuer

I also get this error by sending E-Mails... Does anyone know a fix?

cfreak avatar May 31 '17 12:05 cfreak

Hi. Can you post the code you have that's causing this issue?

Garethp avatar Jun 01 '17 12:06 Garethp

WITH v0.9.1 it is working without Problems, but with 0.9.3 i get the error "Id must be non-empty".

This is the ENDPOINT used: 'ews_mail_endpoint' => env('EWS_MAIL_ENDPOINT', 'outlook.office365.com'),

if (Auth::user()) {
   $impers = Auth::user()->email;
} elseif ($from) {
   $impers = $from;
} else {
   $impers = config('mke.ews_impers');
}

$api = MailAPI::withUsernameAndPassword(
    config('mke.ews_mail_endpoint'),
    config('mke.ews_username'),
    config('mke.ews_password'),
    ['impersonation' => $impers]
);

$office365message = new Type\MessageType();
$office365message->setBody($message->getBody());
$office365message->setSubject($message->getSubject());
$office365message->setToRecipients($to);

if (!empty($cc)) {
foreach ($cc as $recipient) {
      $address = new Type\EmailAddressType();
      $address->setEmailAddress($recipient);
      $recipient = $address;
      $office365message->addCcRecipients($recipient);
   }
}

if (is_array($message->getChildren()) && !empty($message->getChildren())) {
    //Create our message without sending it
    $mailId = $return = $api->sendMail($office365message, array('MessageDisposition' => 'SaveOnly'));

    //Create Attachments
    foreach ($message->getChildren() as $key => $attach) {
        $api->getClient()->CreateAttachment(array(
            'ParentItemId' => $mailId->toArray(),
            'Attachments' => array(
                'FileAttachment' => array(
                    'Name' => urldecode($attach->getFilename()),
                    'Content' => $attach->getBody()
                )
            ),
        ));
    }

    $mailId = $api->getItem($mailId)->getItemId();

    //Send the message
    $api->getClient()->SendItem(array(
        'SaveItemToFolder' => true,
        'ItemIds' => array(
            'ItemId' => $mailId->toArray()
        )
    ));
}

cfreak avatar Jun 02 '17 14:06 cfreak

Hi there. Sorry for the late reply. The new version 0.9.4 should contain a fix for this. Can you please try it?

Garethp avatar Aug 29 '17 11:08 Garethp