首页 > 解决方案 > 销售订单行的 Acumatica rest API PUT 不断返回 500 错误

问题描述

我一直在尝试使用 Acumatica 上的销售线上传销售订单REST API,但我一直收到500错误消息。

我正在使用默认的销售订单端点。当我注释掉SalesOrderDetail列表时,它成功了,所以我认为这就是问题所在。

PUT方法:

public async Task<bool> PutSalesOrdersAsync(Models.AcumaticaSalesOrder customer)
{
    if (await Login() == false) return false;

    var uri = new Uri(settings.url + settings.endpoint + "SalesOrder"); //?$filter=Location eq 'MAIN'&$top=10");
    try
    {
        var json = JsonConvert.SerializeObject(customer);
        var stringContent = new StringContent(json, Encoding.UTF8, "application/json");

        var response = await client.PutAsync(uri, stringContent);
        if (response.IsSuccessStatusCode)
        {
            //var content = await response.Content.ReadAsStringAsync();
            //Customers = JsonConvert.DeserializeObject<List<Models.AcumaticaCustomer>>(content);
        }
        else
        {
            err = await response.Content.ReadAsStringAsync();

            try
            {
                ResponseMessage msg = JsonConvert.DeserializeObject<ResponseMessage>(err);
                if (msg != null && msg.exceptionMessage != "") err = msg.exceptionMessage;
                return false;
            }
            catch (Exception ex)
            {
                err = ex.Message;
                return false;
            }
        }
    }
    catch (Exception ex)
    {
        Debug.WriteLine(@"              ERROR {0}", ex.Message);
        err = ex.Message;
        return false;
    }

    return true;
}

Acumatica 销售订单设置:

public async Task<AcumaticaSalesOrder> ToAcumaticaSalesOrderAsync()
{
    AcumaticaSalesOrder c = new AcumaticaSalesOrder();

    c.CurrencyID = new StringField { value = this.CurrencyID };
    c.CustomerID = new StringField { value = this.CustomerID };
   // c.OrderSummaryCustomerName = new StringField { value = this.OrderSummaryCustomerName };
    c.CustomerOrder = new StringField { value = this.CustomerOrder };
    c.Date = new DateTimeField { value = this.Date };
    c.Description = new StringField { value = this.Description };
    c.FinancialSettings = new Models.AcumaticaSalesOrderFinancialSettings();
    c.FinancialSettings.InvoiceNbr = new StringField { value = this.InvoiceNbr };
    c.LocationID = new StringField { value = this.LocationID };
    c.OrderNbr = new StringField { value = this.OrderNbr };
    c.OrderTotal = new DecimalField { value = this.OrderTotal };
    c.OrderedQty = new DecimalField { value = this.OrderedQty };
    c.OrderType = new StringField { value = this.OrderType };
    c.Status = new StringField { value = this.Status };
    c.Totals = new Models.AcumaticaSalesOrderTotals();
    c.Totals.LineTotalAmount = new DecimalField { value = this.LineTotalAmount };
    c.Totals.MiscTotalAmount = new DecimalField { value = this.MiscTotalAmount };
    c.TaxTotal = new DecimalField { value = this.TaxTotal };

    c.Details = new List<AcumaticaSalesOrderDetail>();
    c.Details = await GetSalesOrderLineAsync();

    return c;
}

private async Task<List<AcumaticaSalesOrderDetail>> GetSalesOrderLineAsync()
{
    AASDatabase db = new AASDatabase();
    List<Models.AcumaticaSalesOrderDetail> asols = new List<AcumaticaSalesOrderDetail>();
    List <Models.SalesOrderDetail> sols = await db.GetSalesOrderDetailByOrderNbrAsync(OrderNbr);
    foreach (Models.SalesOrderDetail sol in sols)
    {
        Models.AcumaticaSalesOrderDetail c = new AcumaticaSalesOrderDetail();
        c.LineNbr = new IntField { value = sol.LineNbr };
        c.DiscountAmount = new DecimalField { value = sol.DiscountAmount };
        c.LineType = new StringField { value = sol.LineType }; ;
        c.LineDescription = new StringField { value = sol.LineDescription };
        c.InventoryID = new StringField { value = sol.InventoryID };
        c.UOM = new StringField { value = sol.UOM };
        c.WarehouseID = new StringField { value = sol.WarehouseID };

        c.OrderQty = new DecimalField { value = sol.OrderQty };
        c.UnitPrice = new DecimalField { value = sol.UnitPrice };
        asols.Add(c);
    }
    return asols;
}

标签: c#apiacumatica

解决方案


代码是正确的。我发送的 json 不是正确的销售订单类型。这put是唯一的剂量类型 SO。


推荐阅读