@@ -444,59 +444,73 @@ protected void doPost(HttpServletRequest request, HttpServletResponse response)
444444 String newFileName = "sample2.jpg" ;
445445
446446 // CREATE Accounts attachment
447+ where = "Status==\" ACTIVE\" " ;
447448 Accounts myAccounts = accountingApi .getAccounts (ifModifiedSince , where , order );
448- UUID accountID = myAccounts .getAccounts ().get (0 ).getAccountID ();
449- Attachments createdAttachments = accountingApi .createAccountAttachmentByFileName (accountID , newFileName , bytes );
450- messages .add ("Attachment to Account ID: " + accountID + " attachment - ID: " + createdAttachments .getAttachments ().get (0 ).getAttachmentID ());
451-
449+ if ( myAccounts .getAccounts ().size () > 0 ) {
450+ UUID accountID = myAccounts .getAccounts ().get (0 ).getAccountID ();
451+ Attachments createdAttachments = accountingApi .createAccountAttachmentByFileName (accountID , newFileName , bytes );
452+ messages .add ("Attachment to Account ID: " + accountID + " attachment - ID: " + createdAttachments .getAttachments ().get (0 ).getAttachmentID ());
453+ }
452454 // CREATE BankTransactions attachment
453455 BankTransactions myBanktransactions = accountingApi .getBankTransactions (ifModifiedSince , where , order , page );
454- UUID banktransactionID = myBanktransactions .getBankTransactions ().get (0 ).getBankTransactionID ();
455- Attachments createdBanktransationAttachments = accountingApi .createBankTransactionAttachmentByFileName (banktransactionID , newFileName , bytes );
456- messages .add ("Attachment to BankTransaction ID: " + banktransactionID + " attachment - ID: " + createdBanktransationAttachments .getAttachments ().get (0 ).getAttachmentID ());
457-
456+ if ( myBanktransactions .getBankTransactions ().size () > 0 ) {
457+ UUID banktransactionID = myBanktransactions .getBankTransactions ().get (0 ).getBankTransactionID ();
458+ Attachments createdBanktransationAttachments = accountingApi .createBankTransactionAttachmentByFileName (banktransactionID , newFileName , bytes );
459+ messages .add ("Attachment to BankTransaction ID: " + banktransactionID + " attachment - ID: " + createdBanktransationAttachments .getAttachments ().get (0 ).getAttachmentID ());
460+ }
458461 // CREATE BankTransfer attachment
462+ where = null ;
459463 BankTransfers myBankTransfer = accountingApi .getBankTransfers (ifModifiedSince , where , order );
460- UUID bankTransferID = myBankTransfer .getBankTransfers ().get (0 ).getBankTransferID ();
461- Attachments createdBankTransferAttachments = accountingApi .createBankTransferAttachmentByFileName (bankTransferID , newFileName , bytes );
462- messages .add ("Attachment to BankTransfer ID: " + bankTransferID + " attachment - ID: " + createdBankTransferAttachments .getAttachments ().get (0 ).getAttachmentID ());
463-
464+ if ( myBankTransfer .getBankTransfers ().size () > 0 ) {
465+ UUID bankTransferID = myBankTransfer .getBankTransfers ().get (0 ).getBankTransferID ();
466+ Attachments createdBankTransferAttachments = accountingApi .createBankTransferAttachmentByFileName (bankTransferID , newFileName , bytes );
467+ messages .add ("Attachment to BankTransfer ID: " + bankTransferID + " attachment - ID: " + createdBankTransferAttachments .getAttachments ().get (0 ).getAttachmentID ());
468+ }
464469 // CREATE Contacts attachment
470+ where = "Status==\" ACTIVE\" " ;
465471 Contacts myContacts = accountingApi .getContacts (ifModifiedSince , where , order , ids , page , includeArchived );
466- UUID contactID = myContacts .getContacts ().get (0 ).getContactID ();
467- Attachments createdContactAttachments = accountingApi .createContactAttachmentByFileName (contactID , newFileName , bytes );
468- messages .add ("Attachment to Contact ID: " + contactID + " attachment - ID: " + createdContactAttachments .getAttachments ().get (0 ).getAttachmentID ());
469-
472+ if ( myContacts .getContacts ().size () > 0 ) {
473+ UUID contactID = myContacts .getContacts ().get (0 ).getContactID ();
474+ Attachments createdContactAttachments = accountingApi .createContactAttachmentByFileName (contactID , newFileName , bytes );
475+ messages .add ("Attachment to Contact ID: " + contactID + " attachment - ID: " + createdContactAttachments .getAttachments ().get (0 ).getAttachmentID ());
476+ }
477+
470478 // CREATE CreditNotes attachment
471479 CreditNotes myCreditNotes = accountingApi .getCreditNotes (ifModifiedSince , where , order , page );
472- UUID creditNoteID = myCreditNotes .getCreditNotes ().get (0 ).getCreditNoteID ();
473- Attachments createdCreditNoteAttachments = accountingApi .createCreditNoteAttachmentByFileName (creditNoteID , newFileName , bytes );
474- messages .add ("Attachment to Credit Notes ID: " + creditNoteID + " attachment - ID: " + createdCreditNoteAttachments .getAttachments ().get (0 ).getAttachmentID ());
475-
480+ if ( myCreditNotes .getCreditNotes ().size () > 0 ) {
481+ UUID creditNoteID = myCreditNotes .getCreditNotes ().get (0 ).getCreditNoteID ();
482+ Attachments createdCreditNoteAttachments = accountingApi .createCreditNoteAttachmentByFileName (creditNoteID , newFileName , bytes );
483+ messages .add ("Attachment to Credit Notes ID: " + creditNoteID + " attachment - ID: " + createdCreditNoteAttachments .getAttachments ().get (0 ).getAttachmentID ());
484+ }
476485 // CREATE invoice attachment
477486 Invoices myInvoices = accountingApi .getInvoices (ifModifiedSince , where , order , ids , invoiceNumbers , contactIDs , statuses , page , includeArchived , createdByMyApp );
478- UUID invoiceID = myInvoices .getInvoices ().get (0 ).getInvoiceID ();
479- Attachments createdInvoiceAttachments = accountingApi .createInvoiceAttachmentByFileName (invoiceID , newFileName , bytes );
480- messages .add ("Attachment to Invoice ID: " + invoiceID + " attachment - ID: " + createdInvoiceAttachments .getAttachments ().get (0 ).getAttachmentID ());
481-
487+ if ( myInvoices .getInvoices ().size () > 0 ) {
488+ UUID invoiceID = myInvoices .getInvoices ().get (0 ).getInvoiceID ();
489+ Attachments createdInvoiceAttachments = accountingApi .createInvoiceAttachmentByFileName (invoiceID , newFileName , bytes );
490+ messages .add ("Attachment to Invoice ID: " + invoiceID + " attachment - ID: " + createdInvoiceAttachments .getAttachments ().get (0 ).getAttachmentID ());
491+ }
482492 // CREATE ManualJournals attachment
483493 ManualJournals myManualJournals = accountingApi .getManualJournals (ifModifiedSince , where , order , page );
484- UUID manualJournalID = myManualJournals .getManualJournals ().get (0 ).getManualJournalID ();
485- Attachments createdManualJournalAttachments = accountingApi .createManualJournalAttachmentByFileName (manualJournalID , newFileName , bytes );
486- messages .add ("Attachment to Manual Journal ID: " + manualJournalID + " attachment - ID: " + createdManualJournalAttachments .getAttachments ().get (0 ).getAttachmentID ());
487-
494+ if ( myManualJournals .getManualJournals ().size () > 0 ) {
495+ UUID manualJournalID = myManualJournals .getManualJournals ().get (0 ).getManualJournalID ();
496+ Attachments createdManualJournalAttachments = accountingApi .createManualJournalAttachmentByFileName (manualJournalID , newFileName , bytes );
497+ messages .add ("Attachment to Manual Journal ID: " + manualJournalID + " attachment - ID: " + createdManualJournalAttachments .getAttachments ().get (0 ).getAttachmentID ());
498+ }
488499 // CREATE Receipts attachment
489500 Receipts myReceipts = accountingApi .getReceipts (ifModifiedSince , where , order );
490- UUID receiptID = myReceipts .getReceipts ().get (0 ).getReceiptID ();
491- Attachments createdReceiptsAttachments = accountingApi .createReceiptAttachmentByFileName (receiptID , newFileName , bytes );
492- messages .add ("Attachment to Receipt ID: " + receiptID + " attachment - ID: " + createdReceiptsAttachments .getAttachments ().get (0 ).getAttachmentID ());
493-
501+ if ( myReceipts .getReceipts ().size () > 0 ) {
502+ UUID receiptID = myReceipts .getReceipts ().get (0 ).getReceiptID ();
503+ Attachments createdReceiptsAttachments = accountingApi .createReceiptAttachmentByFileName (receiptID , newFileName , bytes );
504+ messages .add ("Attachment to Receipt ID: " + receiptID + " attachment - ID: " + createdReceiptsAttachments .getAttachments ().get (0 ).getAttachmentID ());
505+ }
494506 // CREATE Repeating Invoices attachment
495507 RepeatingInvoices myRepeatingInvoices = accountingApi .getRepeatingInvoices (where , order );
496- UUID repeatingInvoiceID = myRepeatingInvoices .getRepeatingInvoices ().get (0 ).getRepeatingInvoiceID ();
497- Attachments createdRepeatingInvoiceAttachments = accountingApi .createRepeatingInvoiceAttachmentByFileName (repeatingInvoiceID , newFileName , bytes );
498- messages .add ("Attachment to Repeating Invoices ID: " + repeatingInvoiceID + " attachment - ID: " + createdRepeatingInvoiceAttachments .getAttachments ().get (0 ).getAttachmentID ());
499-
508+ if ( myRepeatingInvoices .getRepeatingInvoices ().size () > 0 ) {
509+ UUID repeatingInvoiceID = myRepeatingInvoices .getRepeatingInvoices ().get (0 ).getRepeatingInvoiceID ();
510+ Attachments createdRepeatingInvoiceAttachments = accountingApi .createRepeatingInvoiceAttachmentByFileName (repeatingInvoiceID , newFileName , bytes );
511+ messages .add ("Attachment to Repeating Invoices ID: " + repeatingInvoiceID + " attachment - ID: " + createdRepeatingInvoiceAttachments .getAttachments ().get (0 ).getAttachmentID ());
512+ }
513+ where = null ;
500514 } else if (object .equals ("Assets" )) {
501515 /* Asset */
502516 // Create Asset
0 commit comments