Sage 300 WebAPi Authentication not working

Hi I want to learn how to use the WebAPI but I'm not able to authenticate. I always get an authentication error when I try to access any endpoint.

This is what I did.

Sage 2019 SQL Server 2014 on Server 2016.
The web api feature has been installed and I can see it in the IIS console. If I open the Swagger UI in Internet explorer everything loads up fine.

And If I visit an endpoint directly a username and password box pops up. I also created a user called WEBAPI with password WEBAPI, assigned super permissions to the WEBAPI user including access to the Web API in all modules that I could. I also enabled allow Admin to log in via the web.config (There's another file in the root which I allowed Admin, can't remember the name now)  restarted IIS, rebooted the server still not working. I entered the username/password in combinations of upper and lower case. (I think it has to be uppercase)

I then assigned permissions to the main installation directory of Sage300 (C:\Sage300) I added my account, Administrator and everyone with full read/write/modify permissions.

I also tried to change the user in IIS to administrator and it also didn't work.

The exact error from the C:\Sage300\Online\WebApi\Logs trace.log file is

----------------------------------------
Timestamp: 4/27/2019 6:14:14 PM
 Message: Error-[Tenant:] [Company:] [Module:] [User:] - Sage 300 Web API encountered an error for Url 'localhost/.../ICLocations'.:
Exception Source:      
Exception Type:        System.UnauthorizedAccessException
Exception Message:     Attempted to perform an unauthorized operation.
---- Stack Trace ----

 Machine Name: TESTENV01

If I visit the endpoint http://localhost/Sage300WebApi/v1.0/-/SAMINC/IC/ICItems in a browser, after entering the username and password U:WEBAPI P:WEBAPI or ADMIN:ADMIN I get the below response.

{
  "error": {
    "code": "Unauthorized",
    "message": {
      "lang": "en-US",
      "value": "Authentication error from invalid credentials."
    }
  }
}

FYI I made sure the WEBAPI user was created  SAMINC and not SAMLTD which is the default company when "Trying" from the Swagger UI

There isn't much info out on google about this issue and I only run into unanswered  threads , I'm out of Ideas.

Parents
No Data
Reply
  • I found the problem. Like usual I struggle for days then I decide to ask online, fiddle a little while waiting for replies and then I find the issue!

    The solution make no sense to me but anyway here goes...

    In Eventviewer --> System, there was a DNS warning. SAMINC could not be found and later SAMLTD could not be found as well.

    So I altered the hosts file to point request made for hostnames SAMINC and SAMLTD  to 127.0.0.1

    Like this.

    C:\Windows\System32\drivers\etc

    # Copyright (c) 1993-2009 Microsoft Corp.
    #
    # This is a sample HOSTS file used by Microsoft TCP/IP for Windows.
    #
    # This file contains the mappings of IP addresses to host names. Each
    # entry should be kept on an individual line. The IP address should
    # be placed in the first column followed by the corresponding host name.
    # The IP address and the host name should be separated by at least one
    # space.
    #
    # Additionally, comments (such as these) may be inserted on individual
    # lines or following the machine name denoted by a '#' symbol.
    #
    # For example:
    #
    # 102.54.94.97 rhino.acme.com # source server
    # 38.25.63.10 x.acme.com # x client host

    # localhost name resolution is handled within DNS itself.
    # 127.0.0.1 localhost
    # ::1 localhost


    127.0.0.1 samltd
    127.0.0.1 saminc

    Then suddenly it all started working.

Children
No Data