Solved

REST API Response "< script > window.open ("/Main","_top"); < /script > "

  • 10 October 2023
  • 3 replies
  • 174 views

Badge

I created a console application to test the API token behavior, how it works with multiple users and API limits. The console app does the following:

  1. Calls the token endpoint by passing username/password.
  2. It receives the token and does a GET appointment 50 records API call.
  3. There is 20 second wait
  4. Because our license has Max 20 API users limit, I am running the above steps for 22 users to verify the behavior. It run synchronously for one user after another, not in parallel.

Observations:

  1. Sometimes I get the 200 status and Response “<script>window.open("/Main","_top");</script>” in Appointment Get call
  2. In the screen System Monitor → Active Users, I notice it always maintains 20 users list. It removes the oldest active user from the list. But still I can use the token of the user which is not in the Active User list anymore and make API calls.

Questions:

  1. What is the reason for the error “<script>window.open("/Main","_top");</script>” ?
  2. I have a use case to build app where around 30 users will need to make REST API calls in parallel. Because I am able to use the token of users not present in the “Active Users” screen, Can I use any number of API users using token endpoint until the token expires or do you think I will face the API limit? If I will face API limit issue, what issue would it be?
  3.  

 

icon

Best answer by rajeshmishra90 13 November 2023, 18:57

View original

3 replies

Userlevel 3
Badge

Hello @rajeshmishra90 !

Could you post the API query your console application is using, minus any authentication details? This will help us troubleshoot and determine where the error messages might be coming from.

To answer your questions:

  1. I believe the “<script>window.open("/Main","_top");</script>” error message could appear due the following:
    1. The API request might be expiring before it can finish setting the location for the query.
    2. The API request call might need the location to be identified first with an async call. Example from https://stackoverflow.com/questions/20696041/window-openurl-blank-not-working-on-imac-safari:
      var windowReference = window.open();

      myService.getUrl().then(function(url) {
      windowReference.location = url;
      });
  2. In terms of API users and limits, your licensing will determine the maximum number of concurrent API requests. I’d check in with your account team if you have any questions or need adjustments.

    If you are hitting an API limit either due to the request expiring without a logout method attached (see Acumatica posting below for best practices) and/or the maximum number of API users are being utilized, it’s possible that the API queries will expire while in transit, the data won’t be pulled back, or your team will continue to see error messages.

Let me know if any of the above information helps, thanks!

Badge

@VladSushkin83 Thanks for your response! here is the code snippet for the API call:

internal static async Task<string> AuthenticateROPCMultipleAsync(IConfiguration _configuration, string _acumaticaBaseUrl, HttpClient _client, string userName, string password)
{
try
{
var requestUrl = $"{_acumaticaBaseUrl}/identity/connect/token";

var requestContent = new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("password", password),
new KeyValuePair<string, string>("username", userName),
new KeyValuePair<string, string>("client_id", _configuration["ClientId"]),
new KeyValuePair<string, string>("client_secret", "secret"),
new KeyValuePair<string, string>("scope", "api offline_access"),
new KeyValuePair<string, string>("grant_type", "password"),
});

var response = await _client.PostAsync(requestUrl, requestContent);
if (!response.IsSuccessStatusCode)
{
Console.WriteLine("Authentication returned error");
var exceptionDetails = await response.Content.ReadAsStringAsync();
Console.WriteLine(exceptionDetails);
return null;
}
var resContent = response.Content.ReadAsStringAsync().Result;
var auth = JsonConvert.DeserializeObject<AuthResponse>(resContent);
return auth.access_token;
}
catch (Exception)
{
return null;
}
}

internal class AuthResponse
{
public string access_token { get; set; }
public int expires_in { get; set; }
public string token_type { get; set; }
public string refresh_token { get; set; }
}
  1. I am unable to understand your point regarding the setting the location. I am making a call from the C# console application. The snippets attached are javascript so I am unable to follow it. Are you suggesting that I need to make modification to the way I am calling the Auth API?
  2. Regarding the license API Limits, I do know what the limits and I attached the screenshot as well. The issue is that I have 20 users API limit in my license and even if I have more than active 20 users, they all are working without any error. I was expecting an error but with the AUTH token I am not getting the API limit, so I am asking why is it so?
    1. I tried calling sign out with the token but it does not have any effect and I can still use the auth token to make appointment GET calls.
Badge

When I checked the system monitor for errors, I found that this error is coming due to login limit as I was assuming but got it confirmed. It's weird that I get 200 status with javascript code when the login limit is reached.

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