Xero - beautiful accounting software

Xero Developer Help Center

Xero Developer Community

Community > API Endpoints >

Contact payment terms - java

Started by Jason Raikes -   in API Endpoints

I am using the JAVA SDK and retrieving a contact from Xero. I would like to know the payment terms of a contact. However, I do not see any properties of the contact class for the payment terms.

Please can someone point me in the correct direction?
Hi Jason,

Make sure you are using the latest version of the SDK 2.2.16

The follow lines of code should do the trick now.

ApiClient apiClientForAccounting = new ApiClient(config.getApiUrl(),null,null,null);
AccountingApi accountingApi = new AccountingApi(config);
accountingApi.setApiClient(apiClientForAccounting);
accountingApi.setOAuthToken(token, tokenSecret);

// you need a valid contact id for oneContactID variable.
Contacts contact = accountingApi.getContact(oneContactID);
System.out.println("PaymentTerms DAY" + contact.getContacts().get(0).getPaymentTerms().getBills().getDay());


 

Sidney Maestre (Community Manager)  

Sidney,

Thank you for that - I was using the wrong contact class (com.xero.model.contact)!

However, although some of the contacts contain payment terms, they all return a null value for the getPaymentTerms() property.

 

Jason Raikes  

Hi Jason,

Not sure what to tell you. I've tested the code using the com.xero.models.accounting classes and I can successfully create a new Contact with the Payment Terms, then make an API call with the ID of the new Contact and read the PaymentTerms to the console. If the payment terms value is NULL, then i assume the contact you are working with does not have any payment terms set.

// CREATE contact
Contact contact = new Contact();
contact.setName("Foo" + SampleData.loadRandomNum());
contact.setEmailAddress("sid" + SampleData.loadRandomNum() + "@blah.com");
PaymentTerm paymentTerm = new PaymentTerm();
Bill bill = new Bill();
bill.setDay(15);
bill.setType(PaymentTermType.OFCURRENTMONTH);
Bill sale = new Bill();
sale.setDay(10);
sale.setType(PaymentTermType.DAYSAFTERBILLMONTH);
paymentTerm.setBills(bill);
paymentTerm.setSales(sale);
contact.setPaymentTerms(paymentTerm);
Contacts newContact = accountingApi.createContact(contact);

UUID oneContactID = newContact.getContacts().get(0).getContactID();
Contacts oneContact = accountingApi.getContact(oneContactID);
System.out.println("PaymentTerms Bill Day" + oneContact.getContacts().get(0).getPaymentTerms().getBills().getDay());
System.out.println("PaymentTerms Sale Day" + oneContact.getContacts().get(0).getPaymentTerms().getSales().getDay());
 

Sidney Maestre (Community Manager)  

Sidney,

I did not create the contact or the payment terms using the XERO api. The contact and their payment terms were entered through the standard XERO user interface. I can retrieve addresses and similar properties through the API but get nulls for the payment terms.

 

Jason Raikes  

Hi Jason,

Here is a screencast where I update the Payment Terms in the Xero UI, then using the ContactID, retrieve the data via the API.

https://www.screencast.com/t/VC01VYQ9
 

Sidney Maestre (Community Manager)  

OK - thank you for that.

I got it to work by creating a query against XERO for each contact as in your example. However, I am iterating for each contact and ran into the 60 calls per minute limit.

I originally tried the following:
Contacts contacts = accountingApi.getContacts(null, null , null, null, null, true);
for (int x = 0; x<contacts.getContacts().size(); x++) {
Contact cont = contacts.getContacts().get(x);
System.out.println(cont.getName() + ", " + cont.getPaymentTerms());
}

But like this I got a null for the payment terms although it is a single call to the API.

Any ideas please?
 

Jason Raikes  

Hi Jason,

I recommend using the page argument on getContacts to get 100 contacts back at a time to avoid hitting rate limits.

Contacts contacts = accountingApi.getContacts(null, null, null, null, 1, false);

Have you tried checking if the payment terms are null in your loop?

if (contacts.getContacts().get(0).getPaymentTerms() == null)
{
System.out.println("I am null");
}

Hope this gets you going in the right direction.
 

Sidney Maestre (Community Manager)  

Sidney,

Thank you for that - got it working.
 

Jason Raikes