v2.0.0
Merge Java SDK Release Notes - Version [2.0.0]
Breaking Changes
- Expand Query Params:
Previously a comma separated string was used for multiple enums. Now users will pass in a list of enums, then the SDK will pass them into the request correctly. Here's an example below:
import com.merge.api.MergeApiClient;
import com.merge.api.MergeApiClientBuilder;
import com.merge.api.accounting.types.Invoice;
import com.merge.api.accounting.types.InvoicesListRequest;
import com.merge.api.accounting.types.InvoicesListRequestExpandItem;
import com.merge.api.core.SyncPagingIterable;
import java.util.List;
MergeApiClient client = MergeApiClientBuilder.builder()
.apiKey("YOUR_API_KEY")
.accountToken("YOUR_ACCOUNT_TOKEN")
.build();
InvoicesListRequest request = InvoicesListRequest.builder()
// Pass a list of enum properties into the request, and the SDK will parse the values accordingly
.expand(List.of(InvoicesListRequestExpandItem.EMPLOYEE, InvoicesListRequestExpandItem.ACCOUNTING_PERIOD))
.build();
SyncPagingIterable<Invoice> invoices = client.accounting().invoices().list(request);
As part of this release we have provided a legacy client under com.merge.legacy.api to retain the previous functionality of v1.1.1. This legacy client will not be updated with new endpoints.
import com.merge.legacy.api.MergeApiClient;
import com.merge.legacy.api.resources.crm.requests.ContactsListRequest;
import com.merge.legacy.api.resources.crm.types.PaginatedContactList;
MergeApiClient mergeClient = MergeApiClient.builder()
.apiKey("YOUR_API_KEY")
.accountToken("YOUR_ACCOUNT_TOKEN")
.build();
ContactsListRequest request = ContactsListRequest.builder()
.expand("company,addresses")
.build();
PaginatedContactList response = mergeClient.crm().contacts().list(request);
System.out.println(response.getResults());
Improvements
- Auto pagination
Users can auto-paginate through responses. Paginated requests will return an Iterable, which can be used to loop through the underlying items. Here's a code snippet below:
import com.merge.api.MergeApiClient;
import com.merge.api.MergeApiClientBuilder;
import com.merge.api.accounting.types.Invoice;
import com.merge.api.accounting.types.InvoicesListRequest;
import com.merge.api.accounting.types.InvoicesListRequestExpandItem;
import com.merge.api.core.SyncPagingIterable;
import java.util.List;
MergeApiClient client = MergeApiClientBuilder.builder()
.apiKey("YOUR_API_KEY")
.accountToken("YOUR_ACCOUNT_TOKEN")
.build();
SyncPagingIterable<Invoice> invoices =
client.accounting().invoices().list(InvoicesListRequest.builder()
.expand(List.of(InvoicesListRequestExpandItem.EMPLOYEE,
InvoicesListRequestExpandItem.ACCOUNTING_PERIOD))
.build());
for (Invoice invoice : invoices) {
System.out.printf(
"invoice: ID: %s, Type: %s\\\\n",
invoice.getId(), invoice.getType());
}
or stream them:
client.accounting().invoices()
.list(InvoicesListRequest.builder()
.expand(List.of(InvoicesListRequestExpandItem.EMPLOYEE,
InvoicesListRequestExpandItem.ACCOUNTING_PERIOD))
.build())
.streamItems()
.map(invoice -> invoice.getId());
or calling nextPage() to perform the pagination manually:
// First page
List<Invoice> pageInvoices = invoices.getItems();
for (Invoice invoice : pageInvoices) {
// ...
}
// Remaining pages
while (invoices.hasNext()) {
pageInvoices = invoices.nextPage().getItems();
for (Invoice invoice : pageInvoices) {
// ...
}
}
- Ability to specify your own OkHttpClient
import com.merge.api.MergeApiClient;
import okhttp3.OkHttpClient;
OkHttpClient customClient = ...;
MergeApiClient client = MergeApiClient
.builder()
.httpClient(customClient)
.build();