I am using Exchange web services for sync. of my calendars and events. I wasted my lots of time for finding solution of this error. Can any one please help me.
-
`Status code 401` means that your request is `Unauthorized`. You need to use either the `basic`, `ntlm` or the `Oauth`-auth scheme for EWS. [This answer](http://stackoverflow.com/questions/3962427/help-with-exchange-2010-ews-api-and-or-phps-nusoap-library) is somewhat related. – Tholle Nov 09 '15 at 13:20
2 Answers
Current status for anyone arriving from Google:
Username and password authentication has been removed as per October 2022 for exchange servers on 365.
So you will have to change authentication to oauth or use a different library.
There is a comment about it on this issue: https://github.com/jamesiarmes/php-ews/issues/212#issuecomment-1275400001

- 2,342
- 22
- 21
-
Thanks! This is the explanation for the problem I currently have in a legacy application. – YetiCGN Oct 25 '22 at 08:28
I got a 401 response for every SOAP Request and also struggled to find out why.
Running Ubuntu, curl version: 7.35.0.
As pointed out here "CURLAUTH_BASIC" should be removed in NTLMSoapClient.php from line:
curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC | CURLAUTH_NTLM);
so that it only says
curl_setopt($this->ch, CURLOPT_HTTPAUTH, CURLAUTH_NTLM);
This works for me for jamesiarmes/php-ews project.
In garethp/php-ews though, (which seems to offer quite a lot of convenience methods for querying the exchange server), setting the curl authentication method moved to src/API/ExchangeWebServicesAuth.php.
EDIT: See curl docs for more info on authentication methods.

- 105
- 12
-
Hi @nmnd, this is an interesting issue as originally I accidentally missed NTLM all together because I was testing against a 2007 server which basic worked on. I'm not quite sure how AUTH_BASIC would cause an error, and I'm unsure if removing it would break any existing installations (are there some servers out there that don't support NTLM?). Do you have any more information on this? Should I remove the BASIC_AUTH support or make it a configuration option? Thanks - Gareth – Gareth Parker Feb 22 '16 at 09:30
-
Hi @GarethParker , I don't know that much about authentication methods in curl. According to php manual : "The bitwise | (or) operator can be used to combine more than one method. If this is done, cURL will poll the server to see what methods it supports and pick the best one." Appearently picking the best one didn't quite work out in my case (using Exchnage 2010). I don't see how AUTH_BASIC could cause an error either, sorry. I don't see my knowledge about this good enough to recommend further action for your library. – nmnd Feb 22 '16 at 10:13
-
1Hm, thanks. I don't really understand why it causes an issue in that case, as the pipe operator should mean that that having both BASIC and NTLM at the same time shouldn't be an issue. I'll look in to seeing if I can make it an option to only use NTLM in that case. If you have any more suggestions/improvements/ideas/fixes to my library, please feel free to drop me a Github issue. I usually try to check them daily – Gareth Parker Feb 22 '16 at 10:18
-
The issue here was the account was not premium subscription, thats why it was getting authenticated. There is option in mail box setting with Preimum accounts. Thank you all for your help. – Viraj Apr 06 '18 at 06:05