Comments (6)
My two cents:
First, add this before setting the URL:
exch.HttpHeaders.Add('X-AnchorMailbox', "Username");
Next, do a resolve on the user, before getting availability.
something like:
await exch.ResolveName(user).then((response) => {...}))
If you are using autodiscovery, you also need to pass the credentials to the auto-discovery service as well
const autod = new ews.AutodiscoverService(config.exchangeVersion || ews.ExchangeVersion.Exchange2019);
autod.Credentials = new ews.WebCredentials(user, password);
from ews-javascript-api.
My two cents: First, add this before setting the URL: exch.HttpHeaders.Add('X-AnchorMailbox', "Username"); Next, do a resolve on the user, before getting availability. something like: await exch.ResolveName(user).then((response) => {...}))
If you are using autodiscovery, you also need to pass the credentials to the auto-discovery service as well
const autod = new ews.AutodiscoverService(config.exchangeVersion || ews.ExchangeVersion.Exchange2019); autod.Credentials = new ews.WebCredentials(user, password);
@kstankov Thanks a million for your help. With the first hint I have no problem. But with the second one, we can use await only inside an aync function. I am new to Javascript. Can you please help me with the await keyword?
So, I have changed the code as below,
var ews = require('ews-javascript-api');
var exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2019);
exch.Credentials = new ews.WebCredentials("Username", "Password");
console.log(exch.Credentials);
console.log(exch.Credentials.getPassword());
exch.HttpHeaders.Add('X-AnchorMailbox', "user");
//set ews endpoint url to use
exch.Url = new ews.Uri("https://xxx.com/EWS/Exchange.asmx"); // you can also use exch.AutodiscoverUrl+
console.log(exch.Url);
console.log(exch.requestedServerVersion);
var attendee =[new ews.AttendeeInfo("[email protected]")];
console.log(attendee);
async() =>{
await exch.ResolveName("user").then((response) => {});
}
//create timewindow object o request avaiability suggestions for next 48 hours, DateTime and TimeSpan object is created to mimic portion of .net datetime/timespan object using momentjs
var timeWindow = new ews.TimeWindow(ews.DateTime.Now, ews.DateTime.Now.AddDays(2));
console.log(timeWindow);
//console.log(GetUserAvailabilityResults);
exch.GetUserAvailability(attendee, timeWindow, ews.AvailabilityData.FreeBusyAndSuggestions)
.then(function (availabilityResponse) {
//do what you want with user availability
console.log('This example is different!');
console.log(availabilityResponse);
}, function(error) {
// Common error handling
console.log(error.responseCode);
console.log(error);
});
from ews-javascript-api.
most of the methods in this library return promise. you can use await with this lib. You can use your own async function or async IIFE to use await
from ews-javascript-api.
most of the methods in this library return promise. you can use await with this lib. You can use your own async function or async IIFE to use await
Thanks @gautamsi for your reply. I used async IIFE, but still getting the same error.
var ews = require('ews-javascript-api');
var exch = new ews.ExchangeService(ews.ExchangeVersion.Exchange2019);
exch.Credentials = new ews.WebCredentials("Username", "Password");
console.log(exch.Credentials);
console.log(exch.Credentials.getPassword());
exch.HttpHeaders.Add('X-AnchorMailbox', "user");
//set ews endpoint url to use
exch.Url = new ews.Uri("https://xxx.com/EWS/Exchange.asmx");
console.log(exch.Url);
console.log(exch.requestedServerVersion);
**_async() =>{
await exch.ResolveName("GuestUsername").then((response) => {});
}_**
var attendee =[new ews.AttendeeInfo("[[email protected]](mailto:[email protected])")];
console.log(attendee);
//create timewindow object o request avaiability suggestions for next 48 hours, DateTime and TimeSpan object is created to mimic portion of .net datetime/timespan object using momentjs
var timeWindow = new ews.TimeWindow(ews.DateTime.Now, ews.DateTime.Now.AddDays(2));
console.log(timeWindow);
//console.log(GetUserAvailabilityResults);
exch.GetUserAvailability(attendee, timeWindow, ews.AvailabilityData.FreeBusyAndSuggestions)
.then(function (availabilityResponse) {
//do what you want with user availability
console.log('This example is different!');
console.log(availabilityResponse);
}, function(error) {
// Common error handling
console.log(error.responseCode);
console.log(error);
});
So, my Soap fault details are printed twice. Once with async and ither time with console.log(error). Can we do anything to avoid this soap fault message of 401 unauthorized?
from ews-javascript-api.
is your server only using NTLM? that could be one reason why it comes back as 401.
I do not see the IIFE properly here. when you use await you do not have to use .then
or .catch
you use try...catch
from ews-javascript-api.
True! NTLM. Will raise another issue next week on User availability.
from ews-javascript-api.
Related Issues (20)
- Error SoapFaultDetails message: '401 Unauthorized', HOT 8
- TypeScript errors when compiling (cannot find name PrivilegedUserId and more) HOT 4
- Usage React Native
- Failing to fetch .msg file attachment from ews exchange server ews-javascript-api HOT 4
- C# code works, but not its Node equivalent: 401 Unauthorized HOT 16
- Booking type causes sync to fail
- Specify certificate authority while sending request HOT 2
- nodejs 18: digital envelope routines::unsupported HOT 5
- Appointment.Bind sometimes return null Organizer HOT 2
- Possibility to set User-Agent HOT 4
- when creating an event in the calendar, the body is not added HOT 1
- UNABLE_TO_VERIFY_LEAF_SIGNATURE HOT 1
- Missing typescript declaration for CreateItem HOT 2
- how to retrieve strings from Extended Properties with more than 255 characters HOT 1
- Missing finally in promise declaration
- AWS WorkMail: 500 Error HOT 1
- Question: Can we create a new mailbox for an existing AD user using this library? HOT 3
- Cannot get attachment of .EML type HOT 1
- Appointment created by ews-javascript-api are shown in Monrovia timezone HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from ews-javascript-api.