php-ews (jamesiarmes\PhpEws) get UniqueBody of conversation item

188 Views Asked by At

I am using php-ews to read mailbox items, in order to process emails as support tickets.

As some are/could be part of conversations, I want to use the UniqueBody property, to get the latest/unique part of the message.

Example request:

$request = new GetItemType();
$request->ItemShape = new ItemResponseShapeType();
$request->ItemShape->BaseShape = DefaultShapeNamesType::ALL_PROPERTIES;
$request->ItemType = new ItemType();
$request->ItemType->UniqueBody = true;
$request->ItemIds = new NonEmptyArrayOfBaseItemIdsType();
$item = new ItemIdType();
$item->Id = 'MessageId';
$request->ItemIds->ItemId[] = $item;
$response = $client->GetItem($request); 

However, this results in the UniqueBody response being empty.

I have a feeling that the request value of UniqueBody is incorrect, but I cannot find any documentation, examples or other PHP solutions that help.

Has anyone know how to get this to work?

Thanks in advance,

Baz

1

There are 1 best solutions below

0
JustBaron On BEST ANSWER

OK, with a clearer head I've done a bit of digging around in the classes and found the solution.

Add this reference:

use \jamesiarmes\PhpEws\ArrayType\NonEmptyArrayOfPathsToElementType;

Then added the ItemShape->AdditionalProperties

$request->ItemShape->AdditionalProperties = new NonEmptyArrayOfPathsToElementType();            
$request->ItemShape->AdditionalProperties->FieldURI = new PathToUnindexedFieldType();
$request->ItemShape->AdditionalProperties->FieldURI->FieldURI = UnindexedFieldURIType::ITEM_UNIQUE_BODY;

To make this:

$request = new GetItemType();
$request->ItemShape = new ItemResponseShapeType();
$request->ItemShape->BaseShape = DefaultShapeNamesType::ALL_PROPERTIES;
$request->ItemShape->AdditionalProperties = new NonEmptyArrayOfPathsToElementType();            
$request->ItemShape->AdditionalProperties->FieldURI = new PathToUnindexedFieldType();
$request->ItemShape->AdditionalProperties->FieldURI->FieldURI = UnindexedFieldURIType::ITEM_UNIQUE_BODY;
$request->ItemIds = new NonEmptyArrayOfBaseItemIdsType();
$item = new ItemIdType();
$item->Id = 'MessageId';
$request->ItemIds->ItemId[] = $item;
$response = $client->GetItem($request); 

The response now contains the UniqueBody in HTML format

$response->ResponseMessages->GetItemResponseMessage[0]->Items->Message[0]->UniqueBody

Results in:

<html><body><div>
<div>
<div>
<div>
<div dir="ltr">
<div dir="ltr">Second message.</div>
<div dir="ltr">Kind regards</div>
<div dir="ltr">Me&nbsp;</div></div></div></div></div></div>
</body></html>