Home > Back-end >  How to fix Zoho api returns "Please ensure LineItem has less than a 100 characters" when u
How to fix Zoho api returns "Please ensure LineItem has less than a 100 characters" when u

Time:06-29

I'm currently trying to create a invoice and send it to Zoho Books. I managed to get the refresh token working after ages and now when trying to send through an invoice, I get the following response: code: 15 message: "Please ensure that the lineItems has less than 100 characters."

I am guessing it is because my formatting in out in the LineItem part. Any suggestions on what I could be doing wrong. (FYI, I am a newbee so this stuff is pretty difficult for me)

Here is my code in the controller:

 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);

And here is the model code


    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; }


    }

CodePudding user response:

Instead of having just one line item, the term "line items" hints that there could be several. Hence you have to provide a list of line items. To do so, change your classes like this:

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

When creating the data, add a line item like this:

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);
// ...

For details on lists and collections in C#, see this link.

  • Related