【问题标题】:Acumatica REST API from Generic query returns only first record来自通用查询的 Acumatica REST API 仅返回第一条记录
【发布时间】:2021-08-31 11:44:26
【问题描述】:

我扩展了默认 web 服务端点并为通用查询创建了一个端点。它运行良好,但仅返回字符串预算项中通用查询的第一条记录。当我在 Acumatica 中手动“查看查询”时,大约有 100 个记录。创建端点时,我确实为结果创建了一个详细对象。我不明白为什么它返回的次数不超过第一条记录。

任何帮助将不胜感激。见以下代码:

  using System;
  using System.Collections.Generic;
  using System.ComponentModel;
  using System.Data;
  using System.Drawing;
  using System.Linq;
  using System.Text;
  using System.Threading.Tasks;
  using System.Data.SqlClient;
  using System.Net;
  using System.Net.Http;
  using System.Net.Http.Headers;
  using System.Web.Script.Serialization;

  namespace AcmBudTrxToAzure
  {
      class Program
  {
      static void Main(string[] args)
      {
        RestService rs = new RestService("https://acmsite.acumatica.com");           

        string parameters = "";
       
        string json2 = "{\"implicit:array:implicit:object\": [{\"\" : { } } ] }";
        
        string budgetitems = rs.Put("GLBudTrx", parameters, json2);

        Console.WriteLine("got here");

        Console.Write("Press  to exit... ");
        while (Console.ReadKey().Key != ConsoleKey.Enter)
        {
            //run loop until Enter is press
        }

    }

    public class RestService : IDisposable
    {
        private readonly HttpClient _httpClient;
        public readonly string _acumaticaBaseUrl;

        public RestService(
        string acumaticaBaseUrl)
        {
            _acumaticaBaseUrl = acumaticaBaseUrl;
            _httpClient = new HttpClient(
            new HttpClientHandler
            {
                UseCookies = true,
                CookieContainer = new CookieContainer()
            })
            {
                BaseAddress = new Uri(acumaticaBaseUrl +
                  "/entity/auth/login"),
                DefaultRequestHeaders =
                {
                    Accept = { MediaTypeWithQualityHeaderValue.Parse("text/json")}
                }
            };
            //Log in to Acumatica ERP
            
            clsUser Usr = new clsUser();
            string nm = Usr.clsUserInfo.name;
            string pw = Usr.clsUserInfo.password;
            string cmp = Usr.clsUserInfo.company;
            string br = Usr.clsUserInfo.branch;
            string lc = Usr.clsUserInfo.locale;
            //var usrInfo = Usr.clsUserInfo;
            var str = new StringContent(
            new JavaScriptSerializer()
            .Serialize(
               new
               {
                   name = nm,
                   password = pw,
                   company = cmp,
                   branch = br,
                   locale = lc
               }),
               Encoding.UTF8, "application/json");
            
            var response = _httpClient.PostAsync(
               acumaticaBaseUrl + "/entity/auth/login",
                str).Result.EnsureSuccessStatusCode();
        }

        void IDisposable.Dispose()
        {
            _httpClient.PostAsync(_acumaticaBaseUrl + "/entity/auth/logout",
                new ByteArrayContent(new byte[0])).Wait();
            _httpClient.Dispose();
        }

        public string Get(string entityName, string parameters)
        {
            var res = _httpClient.GetAsync(
            _acumaticaBaseUrl + "/entity/acmsiteEndpoint/20.200.001/"
            + entityName + "?" + parameters).Result
            .EnsureSuccessStatusCode();
            return res.Content.ReadAsStringAsync().Result;

        }

        public string Put(string entityName, string parameters, string entity)
        {

            var res = _httpClient
            .PutAsync(_acumaticaBaseUrl + "/entity/acmsiteEndpoint/20.200.001/" +
                               entityName + "?$expand=Results" ,
            new StringContent(entity, Encoding.UTF8, "application/json"))
            .Result
            .EnsureSuccessStatusCode();

            return res.Content.ReadAsStringAsync().Result;


        }
    }
}

}

【问题讨论】:

    标签: acumatica rest


    【解决方案1】:

    解决了这个问题。它不在代码中。我在 Acumatica 端点上重新生成了细节对象,它现在可以工作了。不确定这是否重要,但我最初将详细对象命名为“结果”,当我重新生成它时,我将其更改为其他内容。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-08-31
      • 1970-01-01
      • 2019-01-31
      • 2018-07-03
      • 2021-05-07
      • 1970-01-01
      相关资源
      最近更新 更多