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 Reply Children
  • 0 in reply to 5108963

    Thanks, Just did that but still same error.

    I am not sure of what am doing wrong.

  • 0 in reply to Djshweiz

    Have you checked the trace logs? They are in your Sage300\Online\WebApi\Logs, Sage300\Online\Web\Logs, and Sage300\Online\Worker\Logs. When you try and make a request and you get the unauthorised message, it should give you more in there. There might be more in the IIS logs which are probably in one of the C:\inetpub\logs\LogFiles\W3SVC# folders.

    If they don't throw anything up, then we'll start from the beginning. I only just set up the web API on a new server yesterday.

  • 0 in reply to Vega

    Sage300\Online\WebApi\Logs I have

    Timestamp: 3/8/2022 9:37:13 AM
    Message: Error-[Tenant:] [Company:] [Module:] [User:] - Sage 300 Web API encountered an error for Url 'maina-pc/.../TXTaxGroups
    Exception Source:
    Exception Type: System.UnauthorizedAccessException
    Exception Message: Attempted to perform an unauthorized operation.
    ---- Stack Trace ----

    Machine Name: MAINA-PC

    on  C:\Sage\Sage 300 ERP\Online\Worker\Logs  I have

    Timestamp: 3/4/2022 11:52:44 AM

    Message: Critical-[Tenant:] [Company:] [Module:Worker Role] [User:] - The windows service failed to start.:
    (Inner Exception)
    (Inner Exception)
    Exception Source:
    Exception Type: System.ComponentModel.Win32Exception
    Exception Message: The wait operation timed out

    --- Stack Trace ----

    (Outer Exception)
    Exception Source: .Net SqlClient Data Provider
    Exception Type: System.Data.SqlClient.SqlException
    Exception Message: A network-related or instance-specific error occurred while establishing a connection to SQL Server. The server was not found or was not accessible. Verify that the instance name is correct and that SQL Server is configured to allow remote connections. (provider: TCP Provider, error: 0 - The wait operation timed out.)

    Sage300\Online\Web\Logs

    no logs

    C:\inetpub\logs\LogFiles\W3SVC1

    2022-03-08 09:37:12 172.16.4.30 POST /CRM/eware.dll/Do SID=202525542041132&Act=432&Mode=1&CLk=T&Key0=4&func=baseUrl&dotnetdll=ImportPage&dotnetfunc=GetImportPage&Option=Synchronize 80 - 172.16.4.30 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/99.0.4844.51+Safari/537.36 maina-pc/.../Do 200 0 0 473
    2022-03-08 09:37:12 172.16.4.30 GET /CRM/Themes/custom/RedefinedStyles.css 20220308123712814 80 - 172.16.4.30 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/99.0.4844.51+Safari/537.36 maina-pc/.../Do 200 0 0 0
    2022-03-08 09:37:12 172.16.4.30 GET /CRM/eware.dll/Do SID=202525542041132&Act=1696&Mode=1&CLk=T&FldCoachingActionID=ActACCPAC/Config_DropdownsKey0&AAct=432 80 - 172.16.4.30 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/99.0.4844.51+Safari/537.36 maina-pc/.../Do 200 0 0 18
    2022-03-08 09:37:12 172.16.4.30 GET /sdata/crmj/userdata SID=202525542041132&Action=getNotifications 80 - 172.16.4.30 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/99.0.4844.51+Safari/537.36 maina-pc/.../Do 404 0 2 0
    2022-03-08 09:37:12 172.16.4.30 GET /sdata/crmj/userdata SID=202525542041132&Action=getNotificationOptions 80 - 172.16.4.30 Mozilla/5.0+(Windows+NT+10.0;+Win64;+x64)+AppleWebKit/537.36+(KHTML,+like+Gecko)+Chrome/99.0.4844.51+Safari/537.36 maina-pc/.../Do 404 0 2 0

  • 0 in reply to Djshweiz

    Could it be my IIS setup? or sage - crm versions incompatibility? (sage 2020  update 7 and CRM 2021 R2)

  • 0 in reply to Djshweiz

    Looking at this request URL (http://maina-pc/Sage300WebApi/v1.0/-/CHECOM/TX/TXTaxGroups?$select=TaxGroupKey,TransactionType,Description%27) it looks like the permissions are not set up. So when setting up a user for web API, you are using the CRM user. I wouldn't as that is just for the CRM integration. Create another one (WEBAPI or something else) as a user that cannot change passwords and it doesn't expire. Then go into Security Groups create a group called WEBAPI and apply it to AP, AR, Admin services, Bank Services, Common Services, GL, and Tax Services and tick all for each. Save as you go. Then in User Authorisations, apply that group to AP, AR, AS, Bank, CS, GL, and Tax. That will give the user maximum permissions without admin. You can alter the access later. Then log into Sage with that user AT LEAST ONCE, and ALSO log into Web Screens AT LEAST ONCE to ensure that the user works. If you can't log in, it is most likely the portal database needs reintsalling.

  • 0 in reply to Vega

    Created  the user WEBAPI with all the rights. I can connect  on desktop app but on web am getting the below error.

  • 0 in reply to Djshweiz

    I'd reinstall web screens and portal and make sure you're on the latest PU and try that again. Something isn't right with your installation.

  • 0 in reply to Vega

    Thank you all, I reinstalled everything from IIS to sage CRM and everything worked.

    I suspect sage installation was not okay plus IIS.

    I used  https://www.acutedata.com/iis-features-needed-web-screens/ to setup iis