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

AWS WorkMail: 500 Error

Open GaboDimitrov opened this issue 1 year ago • 1 comments
trafficstars

I am encountering a 500 Internal Server Error while attempting to retrieve user availability from AWS WorkMail using the GetUserAvailability operation. I have tried two authentication methods—WebCredentials and AssumeImpersonationRole (OAuthCredentials). In both cases, the login is successful, but the subsequent command execution results in a 500 error.

Code Samples:

Web credentials authentication:

const ews = require('ews-javascript-api');

const exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2013);
exch.Credentials = new ews.WebCredentials('[email protected]', 'PASSWORD');
exch.Url = new ews.Uri('https://ews.mail.eu-west-1.awsapps.com/EWS/Exchange.asmx');

AssumeImpersonationRole (OAuthCredentials) authentication:

const ews = require('ews-javascript-api');
const {
  WorkMailClient,
  AssumeImpersonationRoleCommand,
} = require('@aws-sdk/client-workmail');

const client = new WorkMailClient({ region: 'eu-west-1' });
const params = {
  OrganizationId: 'WORKMAIL-ORGANISATION-ID',
  ImpersonationRoleId: 'IMPERSONATION-ROLE-ID',
};

const command = new AssumeImpersonationRoleCommand(params);
const data = await client.send(command);

const exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2013);
exch.Credentials = new ews.OAuthCredentials(`Bearer ${data.Token}`);
exch.Url = new ews.Uri('https://ews.mail.eu-west-1.awsapps.com/EWS/Exchange.asmx');
exch.ImpersonatedUserId = new ews.ImpersonatedUserId(
  ews.ConnectingIdType.SmtpAddress,
  '[email protected]',
);

Operation Execution:

const attendee = [new ews.AttendeeInfo('[email protected]')];
const timeWindow = new ews.TimeWindow(
  ews.DateTime.Now,
  ews.DateTime.Now.AddDays(2),
);

exch.GetUserAvailability(
  attendee,
  timeWindow,
  ews.AvailabilityData.FreeBusyAndSuggestions,
).then(
  function (availabilityResponse) {
    console.log(availabilityResponse);
  },
  function (errors) {
    console.log(errors);
  },
);

Error Received:

SoapFaultDetails {
  message: 'Request failed with status code 500',
  InnerException: null,
  faultCode: null,
  faultString: null,
  faultActor: null,
  responseCode: 127,
  errorCode: 0,
  exceptionType: null,
  lineNumber: 0,
  positionWithinLine: 0,
  errorDetails: DictionaryWithStringKey {
    keys: [],
    keysToObjs: {},
    objects: {},
    keyPicker: [Function (anonymous)]
  },
  HttpStatusCode: undefined
}

GaboDimitrov avatar Nov 27 '23 16:11 GaboDimitrov

enable debug logging and see if there is any error which is not captured here in SoapFaultDetail. Also have you tried using this credential in EWS Editor to check if there is some other error. https://github.com/dseph/EwsEditor/releases

gautamsi avatar Nov 28 '23 13:11 gautamsi