Garethp / php-ews

PHP Exchange Web Services
BSD 3-Clause "New" or "Revised" License
112 stars 45 forks source link

Update Mail Item -> Categorize Email #247

Closed nunorbatista closed 1 year ago

nunorbatista commented 1 year ago

Hi,

I'm trying to add a category to an email and can't seem to get it to work. The other item update works such as isRead = true but not the category. Am I missing some parameter? I have no error on the response and this is what I'm trying to do:

$changes = [
          'isRead' => true,
          'Categories' => ['DONE']
      ];

      $request = array(
          'ItemChange' => array(
              'ItemId' => $itemId->toArray(),
              'Updates' => API\ItemUpdateBuilder::buildUpdateItemChanges('Message', 'message', $changes)
          )
      );

      $response  = $api->updateItems($request);
      return $response;

The code above marks the email as read, but doesn't categorize it.

Thanks!

nunorbatista commented 1 year ago

I could solve it by generating the request manually, like so:

$request = array(
                'ItemChanges' => [
                    'ItemChange' => [
                        'itemId' => $itemId,
                        'Updates' => [
                            'SetItemField' => [
                                'FieldURI' => ['FieldURI' => 'item:Categories'],
                                'Message' => [
                                    'Categories' => ['cat1', 'cat2']
                                ]
                            ]
                        ]
                    ]
                ],
            'MessageDisposition' => 'SaveOnly'
        );

        $request = Type::buildFromArray($request);
        $response = $api->getClient()->UpdateItem($request);