Sage 300 WebAPi Authentication not working

SOLVED

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 localhost/.../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
  • 0

    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.

  • 0 in reply to MartinViljoen

    Hello,

    I have exactly the same problem. But your solution here did work out for me. I have a user WEBAPI (Passowrd:WEBAPI) with access to all modules. I have enabled access to Web API too.

    When making a request with an authorization header whose value is Basic V0VCQVBJOldFQkFQSQ== 

    The outcome is as below:

    The log file shows:
    -----------------------------

    ----------------------------------------
    Timestamp: 3/15/2020 3:08:40 PM
    Message: Error-[Tenant:] [Company:] [Module:] [User:] - Sage 300 Web API encountered an error for Url 'k**sage/.../ARCustomers'.:
    Exception Source:
    Exception Type: System.UnauthorizedAccessException
    Exception Message: Attempted to perform an unauthorized operation.
    ---- Stack Trace ----


    Please someone advice

  • 0 in reply to Mr. Mbithi

    Have you resolved this issue?  I am having exactly the same problem. 

  • 0 in reply to bob1th

    I had the same issue. It turns out the password for the Sage WEB API user must be in all UPPERCASE or numbers, no lowercase letters are allowed in the Password.

  • 0 in reply to Dan Devolder

    I have all the above still getting status 401. Does anyone have alternatives.
    Its frustrating

  • 0 in reply to don dausi

    A few questions:

    1. Are webscreens installed?
    2. What user are you using to connect to the web API?
    3. If admin, have you enabled the admin access to the web API in BOTH places?
    4. Have you tried using the Swagger UI to access/update Sage?
  • 0 in reply to Vega

    1.Yes Webscreen.installed
    2. I am using both C# code, POSTMAN, and Swagger,
    3. Yes, I have set this tag "<add key="AllowWebApiAccessForAdmin" value="true" />" for both online and api
    4.Yes I have

  • 0 in reply to don dausi

    Ok, cool. So it looks on the face of it that it is set up. With regards to 4 you say you've tried the Swagger UI. Did it work? ie did you get data out? Could you update records?

  • 0 in reply to Vega

    Yeah, Swagger UI has the pop screen for credentials, which I put the correct one but still remain even with wrong or correct logins

  • 0 in reply to don dausi

    Ok, try using the ADMIN credentials there. Make sure you type the user name and password in upper case on that pop up. You've enabled the admin user in the config files so try that first. If you're going to use a different user then you don't need to enable admin. I tend not to use admin myself but to get this off the ground, we can rule out user config by using admin.

  • 0 in reply to Vega

    Yes, I did that, used the admin credentials, still didn't work

  • 0 in reply to don dausi

    In IIS when you click on Default Web Site and open the Authentication. You should only have Anonymous Authentication enabled. All others should be disabled.

    Then...

    Open localhost/sage300webapi and when it loads, click on the blue button to open the swagger ui. Expand ARCustomers. Click on the last GET which takes a customer number parameter. The parameters listed should be SAMLTD as the company unless you have changed the default in the config. In the customer number put 1200 click Try it Out! When the prompt pops up, put in your admin user name and password in upper case. Do you get anything back? The URL will be this 

    https://localhost/Sage300WebApi/V1.0/-/SAMLTD/AR/ARCustomers('1200')

    So you can copy that and paste it into a browser and it will (should) return the JSON. If you're getting a 401 it means you have not authorized.

  • 0 in reply to Mr. Mbithi

    Give that sage webapi user access to all modules in Sage300. Then sign into the webscreens (/sage300) as that user to confirm that they have rights to Sage300.

Reply Children