如何修复 Zoho api 返回"Please ensure LineItem has less than a 100 characters"时使用 C# Newtonsoft



我目前正在尝试创建发票并将其发送给Zoho Books。我设法使刷新令牌在经过一段时间后工作,现在当尝试通过发票发送时,我得到以下响应:代码:15消息:"请确保lineItems少于100个字符。">

我猜这是因为我在LineItem部分的格式。你能告诉我哪里做错了吗。(仅供参考,我是一个新蜜蜂,所以这些东西对我来说相当困难)

下面是我在控制器中的代码:

SmsBodyInvoices smsBodyInvoices = new SmsBodyInvoices
{
//3127622000000075111
customer_id = customerIDNew,
reference_number = "Test refernce number",
date = "2013-11-17",
payment_terms = 15,
due_date = "2013-12-03",
discount = 0,
exchange_rate = 1,
lineItems = new lineItems
{ 
description = "test description",
item_order = 1,
bcy_rate = 1,
rate = 120,
quantity = 1,
unit = "",
discount_amount = 0,
header_name = "test header"
},
allow_partial_payments = true,
notes = "test note",
terms = "test termsn",
shipping_charge = 0,
adjustment = 0,
adjustment_description = "adjust desc",
};
var bodyNew = Newtonsoft.Json.JsonConvert.SerializeObject(smsBodyInvoices);
requestZohoInvoices.AddParameter("application / json; charset = UTF - 8", bodyNew, ParameterType.RequestBody);
IRestResponse responseZohoInvoices = clientZohoInvoices.Execute(requestZohoInvoices);
Console.WriteLine(responseZohoInvoices.Content);
Console.WriteLine(ParameterType.RequestBody);

模型代码


public class SmsBodyInvoices
{
public lineItems lineItems { get; set; }
public int customer_id { get; set; }
public string reference_number { get; set; }
public string date { get; set; }
public int payment_terms { get; set; }
public string due_date { get; set; }
public int discount { get; set; }
public int exchange_rate { get; set; }
public bool allow_partial_payments { get; set; }
public string notes { get; set; }
public string terms { get; set; }
public int shipping_charge { get; set; }
public int adjustment { get; set; }
public string adjustment_description { get; set; }

}
public class lineItems
{
public tags tags { get; set; }
public string description { get; set; }
public int item_order { get; set; }
public int bcy_rate { get; set; }
public int rate { get; set; }
public int quantity { get; set; }
public string unit { get; set; }
public int discount_amount { get; set; }
public int discount { get; set; }
public string header_name { get; set; }

}

术语" line item "有迹象表明可能会有几个。因此,您必须提供一个行项目列表。要做到这一点,像这样修改你的类:

public class SmsBodyInvoices
{
public IList<lineItems> line_items { get; set; } = new List<lineItems>();
// ...
}

创建数据时,添加像这样的行项:

SmsBodyInvoices smsBodyInvoices = new SmsBodyInvoices
{
//3127622000000075111
customer_id = customerIDNew,
// ...
};
smsBodyInvoices.line_items.Add(new lineItems
{ 
description = "test description",
item_order = 1,
bcy_rate = 1,
rate = 120,
quantity = 1,
unit = "",
discount_amount = 0,
header_name = "test header"
});
var bodyNew = Newtonsoft.Json.JsonConvert.SerializeObject(smsBodyInvoices);
// ...
有关c#中列表和集合的详细信息,请参阅此链接。

相关内容

  • 没有找到相关文章

最新更新