Search code examples
javaquickbooksquickbooks-onlineintuit-partner-platform

QuickBooks Online Java SDK invoice creation always for the same customer


I'm referring to version v3 of the API using the Java SDK (v2.2.1). I'm using a trial account for testing, and I have 6 customers stored. The first customer I created has display name 'Abe Lincoln'. Whenever I try to create invoices for a customer using their associated customer ID (retrieved from the API by querying the display name), the invoices are created successfully but every one of them is associated with the customer 'Abe Lincoln' !!

Here's the invoice creation code. I ran it with hardcoded values just to be sure:

Invoice invoice = new Invoice();
invoice.setDocNumber("DocNum");

ReferenceType customerRef = new ReferenceType();
customerRef.setValue("4");  // display name = 'Joe Bloggs'
invoice.setCustomerRef(customerRef);

Line line = new Line();
line.setAmount( new BigDecimal(50) );
line.setDetailType(LineDetailTypeEnum.SALES_ITEM_LINE_DETAIL);

SalesItemLineDetail salesItemLineDetail = new SalesItemLineDetail();
ReferenceType itemRef = customerRef;

itemRef.setName("ProductName");
itemRef.setValue("1");
salesItemLineDetail.setItemRef(itemRef);
line.setSalesItemLineDetail(salesItemLineDetail);

List<Line> linesList = new ArrayList<Line>();
linesList.add(line);
invoice.setLine(linesList);

invoice.setPrivateNote("PrivateNote");
batch.addEntity(invoice, OperationEnum.CREATE, idx + "");

...and after running this, an invoice is created in my account for the customer 'Abe Lincoln'. The display name for the customer with id "4" is actually 'Joe Bloggs'. I've tried it with the values 2 through to 6 (which are all valid for other customers) but no matter what the result is the same. Can anyone suggest what's happening here?


Solution

  • you are overwriting value with 1 at later part.

    ReferenceType itemRef = customerRef;
    
    itemRef.setName("ProductName");
    itemRef.setValue("1");
    

    create a new ReferenceType object here...

    ReferenceType itemRef = new ReferenceType();`