Solved

authApi.Login() hangs up


Userlevel 1

Hello everyone,


First time poster here.  I have used the GitHub “endpoint model generator” solution to generate the DLL’s I need to allow my C# application to connect to our Acumatica instance with our extended endpoint and the RESTAPI dll’s (Acumatica.RESTClient.dll and Acumatica.RESTClient.ContractBasedApi.dll that get compiled along with my endpoint dll.

I am using Visual Studio 2022 and C#.

I have been unable as of yet to figure out why the authApi.Login() function just locks up the app.

This is the content of the request (that was put together by the Acumatica code) as it looks immediately before being passed to the Client.SendAsync(request) call that hangs up. 

 

{Method: POST, RequestUri: 'https://<ouracumaticadomain>/AcumaticaERP1//entity/auth/login', Version: 1.1, Content: System.Net.Http.StringContent, Headers:
{
  Content-Type: application/json; charset=utf-8
}}
    Content: {System.Net.Http.StringContent}
    HasHeaders: false
    Headers: {}
    Method: {POST}
    Options: {System.Net.Http.HttpRequestOptions}
    Properties: {System.Net.Http.HttpRequestOptions}
    RequestUri: {https://<ouracumaticadomain>/AcumaticaERP1//entity/auth/login}
    Version: {1.1}
    VersionPolicy: RequestVersionOrLower
    _content: {System.Net.Http.StringContent}
    _disposed: false
    _headers: {}
    _method: {POST}
    _options: {System.Net.Http.HttpRequestOptions}
    _requestUri: {https://<ouracumaticadomain>/AcumaticaERP1//entity/auth/login}
    _sendStatus: 0
    _version: {1.1}
    _versionPolicy: RequestVersionOrLower

 

The only thing I have noted is that the credentials (and body) appear to not be present in the call:

Has anyone seen this issue, and if so, please advise on how to get past it.  I’ve got all the other functions ready to be tested, I just can’t get logged in.  I suspected the double-slash might be an issue in the URL but it’s not.

My code has the following:

var authApi = new AuthApi(APILoginUrl, requestInterceptor: RequestLogger.LogRequest, responseInterceptor: RequestLogger.LogResponse);
Credentials credentials = new Credentials(APIUserName,APIPassword,"","", "");

authApi.LogIn(credentials);


and I’ve even tried bypassing the credentials object and sending the uid and pwd directly in:


authApi.LogIn(APIUserName, APIPassword);

 

We only have one tenant, so the last 3 values are not required in the login credentials object.

The requestlogger is logging this:

-----------------------------------------

5/8/2024 2:53:09 PM
Request
    Method: POST
    URL: https://<ouracumaticadomain>/AcumaticaERP1//entity/auth/login
    Body: {"name":"<ouruserid>","password":"<ourpassword>"}
-----------------------------------------


I can step into the LogIn code, but once it gets to the function in the ApiClient.cs: 

public async Task<HttpResponseMessage> CallApiAsync(...)

 

it hits this line and hangs:


var response = await Client.SendAsync(request);

I can successfully connect to our instance using Postman and query objects - and the same credentials used in PostMan are the ones I have set into my code here that refuses to ever return from the await call.

Can anyone help?

icon

Best answer by Dmitrii Naumov 9 May 2024, 16:43

View original

8 replies

Userlevel 7
Badge +5

Hello @pjames , 

This is because of the async. 

In some execution contexts async may cause these side effects. 

Please use the latest version of the client where async is handled properly:  https://www.nuget.org/packages/Acumatica.RESTClient/5.1.2-beta

Userlevel 1

Thanks a ton! I’ve spent the last 6 days trying to figure out what was wrong...

I’ve downloaded the DLL package for the 5.1.2 beta version from your link and applied it to my project; but now visual studio is complaining about Acumatica.Auth.Api and Acumatica.Auth.Model
 


Also, the links to the source on the beta page look like they link back to the 4.1 source.  If possible, I’d like to apply the beta project source to the solution that contains the endpoint model generator so that I can build them all together along with my extended endpoint and have access to debugging info.  Would that be possible?

Userlevel 7
Badge +5

Hi @pjames , 

Yes, the namespaces structure has been changed in this new  version. 

For the Auth you’ll need 
using static Acumatica.RESTClient.AuthApi.AuthApiExtensions;

from https://www.nuget.org/packages/Acumatica.RESTClient.ContractBasedApi/5.1.1-beta

 

As for the source, it’s in the same repo in the 5.0 branch

https://github.com/Acumatica/AcumaticaRESTAPIClientForCSharp/tree/5.0

Userlevel 1

Thanks again Dmitrii,

 

I downloaded the full set of source, but now it’s complaining that the ModelGeneratorUI cannot find the Dependency project EndpointModelGenerator - even though the .csproj file is there.

 


So I built the endpointmodelgenerator to get the dll created, but when I go to try and fix the project reference to the new dll I get the following:
 

 

Userlevel 1

It’s me again, sorry if I am being annoying :)

I got past the above problem by removing the Dependency to the EndpointModelGenerator project from the UI project, then re-adding it (and it showed up under Dependency->Assemblies after that instead of Dependencies->Projects) and it was able to run.

However, when it tries to connect to my extended endpoint project it is now complaining about  NewtonSoft.Json:
 

I realize that I am trying to use a beta version now, but I’m kind of stuck not being able to use the most stable release version or this latest beta to move forward.  Any suggestions?

Userlevel 1

UPDATE!

I added the missing reference to NewtonSoft.JSon that was missing from the EndpointModelGenerator project, then I ran ‘dotnet test’ through an administrator command prompt on all 3 projects.  The UI project reference to the modelgenerator project did not have to be removed and re-added (which converts it to an assembly reference).

Now that there was no error I was able to run the UI and regenerate my new extended endpoint API and Model classes in the class project I added to the REST API project using the beta code.

Appreciate your help with this!  Keep up the good work!!!

Userlevel 1

It took some extra tweaking to line up the method access to the new beta code, but I’ve been able to get past the login issue now.  Now to see if my invoice creation code actually works :) Thanks again!

Userlevel 1

This will probably be my last post in this thread.  I have been able to successfully log in, AND create an AR Invoice with detail lines via the REST API using Basic Auth.

Something to note - I was struggling with an error 500, but the requestlogger that I kept intact from the samples allowed me to get to the detail I needed to validate through PostMan.  I was able to copy the URL and the Body into PostMan and send it, at which point it gave me specific messages on the fields it had issues with.

The API was just returning an internal server error, but PostMan was able to tell me two things:
 

  1. The “Type” needed to be changed to “Invoice” - I was using “IN”
  2. One of my extended custom fields could not be found; I’ll have to ensure I extended the endpoint for that field properly.

After updating the type and removing the field it couldn’t find, it successfully created my invoice through the REST API Beta 5.x code.

Once again thank you for the help!

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved