Git Product home page Git Product logo

Comments (6)

kstankov avatar kstankov commented on June 2, 2024 2

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.

Lakshmiganthangithub avatar Lakshmiganthangithub commented on June 2, 2024

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.

gautamsi avatar gautamsi commented on June 2, 2024

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.

Lakshmiganthangithub avatar Lakshmiganthangithub commented on June 2, 2024

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.

gautamsi avatar gautamsi commented on June 2, 2024

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.

Lakshmiganthangithub avatar Lakshmiganthangithub commented on June 2, 2024

True! NTLM. Will raise another issue next week on User availability.

from ews-javascript-api.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.