-1

I'm using the latest Xero java client api's downloaded via gradle:

compile group: 'com.xero', name: 'xero-java-sdk', version: '1.0.9'
compile group: 'com.xero', name: 'xero-accounting-api-schema', version: '0.1.2'

And I'm trying to create an invoice using this code:

Contact xeroContact = xeroClient.getContact(xeroContactId);
xeroInvoice.setContact(xeroContact);
xeroInvoice.setType(InvoiceType.ACCREC);
xeroInvoice.setStatus(InvoiceStatus.AUTHORISED);
xeroInvoice.setCurrencyCode(CurrencyCode.AUD);

xeroInvoice.setBrandingThemeID(invoicingConfig.xeroBrandingThemeId);
xeroInvoice.setSentToContact(true);
xeroInvoice.setLineAmountTypes(LineAmountType.INCLUSIVE);

GregorianCalendar calendar = new GregorianCalendar();
calendar.setTime(Date.from(Instant.ofEpochSecond(timestamp)));
xeroInvoice.setDate(calendar);
xeroInvoice.setDueDate(calendar);

ArrayOfLineItem lineItems = new ArrayOfLineItem();
LineItem lineItem = new LineItem();
lineItem.setAccountCode(invoicingConfig.xeroAccountCode);
lineItem.setQuantity(BigDecimal.ONE);
lineItem.setDescription(chargeDescription);
lineItem.setUnitAmount(chargeAmount);
lineItems.getLineItem().add(lineItem);
xeroInvoice.setLineItems(lineItems);

xeroInvoice.setAmountPaid(chargeAmount);

return xeroClient.createInvoices(Arrays.asList(xeroInvoice)).get(0);

and parameters:

xeroContactId: "f283d2c5-24a8-4e78-9b66-44c5d391a089"
timestamp: 1534133124
chargeDescription: "Dedicated Bronze Num"
chargeAmount: 55.00

(xeroContactId is being read from our database)

And on our production server, for those parameters I'm continuously getting back:

com.xero.api.XeroClient - com.xero.api.XeroApiException: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN""http://www.w3.org/TR/html4/strict.dtd">
<HTML><HEAD><TITLE>Bad Request</TITLE>
<META HTTP-EQUIV="Content-Type" Content="text/html; charset=us-ascii"></HEAD>
<BODY><h2>Bad Request - Invalid URL</h2>
<hr><p>HTTP Error 400. The request URL is invalid.</p>
</BODY></HTML>

This doesn't seem to be a valid Xero api error response.

  • I'm not sure what kind of response or answer you expect here but wouldn't this question be better asked on Xero's support forum or issue tracker? – Phil Aug 22 '18 at 05:32
  • Just answered it myself. Feel it could be useful to someone else. I originally went to post this to their github issue tracker and mistakenly believed I did not have permission to post. – mrkhingston Aug 22 '18 at 05:40
  • It might be useful if a) you show where `xeroContactId` was coming from, and b) where the newline character was coming from and how you eliminated it – Phil Aug 22 '18 at 05:41
  • Thanks. I've tried to edit the question and answer to fit with what you've mentioned. I've also posted an issue on the Xero github: https://github.com/XeroAPI/Xero-Java/issues/93 – mrkhingston Aug 22 '18 at 05:54

1 Answers1

0

What I thought I was sending was:

xeroContactId: "f283d2c5-24a8-4e78-9b66-44c5d391a089"

but my parameter value was actually: "\nf283d2c5-24a8-4e78-9b66-44c5d391a089"

which produced an escaped url that when I accessed it caused the error shown above.

The newline was introduced by a typo when entering a manual change in our database.

I found this out only by chance when a different GET request used that same contact id from our database. I never found a good/easy way to debug the url that the POST was hitting.

  • So just a typo? Where was the newline coming from? Your question shows `xeroContactId` already defined – Phil Aug 22 '18 at 05:36