Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > API Endpoints >

Error while creating Batch Payment

Started by Asif Ahmad -   in API Endpoints

I am getting the 'Object reference not set to an instance of an object.' error when trying to create a Batch Payment even when I am setting all the properties. I am using api.BatchPayments.Create(batchPayment) endpoint from the C# SDK.

Please help me.

Thank you.


batchPayment = new BatchPayment();
batchPayment.Account = new Account();
batchPayment.Account.Id = Guid.Parse("MYBANKACCOUNTGUID");
batchPayment.Account.Code = "1111";
batchPayment.Code = "1111";
batchPayment.Date = DateTime.Today;
batchPayment.UpdatedDateUtc = DateTime.Now;
batchPayment.Details = "TEST";
batchPayment.IsReconciled = true;
batchPayment.Narrative = "TEST";
batchPayment.Particulars = " a";
batchPayment.Reference = " a";
batchPayment.Status = Xero.Api.Core.Model.Status.BatchPaymentStatus.Authorised;
batchPayment.Total = 198.00M;
batchPayment.Type = BatchPaymentType.RecBatch;//.PayBatch;

batchPayment.Payments = new List<BatchPaymentPayment>();

BatchPaymentPayment bpPayment = new BatchPaymentPayment();
bpPayment.Amount = 198.00M;
bpPayment.BankAccountNumber = "BANKACCOUNTNUMBER";
bpPayment.Code = "1111";
bpPayment.Details = "XYZ for INV-9095";
bpPayment.Invoice = new Invoice();
bpPayment.Invoice.Id = Guid.Parse("INVOICETOPAYGUID");
bpPayment.Reference = "Payment for INV-9095";
bpPayment.Narrative = " a";
bpPayment.Particulars = " a";

Hi Asif,

From the code sample you have shared above, it looks like you are trying to call api.BatchPayments.Create before you have made the batchPayment object. You would need to call api.BatchPayments.Create(batchPayment) after you have done batchPayment = new BatchPayment() and assigned the values. Let me know if I have misunderstood the issue you are having.


Niamh Burns (Xero Staff)  

Hi Niamh,
Thank you for your reply.

The code is just to show what function I am using and not the sequence and of-course object can't be used before declaration in this instance.


Asif Ahmad