401 - Unauthorized: Access is denied due to invalid credentials - Error while calling an API

39 views Asked by At

I am trying call an API(written in C#) from Excel VBA. The Request message is formed within the Excel VBA and send to the API. The message looks like as follows:

<?xml version="1.0" encoding="utf-8"?>
<IncomingMessage xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
               xmlns:xsd="http://www.w3.org/2001/XMLSchema">
   <MessageSource>hello</MessageSource>
   <MessagefromID>Newuser</MessagefromID>
   <MessageVersion>20240221</MessageVersion>
   <MessageType>1</MessageType>
   <Command>Select Count(1) AS count from TableName</Command>
   <MessageParams/>
   <MessageTimeStamp>2024-03-08T14:03:10.00</MessageTimeStamp>
</IncomingMessage>

Also some message header are set:

httpObject.setRequestHeader "Content-type", "application/xml"
    httpObject.setRequestHeader "Content-Length", Len(MessageVariable)

When I try to call the API from the excel macro I get the error -

401 - Unauthorized: Access is denied due to invalid credentials

I would like to have Windows Authentication enabled. Meaning only AD users of the Domain can access the API.

The IIS Authentication setting for the Application Pool is as follows:

Anonymous Auth - Disabled
Basic Auth - Disabled
Windows Auth - Enabled

The IIS Authorization setting for the Application Pool is as follows:

Deny - Anonymous User
Allow - All Users

The Identity of the Application pool is "ApplicationPoolIdentity".

Can you please advise, if I should send something extra in the request header to make it work? Or some other IIS settings that must be updated.

Note: I have tried to update the Identity of the Application Pool to "Local System" , but to no use.

Many thanks in advance for any help.

0

There are 0 answers