ews-javascript-api icon indicating copy to clipboard operation
ews-javascript-api copied to clipboard

ItemAttachment.Load() fails with "The element at position 0 is invalid"

Open cm253 opened this issue 4 years ago • 3 comments

Used library version: 0.10.3 Nodejs: 14 API Exchange Version: Exchange2013_SP1

How to reproduce: Create an ItemAttachment for an appointment, for example drag & drop an Outlook contact, mail or appointment to an appointment. Try call the ItemAttachment's Load() function. The following error is thrown:

Stack trace:

Exception: The element at position 0 is invalid
at Function.EwsUtilities.ValidateParamCollection (node_modules/ews-javascript-api/js/Core/EwsUtilities.js:611:23)
at GetAttachmentRequest.Validate (node_modules/ews-javascript-api/js/Core/Requests/GetAttachmentRequest.js:157:41)
at GetAttachmentRequest.ServiceRequestBase.ValidateAndEmitRequest (node_modules/ews-javascript-api/js/Core/Requests/ServiceRequestBase.js:394:14)
at node_modules/ews-javascript-api/js/Core/Requests/SimpleServiceRequestBase.js:55:19
at Promise._execute (node_modules/bluebird/js/release/debuggability.js:384:9)
at Promise._resolveFromExecutor (node_modules/bluebird/js/release/promise.js:518:18)
at new Promise (node_modules/bluebird/js/release/promise.js:103:10)
at GetAttachmentRequest.SimpleServiceRequestBase.InternalExecute (node_modules/ews-javascript-api/js/Core/Requests/SimpleServiceRequestBase.js:52:16)
at node_modules/ews-javascript-api/js/Core/Requests/MultiResponseServiceRequest.js:48:19
    at Promise._execute (node_modules/bluebird/js/release/debuggability.js:384:9)
at Promise._resolveFromExecutor (node_modules/bluebird/js/release/promise.js:518:18)
at new Promise (node_modules/bluebird/js/release/promise.js:103:10)
at GetAttachmentRequest.MultiResponseServiceRequest.Execute (node_modules/ews-javascript-api/js/Core/Requests/MultiResponseServiceRequest.js:47:16)
at ExchangeService.InternalGetAttachments (node_modules/ews-javascript-api/js/Core/ExchangeService.js:1044:24)
at ExchangeService.GetAttachment (node_modules/ews-javascript-api/js/Core/ExchangeService.js:1010:21)
at ItemAttachment.Attachment.InternalLoad (node_modules/ews-javascript-api/js/ComplexProperties/Attachment.js:212:29)

Code:

const exchangeAttachments: Attachment[] = item.Attachments?.GetEnumerator() ?? [];
for await (const attachment of exchangeAttachments) {
    await attachment.Load();
}

Similar issue: https://github.com/gautamsi/ews-javascript-api/issues/201

cm253 avatar Sep 24 '21 12:09 cm253

A useful workaround may be to fetch the attachment again with ExchangeService.GetAttachments After this re-fetch ItemAttachment.Load() is possible (at least in my case)

if (exchangeItem.HasAttachment) {
  const exchangeAttachments: Attachment[] = exchangeItem.Attachments?.GetEnumerator() ?? [];

  for await (const attachment of exchangeAttachments) {
    const attachments = await ExchangeService.GetAttachments([attachment.Id], BodyType.HTML, []);
    const itemAttachment: ItemAttachment = attachments.Responses[0].Attachment as ItemAttachment;
    await itemAttachment.Load([ItemSchema.MimeContent]);
  }
}

1056109 avatar Jan 12 '22 09:01 1056109

Is this still valid?

cclauss avatar Dec 07 '22 15:12 cclauss

ExchangeService.GetAttachments([attachment.Id], ...) results in a Typescript error for me. It appears GetAttachments expects a full Attachment?

(method) ExchangeService.GetAttachments(attachments: Attachment[], bodyType: BodyType, additionalProperties: PropertyDefinitionBase[]): Promise<ServiceResponseCollection<GetAttachmentResponse>> (+1 overload)

Is this a bug?

parlato-vooma avatar Dec 07 '23 01:12 parlato-vooma

I have to check but use the workaround used by @1056109 for now.

gautamsi avatar Feb 25 '24 06:02 gautamsi