Skip to main content
Question

REST API: why does retrieving a Sales Price row (AR202000 screen) take so long using HttpClient?


Forum|alt.badge.img+2

Since converting from SOAP, I’ve run into C# issues related specifically to the Sales Price (AR202000) page.  For instance, when using a PUT method to create a brand new Sales Price row, I need to use a CancellationToken to timeout after 5 seconds.  Otherwise, I need to wait 5+ minutes to get a response back (InnerException: Error while copying content to a stream).  This is very strange since there is no wait time at all using Postman.  This isn’t my biggest concern since I’ve worked around it with the timeout/cancellation.

My biggest problem occurs when using a PUT method just to retrieve a Sales Price row (using InventoryID/PriceType/PriceCode).  This can take anywhere between 1 second to 5 minutes just to retrieve a response.  I need to do this to retrieve the RecordID, which is a new REST requirement for deleting specific SalePrice rows.  I don’t receive any response errors like I do trying to create the Sales Price row.  This is drastically increasing the processing time compared to my SOAP implementation.  These particular REST issues aren’t happening with other Acumatica page as I haven’t run into these kind of issues before using HttpClient.

Did anyone else run into these issues or found a way around the huge extended wait time?

Here my code (the sharedClient is of type HttpClient/RESTmethod is the URL):

            var json = JsonSerializer.Serialize(body);
            var httpContent = new StringContent(json, Encoding.UTF8, "application/json");

            sharedClient.DefaultRequestHeaders.Accept.Clear();
            sharedClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
            string result = string.Empty;

            using (CancellationTokenSource cancelAfterDelay = new CancellationTokenSource(TimeSpan.FromSeconds(seconds)))
            {
                var response = new HttpResponseMessage();
                if (post)
                    response = sharedClient.PostAsync(RESTmethod, httpContent, cancelAfterDelay.Token).Result;
                else
                    response = sharedClient.PutAsync(RESTmethod, httpContent, cancelAfterDelay.Token).Result;

                var respBody = response.Content.ReadAsStringAsync();
                result = respBody.Result;
            }
 

4 replies

RohitRattan88
Acumatica Moderator
Forum|alt.badge.img+4
  • Acumatica Moderator
  • 245 replies
  • July 15, 2024

@bpgraves Strange that Postman works fine but you are getting issues for c# client. have you looked into C# client @ GitHub - Acumatica/AcumaticaRESTAPIClientForCSharp


Forum|alt.badge.img+2
  • Author
  • Semi-Pro I
  • 61 replies
  • July 15, 2024
RohitRattan88 wrote:

@bpgraves Strange that Postman works fine but you are getting issues for c# client. have you looked into C# client @ GitHub - Acumatica/AcumaticaRESTAPIClientForCSharp

No I haven’t since the highest version offered is 22.200.001 and we’re in the process of upgrading to 2024R1.


Chris Hackett
Community Manager
Forum|alt.badge.img
  • Acumatica Community Manager
  • 2640 replies
  • August 19, 2024

Hi @bpgraves were you able to find a solution? Thank you!


Forum|alt.badge.img+2
  • Author
  • Semi-Pro I
  • 61 replies
  • August 21, 2024
Chris Hackett wrote:

Hi @bpgraves were you able to find a solution? Thank you!

I had to remove the cancellation token and add a filter to the top level JSON for InventoryID.  This drastically improved the time it took to insert a new SalesPrice and also removed my need to retrieve the added SalesPrice. Here’s more info:

 

This isn’t really a solution the question I asked but I currently don’t have a need to do what I asked.  If anyone else found a way to speed up the retrieval of an existing SalesPrice, please post your solution here.


Reply


Cookie policy

We use cookies to enhance and personalize your experience. If you accept you agree to our full cookie policy. Learn more about our cookies.

 
Cookie settings