
com.xero.api.client.AccountingApi Maven / Gradle / Ivy
/*
* Xero Accounting API
* No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
*
* The version of the OpenAPI document: 6.3.0
* Contact: [email protected]
*
* NOTE: This class is auto generated by OpenAPI Generator (https://openapi-generator.tech).
* https://openapi-generator.tech
* Do not edit the class manually.
*/
package com.xero.api.client;
import com.fasterxml.jackson.core.type.TypeReference;
import com.google.api.client.auth.oauth2.BearerToken;
import com.google.api.client.auth.oauth2.Credential;
import com.google.api.client.http.ByteArrayContent;
import com.google.api.client.http.FileContent;
import com.google.api.client.http.GenericUrl;
import com.google.api.client.http.HttpContent;
import com.google.api.client.http.HttpHeaders;
import com.google.api.client.http.HttpMethods;
import com.google.api.client.http.HttpRequestFactory;
import com.google.api.client.http.HttpResponse;
import com.google.api.client.http.HttpResponseException;
import com.google.api.client.http.HttpTransport;
import com.xero.api.ApiClient;
import com.xero.api.XeroApiExceptionHandler;
import com.xero.models.accounting.Account;
import com.xero.models.accounting.Accounts;
import com.xero.models.accounting.Actions;
import com.xero.models.accounting.Allocation;
import com.xero.models.accounting.Allocations;
import com.xero.models.accounting.Attachments;
import com.xero.models.accounting.BankTransactions;
import com.xero.models.accounting.BankTransfers;
import com.xero.models.accounting.BatchPaymentDelete;
import com.xero.models.accounting.BatchPaymentDeleteByUrlParam;
import com.xero.models.accounting.BatchPayments;
import com.xero.models.accounting.BrandingThemes;
import com.xero.models.accounting.Budgets;
import com.xero.models.accounting.CISOrgSettings;
import com.xero.models.accounting.CISSettings;
import com.xero.models.accounting.ContactGroups;
import com.xero.models.accounting.Contacts;
import com.xero.models.accounting.CreditNotes;
import com.xero.models.accounting.Currencies;
import com.xero.models.accounting.Currency;
import com.xero.models.accounting.Employees;
import com.xero.models.accounting.ExpenseClaims;
import com.xero.models.accounting.HistoryRecords;
import com.xero.models.accounting.ImportSummaryObject;
import com.xero.models.accounting.InvoiceReminders;
import com.xero.models.accounting.Invoices;
import com.xero.models.accounting.Items;
import com.xero.models.accounting.Journals;
import com.xero.models.accounting.LinkedTransaction;
import com.xero.models.accounting.LinkedTransactions;
import com.xero.models.accounting.ManualJournals;
import com.xero.models.accounting.OnlineInvoices;
import com.xero.models.accounting.Organisations;
import com.xero.models.accounting.Overpayments;
import com.xero.models.accounting.Payment;
import com.xero.models.accounting.PaymentDelete;
import com.xero.models.accounting.PaymentServices;
import com.xero.models.accounting.Payments;
import com.xero.models.accounting.Prepayments;
import com.xero.models.accounting.PurchaseOrders;
import com.xero.models.accounting.Quotes;
import com.xero.models.accounting.Receipts;
import com.xero.models.accounting.RepeatingInvoices;
import com.xero.models.accounting.ReportWithRows;
import com.xero.models.accounting.Reports;
import com.xero.models.accounting.RequestEmpty;
import com.xero.models.accounting.Setup;
import com.xero.models.accounting.TaxRates;
import com.xero.models.accounting.TrackingCategories;
import com.xero.models.accounting.TrackingCategory;
import com.xero.models.accounting.TrackingOption;
import com.xero.models.accounting.TrackingOptions;
import com.xero.models.accounting.Users;
import jakarta.ws.rs.core.UriBuilder;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.threeten.bp.LocalDate;
import org.threeten.bp.OffsetDateTime;
/** AccountingApi has methods for interacting with all endpoints in the API set */
public class AccountingApi {
private ApiClient apiClient;
private static AccountingApi instance = null;
private String userAgent = "Default";
private String version = "8.3.0";
static final Logger logger = LoggerFactory.getLogger(AccountingApi.class);
/** AccountingApi */
public AccountingApi() {
this(new ApiClient());
}
/**
* AccountingApi getInstance
*
* @param apiClient ApiClient pass into the new instance of this class
* @return instance of this class
*/
public static AccountingApi getInstance(ApiClient apiClient) {
if (instance == null) {
instance = new AccountingApi(apiClient);
}
return instance;
}
/**
* AccountingApi
*
* @param apiClient ApiClient pass into the new instance of this class
*/
public AccountingApi(ApiClient apiClient) {
this.apiClient = apiClient;
}
/**
* get ApiClient
*
* @return apiClient the current ApiClient
*/
public ApiClient getApiClient() {
return apiClient;
}
/**
* set ApiClient
*
* @param apiClient ApiClient pass into the new instance of this class
*/
public void setApiClient(ApiClient apiClient) {
this.apiClient = apiClient;
}
/**
* set user agent
*
* @param userAgent string to override the user agent
*/
public void setUserAgent(String userAgent) {
this.userAgent = userAgent;
}
/**
* get user agent
*
* @return String of user agent
*/
public String getUserAgent() {
return this.userAgent + " [Xero-Java-" + this.version + "]";
}
/**
* Creates a new chart of accounts
*
* 200 - Success - created new Account and return response of type Accounts array with
* new Account
*
*
400 - Validation Error - some data was incorrect returns response of type Error
*
* @param xeroTenantId Xero identifier for Tenant
* @param account Account object in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return Accounts
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public Accounts createAccount(
String accessToken, String xeroTenantId, Account account, String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createAccountForHttpResponse(accessToken, xeroTenantId, account, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createAccount -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("Accounts", object.getMessage(), e);
}
handler.validationError("Accounts", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates a new chart of accounts
*
* 200 - Success - created new Account and return response of type Accounts array with
* new Account
*
*
400 - Validation Error - some data was incorrect returns response of type Error
*
* @param xeroTenantId Xero identifier for Tenant
* @param account Account object in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createAccountForHttpResponse(
String accessToken, String xeroTenantId, Account account, String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling createAccount");
} // verify the required parameter 'account' is set
if (account == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'account' when calling createAccount");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling createAccount");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/json");
headers.setUserAgent(this.getUserAgent());
UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/Accounts");
String url = uriBuilder.build().toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
HttpContent content = null;
content = apiClient.new JacksonJsonHttpContent(account);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
// Overload params for createAccountAttachmentByFileName to allow byte[] or File type to be passed
// as body
/**
* Creates an attachment on a specific account
*
*
200 - Success - return response of type Attachments array of Attachment
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param accountID Unique identifier for Account object
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param mimeType The type of file being attached
* @param accessToken Authorization token for user set in header of each request
* @return Attachments
* @throws IOException if an error occurs while attempting to invoke the API
*/
public Attachments createAccountAttachmentByFileName(
String accessToken,
String xeroTenantId,
UUID accountID,
String fileName,
byte[] body,
String idempotencyKey,
String mimeType)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createAccountAttachmentByFileNameForHttpResponse(
accessToken, xeroTenantId, accountID, fileName, body, idempotencyKey, mimeType);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createAccountAttachmentByFileName -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
handler.execute(e);
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates an attachment on a specific account
*
* 200 - Success - return response of type Attachments array of Attachment
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param accountID Unique identifier for Account object
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param mimeType The type of file being attached
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public HttpResponse createAccountAttachmentByFileNameForHttpResponse(
String accessToken,
String xeroTenantId,
UUID accountID,
String fileName,
byte[] body,
String idempotencyKey,
String mimeType)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling"
+ " createAccountAttachmentByFileName");
} // verify the required parameter 'accountID' is set
if (accountID == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accountID' when calling"
+ " createAccountAttachmentByFileName");
} // verify the required parameter 'fileName' is set
if (fileName == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'fileName' when calling"
+ " createAccountAttachmentByFileName");
} // verify the required parameter 'body' is set
if (body == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'body' when calling createAccountAttachmentByFileName");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling"
+ " createAccountAttachmentByFileName");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/octet-stream");
headers.setUserAgent(this.getUserAgent());
// create a map of path variables
final Map uriVariables = new HashMap();
uriVariables.put("AccountID", accountID);
uriVariables.put("FileName", fileName);
UriBuilder uriBuilder =
UriBuilder.fromUri(
apiClient.getBasePath() + "/Accounts/{AccountID}/Attachments/{FileName}");
String url = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
ByteArrayContent content = null;
content = new ByteArrayContent(mimeType, body);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Creates an attachment on a specific account
*
* 200 - Success - return response of type Attachments array of Attachment
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param accountID Unique identifier for Account object
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return Attachments
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public Attachments createAccountAttachmentByFileName(
String accessToken,
String xeroTenantId,
UUID accountID,
String fileName,
File body,
String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createAccountAttachmentByFileNameForHttpResponse(
accessToken, xeroTenantId, accountID, fileName, body, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createAccountAttachmentByFileName -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("Attachments", object.getMessage(), e);
}
handler.validationError("Attachments", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates an attachment on a specific account
*
* 200 - Success - return response of type Attachments array of Attachment
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param accountID Unique identifier for Account object
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createAccountAttachmentByFileNameForHttpResponse(
String accessToken,
String xeroTenantId,
UUID accountID,
String fileName,
File body,
String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling"
+ " createAccountAttachmentByFileName");
} // verify the required parameter 'accountID' is set
if (accountID == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accountID' when calling"
+ " createAccountAttachmentByFileName");
} // verify the required parameter 'fileName' is set
if (fileName == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'fileName' when calling"
+ " createAccountAttachmentByFileName");
} // verify the required parameter 'body' is set
if (body == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'body' when calling createAccountAttachmentByFileName");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling"
+ " createAccountAttachmentByFileName");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/octet-stream");
headers.setUserAgent(this.getUserAgent());
// create a map of path variables
final Map uriVariables = new HashMap();
uriVariables.put("AccountID", accountID);
uriVariables.put("FileName", fileName);
UriBuilder uriBuilder =
UriBuilder.fromUri(
apiClient.getBasePath() + "/Accounts/{AccountID}/Attachments/{FileName}");
String url = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
java.nio.file.Path bodyPath = body.toPath();
String mimeType = java.nio.file.Files.probeContentType(bodyPath);
HttpContent content = null;
content = new FileContent(mimeType, body);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
// Overload params for createBankTransactionAttachmentByFileName to allow byte[] or File type to
// be passed as body
/**
* Creates an attachment for a specific bank transaction by filename
*
* 200 - Success - return response of Attachments array of Attachment
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param bankTransactionID Xero generated unique identifier for a bank transaction
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param mimeType The type of file being attached
* @param accessToken Authorization token for user set in header of each request
* @return Attachments
* @throws IOException if an error occurs while attempting to invoke the API
*/
public Attachments createBankTransactionAttachmentByFileName(
String accessToken,
String xeroTenantId,
UUID bankTransactionID,
String fileName,
byte[] body,
String idempotencyKey,
String mimeType)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createBankTransactionAttachmentByFileNameForHttpResponse(
accessToken,
xeroTenantId,
bankTransactionID,
fileName,
body,
idempotencyKey,
mimeType);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createBankTransactionAttachmentByFileName -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
handler.execute(e);
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates an attachment for a specific bank transaction by filename
*
* 200 - Success - return response of Attachments array of Attachment
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param bankTransactionID Xero generated unique identifier for a bank transaction
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param mimeType The type of file being attached
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public HttpResponse createBankTransactionAttachmentByFileNameForHttpResponse(
String accessToken,
String xeroTenantId,
UUID bankTransactionID,
String fileName,
byte[] body,
String idempotencyKey,
String mimeType)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling"
+ " createBankTransactionAttachmentByFileName");
} // verify the required parameter 'bankTransactionID' is set
if (bankTransactionID == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'bankTransactionID' when calling"
+ " createBankTransactionAttachmentByFileName");
} // verify the required parameter 'fileName' is set
if (fileName == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'fileName' when calling"
+ " createBankTransactionAttachmentByFileName");
} // verify the required parameter 'body' is set
if (body == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'body' when calling"
+ " createBankTransactionAttachmentByFileName");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling"
+ " createBankTransactionAttachmentByFileName");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/octet-stream");
headers.setUserAgent(this.getUserAgent());
// create a map of path variables
final Map uriVariables = new HashMap();
uriVariables.put("BankTransactionID", bankTransactionID);
uriVariables.put("FileName", fileName);
UriBuilder uriBuilder =
UriBuilder.fromUri(
apiClient.getBasePath()
+ "/BankTransactions/{BankTransactionID}/Attachments/{FileName}");
String url = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
ByteArrayContent content = null;
content = new ByteArrayContent(mimeType, body);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Creates an attachment for a specific bank transaction by filename
*
* 200 - Success - return response of Attachments array of Attachment
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param bankTransactionID Xero generated unique identifier for a bank transaction
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return Attachments
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public Attachments createBankTransactionAttachmentByFileName(
String accessToken,
String xeroTenantId,
UUID bankTransactionID,
String fileName,
File body,
String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createBankTransactionAttachmentByFileNameForHttpResponse(
accessToken, xeroTenantId, bankTransactionID, fileName, body, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createBankTransactionAttachmentByFileName -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("Attachments", object.getMessage(), e);
}
handler.validationError("Attachments", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates an attachment for a specific bank transaction by filename
*
* 200 - Success - return response of Attachments array of Attachment
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param bankTransactionID Xero generated unique identifier for a bank transaction
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createBankTransactionAttachmentByFileNameForHttpResponse(
String accessToken,
String xeroTenantId,
UUID bankTransactionID,
String fileName,
File body,
String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling"
+ " createBankTransactionAttachmentByFileName");
} // verify the required parameter 'bankTransactionID' is set
if (bankTransactionID == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'bankTransactionID' when calling"
+ " createBankTransactionAttachmentByFileName");
} // verify the required parameter 'fileName' is set
if (fileName == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'fileName' when calling"
+ " createBankTransactionAttachmentByFileName");
} // verify the required parameter 'body' is set
if (body == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'body' when calling"
+ " createBankTransactionAttachmentByFileName");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling"
+ " createBankTransactionAttachmentByFileName");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/octet-stream");
headers.setUserAgent(this.getUserAgent());
// create a map of path variables
final Map uriVariables = new HashMap();
uriVariables.put("BankTransactionID", bankTransactionID);
uriVariables.put("FileName", fileName);
UriBuilder uriBuilder =
UriBuilder.fromUri(
apiClient.getBasePath()
+ "/BankTransactions/{BankTransactionID}/Attachments/{FileName}");
String url = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
java.nio.file.Path bodyPath = body.toPath();
String mimeType = java.nio.file.Files.probeContentType(bodyPath);
HttpContent content = null;
content = new FileContent(mimeType, body);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Creates a history record for a specific bank transactions
*
* 200 - Success - return response of type HistoryRecords array of HistoryRecord objects
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param bankTransactionID Xero generated unique identifier for a bank transaction
* @param historyRecords HistoryRecords containing an array of HistoryRecord objects in body of
* request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HistoryRecords
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public HistoryRecords createBankTransactionHistoryRecord(
String accessToken,
String xeroTenantId,
UUID bankTransactionID,
HistoryRecords historyRecords,
String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createBankTransactionHistoryRecordForHttpResponse(
accessToken, xeroTenantId, bankTransactionID, historyRecords, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createBankTransactionHistoryRecord -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("HistoryRecords", object.getMessage(), e);
}
handler.validationError("HistoryRecords", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates a history record for a specific bank transactions
*
* 200 - Success - return response of type HistoryRecords array of HistoryRecord objects
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param bankTransactionID Xero generated unique identifier for a bank transaction
* @param historyRecords HistoryRecords containing an array of HistoryRecord objects in body of
* request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createBankTransactionHistoryRecordForHttpResponse(
String accessToken,
String xeroTenantId,
UUID bankTransactionID,
HistoryRecords historyRecords,
String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling"
+ " createBankTransactionHistoryRecord");
} // verify the required parameter 'bankTransactionID' is set
if (bankTransactionID == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'bankTransactionID' when calling"
+ " createBankTransactionHistoryRecord");
} // verify the required parameter 'historyRecords' is set
if (historyRecords == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'historyRecords' when calling"
+ " createBankTransactionHistoryRecord");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling"
+ " createBankTransactionHistoryRecord");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/json");
headers.setUserAgent(this.getUserAgent());
// create a map of path variables
final Map uriVariables = new HashMap();
uriVariables.put("BankTransactionID", bankTransactionID);
UriBuilder uriBuilder =
UriBuilder.fromUri(
apiClient.getBasePath() + "/BankTransactions/{BankTransactionID}/History");
String url = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
HttpContent content = null;
content = apiClient.new JacksonJsonHttpContent(historyRecords);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Creates one or more spent or received money transaction
*
* 200 - Success - return response of type BankTransactions array with new
* BankTransaction
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param bankTransactions BankTransactions with an array of BankTransaction objects in body of
* request
* @param summarizeErrors If false return 200 OK and mix of successfully created objects and any
* with validation errors
* @param unitdp e.g. unitdp=4 – (Unit Decimal Places) You can opt in to use four decimal
* places for unit amounts
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return BankTransactions
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public BankTransactions createBankTransactions(
String accessToken,
String xeroTenantId,
BankTransactions bankTransactions,
Boolean summarizeErrors,
Integer unitdp,
String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createBankTransactionsForHttpResponse(
accessToken, xeroTenantId, bankTransactions, summarizeErrors, unitdp, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createBankTransactions -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("BankTransactions", object.getMessage(), e);
}
handler.validationError("BankTransactions", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates one or more spent or received money transaction
*
* 200 - Success - return response of type BankTransactions array with new
* BankTransaction
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param bankTransactions BankTransactions with an array of BankTransaction objects in body of
* request
* @param summarizeErrors If false return 200 OK and mix of successfully created objects and any
* with validation errors
* @param unitdp e.g. unitdp=4 – (Unit Decimal Places) You can opt in to use four decimal
* places for unit amounts
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createBankTransactionsForHttpResponse(
String accessToken,
String xeroTenantId,
BankTransactions bankTransactions,
Boolean summarizeErrors,
Integer unitdp,
String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling createBankTransactions");
} // verify the required parameter 'bankTransactions' is set
if (bankTransactions == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'bankTransactions' when calling createBankTransactions");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling createBankTransactions");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/json");
headers.setUserAgent(this.getUserAgent());
UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/BankTransactions");
if (summarizeErrors != null) {
String key = "summarizeErrors";
Object value = summarizeErrors;
if (value instanceof Collection) {
List valueList = new ArrayList<>((Collection) value);
if (!valueList.isEmpty() && valueList.get(0) instanceof UUID) {
List list = new ArrayList();
for (int i = 0; i < valueList.size(); i++) {
list.add(valueList.get(i).toString());
}
uriBuilder = uriBuilder.queryParam(key, String.join(",", list));
} else {
uriBuilder = uriBuilder.queryParam(key, String.join(",", valueList));
}
} else if (value instanceof Object[]) {
uriBuilder = uriBuilder.queryParam(key, (Object[]) value);
} else {
uriBuilder = uriBuilder.queryParam(key, value);
}
}
if (unitdp != null) {
String key = "unitdp";
Object value = unitdp;
if (value instanceof Collection) {
List valueList = new ArrayList<>((Collection) value);
if (!valueList.isEmpty() && valueList.get(0) instanceof UUID) {
List list = new ArrayList();
for (int i = 0; i < valueList.size(); i++) {
list.add(valueList.get(i).toString());
}
uriBuilder = uriBuilder.queryParam(key, String.join(",", list));
} else {
uriBuilder = uriBuilder.queryParam(key, String.join(",", valueList));
}
} else if (value instanceof Object[]) {
uriBuilder = uriBuilder.queryParam(key, (Object[]) value);
} else {
uriBuilder = uriBuilder.queryParam(key, value);
}
}
String url = uriBuilder.build().toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
HttpContent content = null;
content = apiClient.new JacksonJsonHttpContent(bankTransactions);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Creates a bank transfer
*
* 200 - Success - return response of BankTransfers array of one BankTransfer
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param bankTransfers BankTransfers with array of BankTransfer objects in request body
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return BankTransfers
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public BankTransfers createBankTransfer(
String accessToken, String xeroTenantId, BankTransfers bankTransfers, String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createBankTransferForHttpResponse(
accessToken, xeroTenantId, bankTransfers, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createBankTransfer -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("BankTransfers", object.getMessage(), e);
}
handler.validationError("BankTransfers", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates a bank transfer
*
* 200 - Success - return response of BankTransfers array of one BankTransfer
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param bankTransfers BankTransfers with array of BankTransfer objects in request body
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createBankTransferForHttpResponse(
String accessToken, String xeroTenantId, BankTransfers bankTransfers, String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling createBankTransfer");
} // verify the required parameter 'bankTransfers' is set
if (bankTransfers == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'bankTransfers' when calling createBankTransfer");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling createBankTransfer");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/json");
headers.setUserAgent(this.getUserAgent());
UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/BankTransfers");
String url = uriBuilder.build().toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
HttpContent content = null;
content = apiClient.new JacksonJsonHttpContent(bankTransfers);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
// Overload params for createBankTransferAttachmentByFileName to allow byte[] or File type to be
// passed as body
/**
* 200 - Success - return response of Attachments array of 0 to N Attachment for a Bank
* Transfer
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param bankTransferID Xero generated unique identifier for a bank transfer
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param mimeType The type of file being attached
* @param accessToken Authorization token for user set in header of each request
* @return Attachments
* @throws IOException if an error occurs while attempting to invoke the API
*/
public Attachments createBankTransferAttachmentByFileName(
String accessToken,
String xeroTenantId,
UUID bankTransferID,
String fileName,
byte[] body,
String idempotencyKey,
String mimeType)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createBankTransferAttachmentByFileNameForHttpResponse(
accessToken, xeroTenantId, bankTransferID, fileName, body, idempotencyKey, mimeType);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createBankTransferAttachmentByFileName -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
handler.execute(e);
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* 200 - Success - return response of Attachments array of 0 to N Attachment for a Bank
* Transfer
*
* 400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param bankTransferID Xero generated unique identifier for a bank transfer
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param mimeType The type of file being attached
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public HttpResponse createBankTransferAttachmentByFileNameForHttpResponse(
String accessToken,
String xeroTenantId,
UUID bankTransferID,
String fileName,
byte[] body,
String idempotencyKey,
String mimeType)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling"
+ " createBankTransferAttachmentByFileName");
} // verify the required parameter 'bankTransferID' is set
if (bankTransferID == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'bankTransferID' when calling"
+ " createBankTransferAttachmentByFileName");
} // verify the required parameter 'fileName' is set
if (fileName == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'fileName' when calling"
+ " createBankTransferAttachmentByFileName");
} // verify the required parameter 'body' is set
if (body == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'body' when calling"
+ " createBankTransferAttachmentByFileName");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling"
+ " createBankTransferAttachmentByFileName");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/octet-stream");
headers.setUserAgent(this.getUserAgent());
// create a map of path variables
final Map uriVariables = new HashMap();
uriVariables.put("BankTransferID", bankTransferID);
uriVariables.put("FileName", fileName);
UriBuilder uriBuilder =
UriBuilder.fromUri(
apiClient.getBasePath() + "/BankTransfers/{BankTransferID}/Attachments/{FileName}");
String url = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
ByteArrayContent content = null;
content = new ByteArrayContent(mimeType, body);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* 200 - Success - return response of Attachments array of 0 to N Attachment for a Bank
* Transfer
*
* 400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param bankTransferID Xero generated unique identifier for a bank transfer
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return Attachments
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public Attachments createBankTransferAttachmentByFileName(
String accessToken,
String xeroTenantId,
UUID bankTransferID,
String fileName,
File body,
String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createBankTransferAttachmentByFileNameForHttpResponse(
accessToken, xeroTenantId, bankTransferID, fileName, body, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createBankTransferAttachmentByFileName -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("Attachments", object.getMessage(), e);
}
handler.validationError("Attachments", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* 200 - Success - return response of Attachments array of 0 to N Attachment for a Bank
* Transfer
*
* 400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param bankTransferID Xero generated unique identifier for a bank transfer
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createBankTransferAttachmentByFileNameForHttpResponse(
String accessToken,
String xeroTenantId,
UUID bankTransferID,
String fileName,
File body,
String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling"
+ " createBankTransferAttachmentByFileName");
} // verify the required parameter 'bankTransferID' is set
if (bankTransferID == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'bankTransferID' when calling"
+ " createBankTransferAttachmentByFileName");
} // verify the required parameter 'fileName' is set
if (fileName == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'fileName' when calling"
+ " createBankTransferAttachmentByFileName");
} // verify the required parameter 'body' is set
if (body == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'body' when calling"
+ " createBankTransferAttachmentByFileName");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling"
+ " createBankTransferAttachmentByFileName");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/octet-stream");
headers.setUserAgent(this.getUserAgent());
// create a map of path variables
final Map uriVariables = new HashMap();
uriVariables.put("BankTransferID", bankTransferID);
uriVariables.put("FileName", fileName);
UriBuilder uriBuilder =
UriBuilder.fromUri(
apiClient.getBasePath() + "/BankTransfers/{BankTransferID}/Attachments/{FileName}");
String url = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
java.nio.file.Path bodyPath = body.toPath();
String mimeType = java.nio.file.Files.probeContentType(bodyPath);
HttpContent content = null;
content = new FileContent(mimeType, body);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Creates a history record for a specific bank transfer
*
* 200 - Success - return response of type HistoryRecords array of HistoryRecord objects
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param bankTransferID Xero generated unique identifier for a bank transfer
* @param historyRecords HistoryRecords containing an array of HistoryRecord objects in body of
* request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HistoryRecords
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public HistoryRecords createBankTransferHistoryRecord(
String accessToken,
String xeroTenantId,
UUID bankTransferID,
HistoryRecords historyRecords,
String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createBankTransferHistoryRecordForHttpResponse(
accessToken, xeroTenantId, bankTransferID, historyRecords, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createBankTransferHistoryRecord -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("HistoryRecords", object.getMessage(), e);
}
handler.validationError("HistoryRecords", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates a history record for a specific bank transfer
*
* 200 - Success - return response of type HistoryRecords array of HistoryRecord objects
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param bankTransferID Xero generated unique identifier for a bank transfer
* @param historyRecords HistoryRecords containing an array of HistoryRecord objects in body of
* request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createBankTransferHistoryRecordForHttpResponse(
String accessToken,
String xeroTenantId,
UUID bankTransferID,
HistoryRecords historyRecords,
String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling"
+ " createBankTransferHistoryRecord");
} // verify the required parameter 'bankTransferID' is set
if (bankTransferID == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'bankTransferID' when calling"
+ " createBankTransferHistoryRecord");
} // verify the required parameter 'historyRecords' is set
if (historyRecords == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'historyRecords' when calling"
+ " createBankTransferHistoryRecord");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling"
+ " createBankTransferHistoryRecord");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/json");
headers.setUserAgent(this.getUserAgent());
// create a map of path variables
final Map uriVariables = new HashMap();
uriVariables.put("BankTransferID", bankTransferID);
UriBuilder uriBuilder =
UriBuilder.fromUri(apiClient.getBasePath() + "/BankTransfers/{BankTransferID}/History");
String url = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
HttpContent content = null;
content = apiClient.new JacksonJsonHttpContent(historyRecords);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Creates one or many batch payments for invoices
*
* 200 - Success - return response of type BatchPayments array of BatchPayment objects
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param batchPayments BatchPayments with an array of Payments in body of request
* @param summarizeErrors If false return 200 OK and mix of successfully created objects and any
* with validation errors
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return BatchPayments
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public BatchPayments createBatchPayment(
String accessToken,
String xeroTenantId,
BatchPayments batchPayments,
Boolean summarizeErrors,
String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createBatchPaymentForHttpResponse(
accessToken, xeroTenantId, batchPayments, summarizeErrors, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createBatchPayment -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("BatchPayments", object.getMessage(), e);
}
handler.validationError("BatchPayments", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates one or many batch payments for invoices
*
* 200 - Success - return response of type BatchPayments array of BatchPayment objects
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param batchPayments BatchPayments with an array of Payments in body of request
* @param summarizeErrors If false return 200 OK and mix of successfully created objects and any
* with validation errors
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createBatchPaymentForHttpResponse(
String accessToken,
String xeroTenantId,
BatchPayments batchPayments,
Boolean summarizeErrors,
String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling createBatchPayment");
} // verify the required parameter 'batchPayments' is set
if (batchPayments == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'batchPayments' when calling createBatchPayment");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling createBatchPayment");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/json");
headers.setUserAgent(this.getUserAgent());
UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/BatchPayments");
if (summarizeErrors != null) {
String key = "summarizeErrors";
Object value = summarizeErrors;
if (value instanceof Collection) {
List valueList = new ArrayList<>((Collection) value);
if (!valueList.isEmpty() && valueList.get(0) instanceof UUID) {
List list = new ArrayList();
for (int i = 0; i < valueList.size(); i++) {
list.add(valueList.get(i).toString());
}
uriBuilder = uriBuilder.queryParam(key, String.join(",", list));
} else {
uriBuilder = uriBuilder.queryParam(key, String.join(",", valueList));
}
} else if (value instanceof Object[]) {
uriBuilder = uriBuilder.queryParam(key, (Object[]) value);
} else {
uriBuilder = uriBuilder.queryParam(key, value);
}
}
String url = uriBuilder.build().toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
HttpContent content = null;
content = apiClient.new JacksonJsonHttpContent(batchPayments);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Creates a history record for a specific batch payment
*
* 200 - Success - return response of type HistoryRecords array of HistoryRecord objects
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param batchPaymentID Unique identifier for BatchPayment
* @param historyRecords HistoryRecords containing an array of HistoryRecord objects in body of
* request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HistoryRecords
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public HistoryRecords createBatchPaymentHistoryRecord(
String accessToken,
String xeroTenantId,
UUID batchPaymentID,
HistoryRecords historyRecords,
String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createBatchPaymentHistoryRecordForHttpResponse(
accessToken, xeroTenantId, batchPaymentID, historyRecords, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createBatchPaymentHistoryRecord -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("HistoryRecords", object.getMessage(), e);
}
handler.validationError("HistoryRecords", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates a history record for a specific batch payment
*
* 200 - Success - return response of type HistoryRecords array of HistoryRecord objects
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param batchPaymentID Unique identifier for BatchPayment
* @param historyRecords HistoryRecords containing an array of HistoryRecord objects in body of
* request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createBatchPaymentHistoryRecordForHttpResponse(
String accessToken,
String xeroTenantId,
UUID batchPaymentID,
HistoryRecords historyRecords,
String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling"
+ " createBatchPaymentHistoryRecord");
} // verify the required parameter 'batchPaymentID' is set
if (batchPaymentID == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'batchPaymentID' when calling"
+ " createBatchPaymentHistoryRecord");
} // verify the required parameter 'historyRecords' is set
if (historyRecords == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'historyRecords' when calling"
+ " createBatchPaymentHistoryRecord");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling"
+ " createBatchPaymentHistoryRecord");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/json");
headers.setUserAgent(this.getUserAgent());
// create a map of path variables
final Map uriVariables = new HashMap();
uriVariables.put("BatchPaymentID", batchPaymentID);
UriBuilder uriBuilder =
UriBuilder.fromUri(apiClient.getBasePath() + "/BatchPayments/{BatchPaymentID}/History");
String url = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
HttpContent content = null;
content = apiClient.new JacksonJsonHttpContent(historyRecords);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Creates a new custom payment service for a specific branding theme
*
* 200 - Success - return response of type PaymentServices array with newly created
* PaymentService
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param brandingThemeID Unique identifier for a Branding Theme
* @param paymentServices PaymentServices array with PaymentService object in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return PaymentServices
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public PaymentServices createBrandingThemePaymentServices(
String accessToken,
String xeroTenantId,
UUID brandingThemeID,
PaymentServices paymentServices,
String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createBrandingThemePaymentServicesForHttpResponse(
accessToken, xeroTenantId, brandingThemeID, paymentServices, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createBrandingThemePaymentServices -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("PaymentServices", object.getMessage(), e);
}
handler.validationError("PaymentServices", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates a new custom payment service for a specific branding theme
*
* 200 - Success - return response of type PaymentServices array with newly created
* PaymentService
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param brandingThemeID Unique identifier for a Branding Theme
* @param paymentServices PaymentServices array with PaymentService object in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createBrandingThemePaymentServicesForHttpResponse(
String accessToken,
String xeroTenantId,
UUID brandingThemeID,
PaymentServices paymentServices,
String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling"
+ " createBrandingThemePaymentServices");
} // verify the required parameter 'brandingThemeID' is set
if (brandingThemeID == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'brandingThemeID' when calling"
+ " createBrandingThemePaymentServices");
} // verify the required parameter 'paymentServices' is set
if (paymentServices == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'paymentServices' when calling"
+ " createBrandingThemePaymentServices");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling"
+ " createBrandingThemePaymentServices");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/json");
headers.setUserAgent(this.getUserAgent());
// create a map of path variables
final Map uriVariables = new HashMap();
uriVariables.put("BrandingThemeID", brandingThemeID);
UriBuilder uriBuilder =
UriBuilder.fromUri(
apiClient.getBasePath() + "/BrandingThemes/{BrandingThemeID}/PaymentServices");
String url = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("POST " + genericUrl.toString());
}
HttpContent content = null;
content = apiClient.new JacksonJsonHttpContent(paymentServices);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.POST, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
// Overload params for createContactAttachmentByFileName to allow byte[] or File type to be passed
// as body
/**
* 200 - Success - return response of type Attachments array with an newly created
* Attachment
*
* 400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param contactID Unique identifier for a Contact
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param mimeType The type of file being attached
* @param accessToken Authorization token for user set in header of each request
* @return Attachments
* @throws IOException if an error occurs while attempting to invoke the API
*/
public Attachments createContactAttachmentByFileName(
String accessToken,
String xeroTenantId,
UUID contactID,
String fileName,
byte[] body,
String idempotencyKey,
String mimeType)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createContactAttachmentByFileNameForHttpResponse(
accessToken, xeroTenantId, contactID, fileName, body, idempotencyKey, mimeType);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createContactAttachmentByFileName -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
handler.execute(e);
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* 200 - Success - return response of type Attachments array with an newly created
* Attachment
*
* 400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param contactID Unique identifier for a Contact
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param mimeType The type of file being attached
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public HttpResponse createContactAttachmentByFileNameForHttpResponse(
String accessToken,
String xeroTenantId,
UUID contactID,
String fileName,
byte[] body,
String idempotencyKey,
String mimeType)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling"
+ " createContactAttachmentByFileName");
} // verify the required parameter 'contactID' is set
if (contactID == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'contactID' when calling"
+ " createContactAttachmentByFileName");
} // verify the required parameter 'fileName' is set
if (fileName == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'fileName' when calling"
+ " createContactAttachmentByFileName");
} // verify the required parameter 'body' is set
if (body == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'body' when calling createContactAttachmentByFileName");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling"
+ " createContactAttachmentByFileName");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/octet-stream");
headers.setUserAgent(this.getUserAgent());
// create a map of path variables
final Map uriVariables = new HashMap();
uriVariables.put("ContactID", contactID);
uriVariables.put("FileName", fileName);
UriBuilder uriBuilder =
UriBuilder.fromUri(
apiClient.getBasePath() + "/Contacts/{ContactID}/Attachments/{FileName}");
String url = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
ByteArrayContent content = null;
content = new ByteArrayContent(mimeType, body);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* 200 - Success - return response of type Attachments array with an newly created
* Attachment
*
* 400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param contactID Unique identifier for a Contact
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return Attachments
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public Attachments createContactAttachmentByFileName(
String accessToken,
String xeroTenantId,
UUID contactID,
String fileName,
File body,
String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createContactAttachmentByFileNameForHttpResponse(
accessToken, xeroTenantId, contactID, fileName, body, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createContactAttachmentByFileName -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("Attachments", object.getMessage(), e);
}
handler.validationError("Attachments", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* 200 - Success - return response of type Attachments array with an newly created
* Attachment
*
* 400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param contactID Unique identifier for a Contact
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createContactAttachmentByFileNameForHttpResponse(
String accessToken,
String xeroTenantId,
UUID contactID,
String fileName,
File body,
String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling"
+ " createContactAttachmentByFileName");
} // verify the required parameter 'contactID' is set
if (contactID == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'contactID' when calling"
+ " createContactAttachmentByFileName");
} // verify the required parameter 'fileName' is set
if (fileName == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'fileName' when calling"
+ " createContactAttachmentByFileName");
} // verify the required parameter 'body' is set
if (body == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'body' when calling createContactAttachmentByFileName");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling"
+ " createContactAttachmentByFileName");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/octet-stream");
headers.setUserAgent(this.getUserAgent());
// create a map of path variables
final Map uriVariables = new HashMap();
uriVariables.put("ContactID", contactID);
uriVariables.put("FileName", fileName);
UriBuilder uriBuilder =
UriBuilder.fromUri(
apiClient.getBasePath() + "/Contacts/{ContactID}/Attachments/{FileName}");
String url = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
java.nio.file.Path bodyPath = body.toPath();
String mimeType = java.nio.file.Files.probeContentType(bodyPath);
HttpContent content = null;
content = new FileContent(mimeType, body);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Creates a contact group
*
* 200 - Success - return response of type Contact Groups array of newly created Contact
* Group
*
*
400 - Validation Error - some data was incorrect returns response of type Error
*
* @param xeroTenantId Xero identifier for Tenant
* @param contactGroups ContactGroups with an array of names in request body
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return ContactGroups
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public ContactGroups createContactGroup(
String accessToken, String xeroTenantId, ContactGroups contactGroups, String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createContactGroupForHttpResponse(
accessToken, xeroTenantId, contactGroups, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createContactGroup -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("ContactGroups", object.getMessage(), e);
}
handler.validationError("ContactGroups", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates a contact group
*
* 200 - Success - return response of type Contact Groups array of newly created Contact
* Group
*
*
400 - Validation Error - some data was incorrect returns response of type Error
*
* @param xeroTenantId Xero identifier for Tenant
* @param contactGroups ContactGroups with an array of names in request body
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createContactGroupForHttpResponse(
String accessToken, String xeroTenantId, ContactGroups contactGroups, String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling createContactGroup");
} // verify the required parameter 'contactGroups' is set
if (contactGroups == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'contactGroups' when calling createContactGroup");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling createContactGroup");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/json");
headers.setUserAgent(this.getUserAgent());
UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/ContactGroups");
String url = uriBuilder.build().toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
HttpContent content = null;
content = apiClient.new JacksonJsonHttpContent(contactGroups);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Creates contacts to a specific contact group
*
*
200 - Success - return response of type Contacts array of added Contacts
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param contactGroupID Unique identifier for a Contact Group
* @param contacts Contacts with array of contacts specifying the ContactID to be added to
* ContactGroup in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return Contacts
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public Contacts createContactGroupContacts(
String accessToken,
String xeroTenantId,
UUID contactGroupID,
Contacts contacts,
String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createContactGroupContactsForHttpResponse(
accessToken, xeroTenantId, contactGroupID, contacts, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createContactGroupContacts -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("Contacts", object.getMessage(), e);
}
handler.validationError("Contacts", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates contacts to a specific contact group
*
* 200 - Success - return response of type Contacts array of added Contacts
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param contactGroupID Unique identifier for a Contact Group
* @param contacts Contacts with array of contacts specifying the ContactID to be added to
* ContactGroup in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createContactGroupContactsForHttpResponse(
String accessToken,
String xeroTenantId,
UUID contactGroupID,
Contacts contacts,
String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling createContactGroupContacts");
} // verify the required parameter 'contactGroupID' is set
if (contactGroupID == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'contactGroupID' when calling"
+ " createContactGroupContacts");
} // verify the required parameter 'contacts' is set
if (contacts == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'contacts' when calling createContactGroupContacts");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling createContactGroupContacts");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/json");
headers.setUserAgent(this.getUserAgent());
// create a map of path variables
final Map uriVariables = new HashMap();
uriVariables.put("ContactGroupID", contactGroupID);
UriBuilder uriBuilder =
UriBuilder.fromUri(apiClient.getBasePath() + "/ContactGroups/{ContactGroupID}/Contacts");
String url = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
HttpContent content = null;
content = apiClient.new JacksonJsonHttpContent(contacts);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Creates a new history record for a specific contact
*
* 200 - Success - return response of type HistoryRecords array of HistoryRecord objects
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param contactID Unique identifier for a Contact
* @param historyRecords HistoryRecords containing an array of HistoryRecord objects in body of
* request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HistoryRecords
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public HistoryRecords createContactHistory(
String accessToken,
String xeroTenantId,
UUID contactID,
HistoryRecords historyRecords,
String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createContactHistoryForHttpResponse(
accessToken, xeroTenantId, contactID, historyRecords, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createContactHistory -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("HistoryRecords", object.getMessage(), e);
}
handler.validationError("HistoryRecords", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates a new history record for a specific contact
*
* 200 - Success - return response of type HistoryRecords array of HistoryRecord objects
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param contactID Unique identifier for a Contact
* @param historyRecords HistoryRecords containing an array of HistoryRecord objects in body of
* request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createContactHistoryForHttpResponse(
String accessToken,
String xeroTenantId,
UUID contactID,
HistoryRecords historyRecords,
String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling createContactHistory");
} // verify the required parameter 'contactID' is set
if (contactID == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'contactID' when calling createContactHistory");
} // verify the required parameter 'historyRecords' is set
if (historyRecords == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'historyRecords' when calling createContactHistory");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling createContactHistory");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/json");
headers.setUserAgent(this.getUserAgent());
// create a map of path variables
final Map uriVariables = new HashMap();
uriVariables.put("ContactID", contactID);
UriBuilder uriBuilder =
UriBuilder.fromUri(apiClient.getBasePath() + "/Contacts/{ContactID}/History");
String url = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
HttpContent content = null;
content = apiClient.new JacksonJsonHttpContent(historyRecords);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Creates multiple contacts (bulk) in a Xero organisation
*
* 200 - Success - return response of type Contacts array with newly created Contact
*
*
400 - Validation Error - some data was incorrect returns response of type Error
*
* @param xeroTenantId Xero identifier for Tenant
* @param contacts Contacts with an array of Contact objects to create in body of request
* @param summarizeErrors If false return 200 OK and mix of successfully created objects and any
* with validation errors
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return Contacts
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public Contacts createContacts(
String accessToken,
String xeroTenantId,
Contacts contacts,
Boolean summarizeErrors,
String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createContactsForHttpResponse(
accessToken, xeroTenantId, contacts, summarizeErrors, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createContacts -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("Contacts", object.getMessage(), e);
}
handler.validationError("Contacts", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates multiple contacts (bulk) in a Xero organisation
*
* 200 - Success - return response of type Contacts array with newly created Contact
*
*
400 - Validation Error - some data was incorrect returns response of type Error
*
* @param xeroTenantId Xero identifier for Tenant
* @param contacts Contacts with an array of Contact objects to create in body of request
* @param summarizeErrors If false return 200 OK and mix of successfully created objects and any
* with validation errors
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createContactsForHttpResponse(
String accessToken,
String xeroTenantId,
Contacts contacts,
Boolean summarizeErrors,
String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling createContacts");
} // verify the required parameter 'contacts' is set
if (contacts == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'contacts' when calling createContacts");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling createContacts");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/json");
headers.setUserAgent(this.getUserAgent());
UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/Contacts");
if (summarizeErrors != null) {
String key = "summarizeErrors";
Object value = summarizeErrors;
if (value instanceof Collection) {
List valueList = new ArrayList<>((Collection) value);
if (!valueList.isEmpty() && valueList.get(0) instanceof UUID) {
List list = new ArrayList();
for (int i = 0; i < valueList.size(); i++) {
list.add(valueList.get(i).toString());
}
uriBuilder = uriBuilder.queryParam(key, String.join(",", list));
} else {
uriBuilder = uriBuilder.queryParam(key, String.join(",", valueList));
}
} else if (value instanceof Object[]) {
uriBuilder = uriBuilder.queryParam(key, (Object[]) value);
} else {
uriBuilder = uriBuilder.queryParam(key, value);
}
}
String url = uriBuilder.build().toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
HttpContent content = null;
content = apiClient.new JacksonJsonHttpContent(contacts);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Creates allocation for a specific credit note
*
* 200 - Success - return response of type Allocations array with newly created
* Allocation for specific Credit Note
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param creditNoteID Unique identifier for a Credit Note
* @param allocations Allocations with array of Allocation object in body of request.
* @param summarizeErrors If false return 200 OK and mix of successfully created objects and any
* with validation errors
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return Allocations
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public Allocations createCreditNoteAllocation(
String accessToken,
String xeroTenantId,
UUID creditNoteID,
Allocations allocations,
Boolean summarizeErrors,
String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createCreditNoteAllocationForHttpResponse(
accessToken,
xeroTenantId,
creditNoteID,
allocations,
summarizeErrors,
idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createCreditNoteAllocation -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("Allocations", object.getMessage(), e);
}
handler.validationError("Allocations", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates allocation for a specific credit note
*
* 200 - Success - return response of type Allocations array with newly created
* Allocation for specific Credit Note
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param creditNoteID Unique identifier for a Credit Note
* @param allocations Allocations with array of Allocation object in body of request.
* @param summarizeErrors If false return 200 OK and mix of successfully created objects and any
* with validation errors
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createCreditNoteAllocationForHttpResponse(
String accessToken,
String xeroTenantId,
UUID creditNoteID,
Allocations allocations,
Boolean summarizeErrors,
String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling createCreditNoteAllocation");
} // verify the required parameter 'creditNoteID' is set
if (creditNoteID == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'creditNoteID' when calling createCreditNoteAllocation");
} // verify the required parameter 'allocations' is set
if (allocations == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'allocations' when calling createCreditNoteAllocation");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling createCreditNoteAllocation");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/json");
headers.setUserAgent(this.getUserAgent());
// create a map of path variables
final Map uriVariables = new HashMap();
uriVariables.put("CreditNoteID", creditNoteID);
UriBuilder uriBuilder =
UriBuilder.fromUri(apiClient.getBasePath() + "/CreditNotes/{CreditNoteID}/Allocations");
if (summarizeErrors != null) {
String key = "summarizeErrors";
Object value = summarizeErrors;
if (value instanceof Collection) {
List valueList = new ArrayList<>((Collection) value);
if (!valueList.isEmpty() && valueList.get(0) instanceof UUID) {
List list = new ArrayList();
for (int i = 0; i < valueList.size(); i++) {
list.add(valueList.get(i).toString());
}
uriBuilder = uriBuilder.queryParam(key, String.join(",", list));
} else {
uriBuilder = uriBuilder.queryParam(key, String.join(",", valueList));
}
} else if (value instanceof Object[]) {
uriBuilder = uriBuilder.queryParam(key, (Object[]) value);
} else {
uriBuilder = uriBuilder.queryParam(key, value);
}
}
String url = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
HttpContent content = null;
content = apiClient.new JacksonJsonHttpContent(allocations);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
// Overload params for createCreditNoteAttachmentByFileName to allow byte[] or File type to be
// passed as body
/**
* Creates an attachment for a specific credit note
*
* 200 - Success - return response of type Attachments array with newly created
* Attachment for specific Credit Note
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param creditNoteID Unique identifier for a Credit Note
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param includeOnline Allows an attachment to be seen by the end customer within their online
* invoice
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param mimeType The type of file being attached
* @param accessToken Authorization token for user set in header of each request
* @return Attachments
* @throws IOException if an error occurs while attempting to invoke the API
*/
public Attachments createCreditNoteAttachmentByFileName(
String accessToken,
String xeroTenantId,
UUID creditNoteID,
String fileName,
byte[] body,
Boolean includeOnline,
String idempotencyKey,
String mimeType)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createCreditNoteAttachmentByFileNameForHttpResponse(
accessToken,
xeroTenantId,
creditNoteID,
fileName,
body,
includeOnline,
idempotencyKey,
mimeType);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createCreditNoteAttachmentByFileName -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
handler.execute(e);
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates an attachment for a specific credit note
*
* 200 - Success - return response of type Attachments array with newly created
* Attachment for specific Credit Note
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param creditNoteID Unique identifier for a Credit Note
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param includeOnline Allows an attachment to be seen by the end customer within their online
* invoice
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param mimeType The type of file being attached
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public HttpResponse createCreditNoteAttachmentByFileNameForHttpResponse(
String accessToken,
String xeroTenantId,
UUID creditNoteID,
String fileName,
byte[] body,
Boolean includeOnline,
String idempotencyKey,
String mimeType)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling"
+ " createCreditNoteAttachmentByFileName");
} // verify the required parameter 'creditNoteID' is set
if (creditNoteID == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'creditNoteID' when calling"
+ " createCreditNoteAttachmentByFileName");
} // verify the required parameter 'fileName' is set
if (fileName == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'fileName' when calling"
+ " createCreditNoteAttachmentByFileName");
} // verify the required parameter 'body' is set
if (body == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'body' when calling"
+ " createCreditNoteAttachmentByFileName");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling"
+ " createCreditNoteAttachmentByFileName");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/octet-stream");
headers.setUserAgent(this.getUserAgent());
// create a map of path variables
final Map uriVariables = new HashMap();
uriVariables.put("CreditNoteID", creditNoteID);
uriVariables.put("FileName", fileName);
UriBuilder uriBuilder =
UriBuilder.fromUri(
apiClient.getBasePath() + "/CreditNotes/{CreditNoteID}/Attachments/{FileName}");
if (includeOnline != null) {
String key = "IncludeOnline";
Object value = includeOnline;
if (value instanceof Collection) {
List valueList = new ArrayList<>((Collection) value);
if (!valueList.isEmpty() && valueList.get(0) instanceof UUID) {
List list = new ArrayList();
for (int i = 0; i < valueList.size(); i++) {
list.add(valueList.get(i).toString());
}
uriBuilder = uriBuilder.queryParam(key, String.join(",", list));
} else {
uriBuilder = uriBuilder.queryParam(key, String.join(",", valueList));
}
} else if (value instanceof Object[]) {
uriBuilder = uriBuilder.queryParam(key, (Object[]) value);
} else {
uriBuilder = uriBuilder.queryParam(key, value);
}
}
String url = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
ByteArrayContent content = null;
content = new ByteArrayContent(mimeType, body);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Creates an attachment for a specific credit note
*
* 200 - Success - return response of type Attachments array with newly created
* Attachment for specific Credit Note
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param creditNoteID Unique identifier for a Credit Note
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param includeOnline Allows an attachment to be seen by the end customer within their online
* invoice
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return Attachments
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public Attachments createCreditNoteAttachmentByFileName(
String accessToken,
String xeroTenantId,
UUID creditNoteID,
String fileName,
File body,
Boolean includeOnline,
String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createCreditNoteAttachmentByFileNameForHttpResponse(
accessToken,
xeroTenantId,
creditNoteID,
fileName,
body,
includeOnline,
idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createCreditNoteAttachmentByFileName -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("Attachments", object.getMessage(), e);
}
handler.validationError("Attachments", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates an attachment for a specific credit note
*
* 200 - Success - return response of type Attachments array with newly created
* Attachment for specific Credit Note
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param creditNoteID Unique identifier for a Credit Note
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param includeOnline Allows an attachment to be seen by the end customer within their online
* invoice
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createCreditNoteAttachmentByFileNameForHttpResponse(
String accessToken,
String xeroTenantId,
UUID creditNoteID,
String fileName,
File body,
Boolean includeOnline,
String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling"
+ " createCreditNoteAttachmentByFileName");
} // verify the required parameter 'creditNoteID' is set
if (creditNoteID == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'creditNoteID' when calling"
+ " createCreditNoteAttachmentByFileName");
} // verify the required parameter 'fileName' is set
if (fileName == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'fileName' when calling"
+ " createCreditNoteAttachmentByFileName");
} // verify the required parameter 'body' is set
if (body == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'body' when calling"
+ " createCreditNoteAttachmentByFileName");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling"
+ " createCreditNoteAttachmentByFileName");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/octet-stream");
headers.setUserAgent(this.getUserAgent());
// create a map of path variables
final Map uriVariables = new HashMap();
uriVariables.put("CreditNoteID", creditNoteID);
uriVariables.put("FileName", fileName);
UriBuilder uriBuilder =
UriBuilder.fromUri(
apiClient.getBasePath() + "/CreditNotes/{CreditNoteID}/Attachments/{FileName}");
if (includeOnline != null) {
String key = "IncludeOnline";
Object value = includeOnline;
if (value instanceof Collection) {
List valueList = new ArrayList<>((Collection) value);
if (!valueList.isEmpty() && valueList.get(0) instanceof UUID) {
List list = new ArrayList();
for (int i = 0; i < valueList.size(); i++) {
list.add(valueList.get(i).toString());
}
uriBuilder = uriBuilder.queryParam(key, String.join(",", list));
} else {
uriBuilder = uriBuilder.queryParam(key, String.join(",", valueList));
}
} else if (value instanceof Object[]) {
uriBuilder = uriBuilder.queryParam(key, (Object[]) value);
} else {
uriBuilder = uriBuilder.queryParam(key, value);
}
}
String url = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
java.nio.file.Path bodyPath = body.toPath();
String mimeType = java.nio.file.Files.probeContentType(bodyPath);
HttpContent content = null;
content = new FileContent(mimeType, body);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Retrieves history records of a specific credit note
*
* 200 - Success - return response of type HistoryRecords array of HistoryRecord objects
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param creditNoteID Unique identifier for a Credit Note
* @param historyRecords HistoryRecords containing an array of HistoryRecord objects in body of
* request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HistoryRecords
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public HistoryRecords createCreditNoteHistory(
String accessToken,
String xeroTenantId,
UUID creditNoteID,
HistoryRecords historyRecords,
String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createCreditNoteHistoryForHttpResponse(
accessToken, xeroTenantId, creditNoteID, historyRecords, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createCreditNoteHistory -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("HistoryRecords", object.getMessage(), e);
}
handler.validationError("HistoryRecords", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Retrieves history records of a specific credit note
*
* 200 - Success - return response of type HistoryRecords array of HistoryRecord objects
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param creditNoteID Unique identifier for a Credit Note
* @param historyRecords HistoryRecords containing an array of HistoryRecord objects in body of
* request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createCreditNoteHistoryForHttpResponse(
String accessToken,
String xeroTenantId,
UUID creditNoteID,
HistoryRecords historyRecords,
String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling createCreditNoteHistory");
} // verify the required parameter 'creditNoteID' is set
if (creditNoteID == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'creditNoteID' when calling createCreditNoteHistory");
} // verify the required parameter 'historyRecords' is set
if (historyRecords == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'historyRecords' when calling createCreditNoteHistory");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling createCreditNoteHistory");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/json");
headers.setUserAgent(this.getUserAgent());
// create a map of path variables
final Map uriVariables = new HashMap();
uriVariables.put("CreditNoteID", creditNoteID);
UriBuilder uriBuilder =
UriBuilder.fromUri(apiClient.getBasePath() + "/CreditNotes/{CreditNoteID}/History");
String url = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
HttpContent content = null;
content = apiClient.new JacksonJsonHttpContent(historyRecords);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Creates a new credit note
*
* 200 - Success - return response of type Credit Notes array of newly created
* CreditNote
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param creditNotes Credit Notes with array of CreditNote object in body of request
* @param summarizeErrors If false return 200 OK and mix of successfully created objects and any
* with validation errors
* @param unitdp e.g. unitdp=4 – (Unit Decimal Places) You can opt in to use four decimal
* places for unit amounts
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return CreditNotes
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public CreditNotes createCreditNotes(
String accessToken,
String xeroTenantId,
CreditNotes creditNotes,
Boolean summarizeErrors,
Integer unitdp,
String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createCreditNotesForHttpResponse(
accessToken, xeroTenantId, creditNotes, summarizeErrors, unitdp, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createCreditNotes -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("CreditNotes", object.getMessage(), e);
}
handler.validationError("CreditNotes", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates a new credit note
*
* 200 - Success - return response of type Credit Notes array of newly created
* CreditNote
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param creditNotes Credit Notes with array of CreditNote object in body of request
* @param summarizeErrors If false return 200 OK and mix of successfully created objects and any
* with validation errors
* @param unitdp e.g. unitdp=4 – (Unit Decimal Places) You can opt in to use four decimal
* places for unit amounts
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createCreditNotesForHttpResponse(
String accessToken,
String xeroTenantId,
CreditNotes creditNotes,
Boolean summarizeErrors,
Integer unitdp,
String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling createCreditNotes");
} // verify the required parameter 'creditNotes' is set
if (creditNotes == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'creditNotes' when calling createCreditNotes");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling createCreditNotes");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/json");
headers.setUserAgent(this.getUserAgent());
UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/CreditNotes");
if (summarizeErrors != null) {
String key = "summarizeErrors";
Object value = summarizeErrors;
if (value instanceof Collection) {
List valueList = new ArrayList<>((Collection) value);
if (!valueList.isEmpty() && valueList.get(0) instanceof UUID) {
List list = new ArrayList();
for (int i = 0; i < valueList.size(); i++) {
list.add(valueList.get(i).toString());
}
uriBuilder = uriBuilder.queryParam(key, String.join(",", list));
} else {
uriBuilder = uriBuilder.queryParam(key, String.join(",", valueList));
}
} else if (value instanceof Object[]) {
uriBuilder = uriBuilder.queryParam(key, (Object[]) value);
} else {
uriBuilder = uriBuilder.queryParam(key, value);
}
}
if (unitdp != null) {
String key = "unitdp";
Object value = unitdp;
if (value instanceof Collection) {
List valueList = new ArrayList<>((Collection) value);
if (!valueList.isEmpty() && valueList.get(0) instanceof UUID) {
List list = new ArrayList();
for (int i = 0; i < valueList.size(); i++) {
list.add(valueList.get(i).toString());
}
uriBuilder = uriBuilder.queryParam(key, String.join(",", list));
} else {
uriBuilder = uriBuilder.queryParam(key, String.join(",", valueList));
}
} else if (value instanceof Object[]) {
uriBuilder = uriBuilder.queryParam(key, (Object[]) value);
} else {
uriBuilder = uriBuilder.queryParam(key, value);
}
}
String url = uriBuilder.build().toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
HttpContent content = null;
content = apiClient.new JacksonJsonHttpContent(creditNotes);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Create a new currency for a Xero organisation
*
* 200 - Unsupported - return response incorrect exception, API is not able to create
* new Currency
*
* @param xeroTenantId Xero identifier for Tenant
* @param currency Currency object in the body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return Currencies
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public Currencies createCurrency(
String accessToken, String xeroTenantId, Currency currency, String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createCurrencyForHttpResponse(accessToken, xeroTenantId, currency, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createCurrency -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("Currencies", object.getMessage(), e);
}
handler.validationError("Currencies", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Create a new currency for a Xero organisation
*
* 200 - Unsupported - return response incorrect exception, API is not able to create
* new Currency
*
* @param xeroTenantId Xero identifier for Tenant
* @param currency Currency object in the body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createCurrencyForHttpResponse(
String accessToken, String xeroTenantId, Currency currency, String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling createCurrency");
} // verify the required parameter 'currency' is set
if (currency == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'currency' when calling createCurrency");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling createCurrency");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/json");
headers.setUserAgent(this.getUserAgent());
UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/Currencies");
String url = uriBuilder.build().toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
HttpContent content = null;
content = apiClient.new JacksonJsonHttpContent(currency);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Creates new employees used in Xero payrun
*
*
200 - Success - return response of type Employees array with new Employee
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param employees Employees with array of Employee object in body of request
* @param summarizeErrors If false return 200 OK and mix of successfully created objects and any
* with validation errors
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return Employees
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public Employees createEmployees(
String accessToken,
String xeroTenantId,
Employees employees,
Boolean summarizeErrors,
String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createEmployeesForHttpResponse(
accessToken, xeroTenantId, employees, summarizeErrors, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createEmployees -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("Employees", object.getMessage(), e);
}
handler.validationError("Employees", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates new employees used in Xero payrun
*
* 200 - Success - return response of type Employees array with new Employee
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param employees Employees with array of Employee object in body of request
* @param summarizeErrors If false return 200 OK and mix of successfully created objects and any
* with validation errors
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createEmployeesForHttpResponse(
String accessToken,
String xeroTenantId,
Employees employees,
Boolean summarizeErrors,
String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling createEmployees");
} // verify the required parameter 'employees' is set
if (employees == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'employees' when calling createEmployees");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling createEmployees");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/json");
headers.setUserAgent(this.getUserAgent());
UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/Employees");
if (summarizeErrors != null) {
String key = "summarizeErrors";
Object value = summarizeErrors;
if (value instanceof Collection) {
List valueList = new ArrayList<>((Collection) value);
if (!valueList.isEmpty() && valueList.get(0) instanceof UUID) {
List list = new ArrayList();
for (int i = 0; i < valueList.size(); i++) {
list.add(valueList.get(i).toString());
}
uriBuilder = uriBuilder.queryParam(key, String.join(",", list));
} else {
uriBuilder = uriBuilder.queryParam(key, String.join(",", valueList));
}
} else if (value instanceof Object[]) {
uriBuilder = uriBuilder.queryParam(key, (Object[]) value);
} else {
uriBuilder = uriBuilder.queryParam(key, value);
}
}
String url = uriBuilder.build().toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
HttpContent content = null;
content = apiClient.new JacksonJsonHttpContent(employees);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Creates a history record for a specific expense claim
*
* 200 - Success - return response of type HistoryRecords array of HistoryRecord objects
*
* @param xeroTenantId Xero identifier for Tenant
* @param expenseClaimID Unique identifier for a ExpenseClaim
* @param historyRecords HistoryRecords containing an array of HistoryRecord objects in body of
* request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HistoryRecords
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public HistoryRecords createExpenseClaimHistory(
String accessToken,
String xeroTenantId,
UUID expenseClaimID,
HistoryRecords historyRecords,
String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createExpenseClaimHistoryForHttpResponse(
accessToken, xeroTenantId, expenseClaimID, historyRecords, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createExpenseClaimHistory -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("HistoryRecords", object.getMessage(), e);
}
handler.validationError("HistoryRecords", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates a history record for a specific expense claim
*
* 200 - Success - return response of type HistoryRecords array of HistoryRecord objects
*
* @param xeroTenantId Xero identifier for Tenant
* @param expenseClaimID Unique identifier for a ExpenseClaim
* @param historyRecords HistoryRecords containing an array of HistoryRecord objects in body of
* request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createExpenseClaimHistoryForHttpResponse(
String accessToken,
String xeroTenantId,
UUID expenseClaimID,
HistoryRecords historyRecords,
String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling createExpenseClaimHistory");
} // verify the required parameter 'expenseClaimID' is set
if (expenseClaimID == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'expenseClaimID' when calling createExpenseClaimHistory");
} // verify the required parameter 'historyRecords' is set
if (historyRecords == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'historyRecords' when calling createExpenseClaimHistory");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling createExpenseClaimHistory");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/json");
headers.setUserAgent(this.getUserAgent());
// create a map of path variables
final Map uriVariables = new HashMap();
uriVariables.put("ExpenseClaimID", expenseClaimID);
UriBuilder uriBuilder =
UriBuilder.fromUri(apiClient.getBasePath() + "/ExpenseClaims/{ExpenseClaimID}/History");
String url = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
HttpContent content = null;
content = apiClient.new JacksonJsonHttpContent(historyRecords);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Creates expense claims
*
* 200 - Success - return response of type ExpenseClaims array with newly created
* ExpenseClaim
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param expenseClaims ExpenseClaims with array of ExpenseClaim object in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return ExpenseClaims
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public ExpenseClaims createExpenseClaims(
String accessToken, String xeroTenantId, ExpenseClaims expenseClaims, String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createExpenseClaimsForHttpResponse(
accessToken, xeroTenantId, expenseClaims, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createExpenseClaims -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("ExpenseClaims", object.getMessage(), e);
}
handler.validationError("ExpenseClaims", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates expense claims
*
* 200 - Success - return response of type ExpenseClaims array with newly created
* ExpenseClaim
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param expenseClaims ExpenseClaims with array of ExpenseClaim object in body of request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createExpenseClaimsForHttpResponse(
String accessToken, String xeroTenantId, ExpenseClaims expenseClaims, String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling createExpenseClaims");
} // verify the required parameter 'expenseClaims' is set
if (expenseClaims == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'expenseClaims' when calling createExpenseClaims");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling createExpenseClaims");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/json");
headers.setUserAgent(this.getUserAgent());
UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/ExpenseClaims");
String url = uriBuilder.build().toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
HttpContent content = null;
content = apiClient.new JacksonJsonHttpContent(expenseClaims);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
// Overload params for createInvoiceAttachmentByFileName to allow byte[] or File type to be passed
// as body
/**
* Creates an attachment for a specific invoice or purchase bill by filename
*
*
200 - Success - return response of type Attachments array with newly created
* Attachment
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param invoiceID Unique identifier for an Invoice
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param includeOnline Allows an attachment to be seen by the end customer within their online
* invoice
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param mimeType The type of file being attached
* @param accessToken Authorization token for user set in header of each request
* @return Attachments
* @throws IOException if an error occurs while attempting to invoke the API
*/
public Attachments createInvoiceAttachmentByFileName(
String accessToken,
String xeroTenantId,
UUID invoiceID,
String fileName,
byte[] body,
Boolean includeOnline,
String idempotencyKey,
String mimeType)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createInvoiceAttachmentByFileNameForHttpResponse(
accessToken,
xeroTenantId,
invoiceID,
fileName,
body,
includeOnline,
idempotencyKey,
mimeType);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createInvoiceAttachmentByFileName -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
handler.execute(e);
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates an attachment for a specific invoice or purchase bill by filename
*
* 200 - Success - return response of type Attachments array with newly created
* Attachment
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param invoiceID Unique identifier for an Invoice
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param includeOnline Allows an attachment to be seen by the end customer within their online
* invoice
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param mimeType The type of file being attached
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public HttpResponse createInvoiceAttachmentByFileNameForHttpResponse(
String accessToken,
String xeroTenantId,
UUID invoiceID,
String fileName,
byte[] body,
Boolean includeOnline,
String idempotencyKey,
String mimeType)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling"
+ " createInvoiceAttachmentByFileName");
} // verify the required parameter 'invoiceID' is set
if (invoiceID == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'invoiceID' when calling"
+ " createInvoiceAttachmentByFileName");
} // verify the required parameter 'fileName' is set
if (fileName == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'fileName' when calling"
+ " createInvoiceAttachmentByFileName");
} // verify the required parameter 'body' is set
if (body == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'body' when calling createInvoiceAttachmentByFileName");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling"
+ " createInvoiceAttachmentByFileName");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/octet-stream");
headers.setUserAgent(this.getUserAgent());
// create a map of path variables
final Map uriVariables = new HashMap();
uriVariables.put("InvoiceID", invoiceID);
uriVariables.put("FileName", fileName);
UriBuilder uriBuilder =
UriBuilder.fromUri(
apiClient.getBasePath() + "/Invoices/{InvoiceID}/Attachments/{FileName}");
if (includeOnline != null) {
String key = "IncludeOnline";
Object value = includeOnline;
if (value instanceof Collection) {
List valueList = new ArrayList<>((Collection) value);
if (!valueList.isEmpty() && valueList.get(0) instanceof UUID) {
List list = new ArrayList();
for (int i = 0; i < valueList.size(); i++) {
list.add(valueList.get(i).toString());
}
uriBuilder = uriBuilder.queryParam(key, String.join(",", list));
} else {
uriBuilder = uriBuilder.queryParam(key, String.join(",", valueList));
}
} else if (value instanceof Object[]) {
uriBuilder = uriBuilder.queryParam(key, (Object[]) value);
} else {
uriBuilder = uriBuilder.queryParam(key, value);
}
}
String url = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
ByteArrayContent content = null;
content = new ByteArrayContent(mimeType, body);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Creates an attachment for a specific invoice or purchase bill by filename
*
* 200 - Success - return response of type Attachments array with newly created
* Attachment
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param invoiceID Unique identifier for an Invoice
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param includeOnline Allows an attachment to be seen by the end customer within their online
* invoice
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return Attachments
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public Attachments createInvoiceAttachmentByFileName(
String accessToken,
String xeroTenantId,
UUID invoiceID,
String fileName,
File body,
Boolean includeOnline,
String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createInvoiceAttachmentByFileNameForHttpResponse(
accessToken, xeroTenantId, invoiceID, fileName, body, includeOnline, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createInvoiceAttachmentByFileName -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("Attachments", object.getMessage(), e);
}
handler.validationError("Attachments", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates an attachment for a specific invoice or purchase bill by filename
*
* 200 - Success - return response of type Attachments array with newly created
* Attachment
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param invoiceID Unique identifier for an Invoice
* @param fileName Name of the attachment
* @param body Byte array of file in body of request
* @param includeOnline Allows an attachment to be seen by the end customer within their online
* invoice
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createInvoiceAttachmentByFileNameForHttpResponse(
String accessToken,
String xeroTenantId,
UUID invoiceID,
String fileName,
File body,
Boolean includeOnline,
String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling"
+ " createInvoiceAttachmentByFileName");
} // verify the required parameter 'invoiceID' is set
if (invoiceID == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'invoiceID' when calling"
+ " createInvoiceAttachmentByFileName");
} // verify the required parameter 'fileName' is set
if (fileName == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'fileName' when calling"
+ " createInvoiceAttachmentByFileName");
} // verify the required parameter 'body' is set
if (body == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'body' when calling createInvoiceAttachmentByFileName");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling"
+ " createInvoiceAttachmentByFileName");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/octet-stream");
headers.setUserAgent(this.getUserAgent());
// create a map of path variables
final Map uriVariables = new HashMap();
uriVariables.put("InvoiceID", invoiceID);
uriVariables.put("FileName", fileName);
UriBuilder uriBuilder =
UriBuilder.fromUri(
apiClient.getBasePath() + "/Invoices/{InvoiceID}/Attachments/{FileName}");
if (includeOnline != null) {
String key = "IncludeOnline";
Object value = includeOnline;
if (value instanceof Collection) {
List valueList = new ArrayList<>((Collection) value);
if (!valueList.isEmpty() && valueList.get(0) instanceof UUID) {
List list = new ArrayList();
for (int i = 0; i < valueList.size(); i++) {
list.add(valueList.get(i).toString());
}
uriBuilder = uriBuilder.queryParam(key, String.join(",", list));
} else {
uriBuilder = uriBuilder.queryParam(key, String.join(",", valueList));
}
} else if (value instanceof Object[]) {
uriBuilder = uriBuilder.queryParam(key, (Object[]) value);
} else {
uriBuilder = uriBuilder.queryParam(key, value);
}
}
String url = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
java.nio.file.Path bodyPath = body.toPath();
String mimeType = java.nio.file.Files.probeContentType(bodyPath);
HttpContent content = null;
content = new FileContent(mimeType, body);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Creates a history record for a specific invoice
*
* 200 - Success - return response of type HistoryRecords array of HistoryRecord objects
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param invoiceID Unique identifier for an Invoice
* @param historyRecords HistoryRecords containing an array of HistoryRecord objects in body of
* request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HistoryRecords
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public HistoryRecords createInvoiceHistory(
String accessToken,
String xeroTenantId,
UUID invoiceID,
HistoryRecords historyRecords,
String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createInvoiceHistoryForHttpResponse(
accessToken, xeroTenantId, invoiceID, historyRecords, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createInvoiceHistory -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("HistoryRecords", object.getMessage(), e);
}
handler.validationError("HistoryRecords", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates a history record for a specific invoice
*
* 200 - Success - return response of type HistoryRecords array of HistoryRecord objects
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param invoiceID Unique identifier for an Invoice
* @param historyRecords HistoryRecords containing an array of HistoryRecord objects in body of
* request
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createInvoiceHistoryForHttpResponse(
String accessToken,
String xeroTenantId,
UUID invoiceID,
HistoryRecords historyRecords,
String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling createInvoiceHistory");
} // verify the required parameter 'invoiceID' is set
if (invoiceID == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'invoiceID' when calling createInvoiceHistory");
} // verify the required parameter 'historyRecords' is set
if (historyRecords == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'historyRecords' when calling createInvoiceHistory");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling createInvoiceHistory");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/json");
headers.setUserAgent(this.getUserAgent());
// create a map of path variables
final Map uriVariables = new HashMap();
uriVariables.put("InvoiceID", invoiceID);
UriBuilder uriBuilder =
UriBuilder.fromUri(apiClient.getBasePath() + "/Invoices/{InvoiceID}/History");
String url = uriBuilder.buildFromMap(uriVariables).toString();
GenericUrl genericUrl = new GenericUrl(url);
if (logger.isDebugEnabled()) {
logger.debug("PUT " + genericUrl.toString());
}
HttpContent content = null;
content = apiClient.new JacksonJsonHttpContent(historyRecords);
Credential credential =
new Credential(BearerToken.authorizationHeaderAccessMethod()).setAccessToken(accessToken);
HttpTransport transport = apiClient.getHttpTransport();
HttpRequestFactory requestFactory = transport.createRequestFactory(credential);
return requestFactory
.buildRequest(HttpMethods.PUT, genericUrl, content)
.setHeaders(headers)
.setConnectTimeout(apiClient.getConnectionTimeout())
.setReadTimeout(apiClient.getReadTimeout())
.execute();
}
/**
* Creates one or more sales invoices or purchase bills
*
* 200 - Success - return response of type Invoices array with newly created Invoice
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param invoices Invoices with an array of invoice objects in body of request
* @param summarizeErrors If false return 200 OK and mix of successfully created objects and any
* with validation errors
* @param unitdp e.g. unitdp=4 – (Unit Decimal Places) You can opt in to use four decimal
* places for unit amounts
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return Invoices
* @throws IOException if an error occurs while attempting to invoke the API *
*/
public Invoices createInvoices(
String accessToken,
String xeroTenantId,
Invoices invoices,
Boolean summarizeErrors,
Integer unitdp,
String idempotencyKey)
throws IOException {
try {
TypeReference typeRef = new TypeReference() {};
HttpResponse response =
createInvoicesForHttpResponse(
accessToken, xeroTenantId, invoices, summarizeErrors, unitdp, idempotencyKey);
return apiClient.getObjectMapper().readValue(response.getContent(), typeRef);
} catch (HttpResponseException e) {
if (logger.isDebugEnabled()) {
logger.debug(
"------------------ HttpResponseException "
+ e.getStatusCode()
+ " : createInvoices -------------------");
logger.debug(e.toString());
}
XeroApiExceptionHandler handler = new XeroApiExceptionHandler();
if (e.getStatusCode() == 400) {
TypeReference errorTypeRef =
new TypeReference() {};
com.xero.models.accounting.Error object =
apiClient.getObjectMapper().readValue(e.getContent(), errorTypeRef);
if (object.getElements() == null || object.getElements().isEmpty()) {
handler.validationError("Invoices", object.getMessage(), e);
}
handler.validationError("Invoices", object, e);
} else {
handler.execute(e);
}
} catch (IOException ioe) {
throw ioe;
}
return null;
}
/**
* Creates one or more sales invoices or purchase bills
*
* 200 - Success - return response of type Invoices array with newly created Invoice
*
*
400 - A failed request due to validation error
*
* @param xeroTenantId Xero identifier for Tenant
* @param invoices Invoices with an array of invoice objects in body of request
* @param summarizeErrors If false return 200 OK and mix of successfully created objects and any
* with validation errors
* @param unitdp e.g. unitdp=4 – (Unit Decimal Places) You can opt in to use four decimal
* places for unit amounts
* @param idempotencyKey This allows you to safely retry requests without the risk of duplicate
* processing. 128 character max.
* @param accessToken Authorization token for user set in header of each request
* @return HttpResponse
* @throws IOException if an error occurs while attempting to invoke the API
*/
public HttpResponse createInvoicesForHttpResponse(
String accessToken,
String xeroTenantId,
Invoices invoices,
Boolean summarizeErrors,
Integer unitdp,
String idempotencyKey)
throws IOException {
// verify the required parameter 'xeroTenantId' is set
if (xeroTenantId == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'xeroTenantId' when calling createInvoices");
} // verify the required parameter 'invoices' is set
if (invoices == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'invoices' when calling createInvoices");
}
if (accessToken == null) {
throw new IllegalArgumentException(
"Missing the required parameter 'accessToken' when calling createInvoices");
}
HttpHeaders headers = new HttpHeaders();
headers.set("xero-tenant-id", xeroTenantId);
headers.set("Idempotency-Key", idempotencyKey);
headers.setAccept("application/json");
headers.setContentType("application/json");
headers.setUserAgent(this.getUserAgent());
UriBuilder uriBuilder = UriBuilder.fromUri(apiClient.getBasePath() + "/Invoices");
if (summarizeErrors != null) {
String key = "summarizeErrors";
Object value = summarizeErrors;
if (value instanceof Collection) {
List valueList = new ArrayList<>((Collection) value);
if (!valueList.isEmpty() && valueList.get(0) instanceof UUID) {
List list = new ArrayList