Skip to content

Ecwid/ecwid-java-api-client

Folders and files

NameName
Last commit message
Last commit date
Feb 7, 2025
Jul 2, 2021
Sep 30, 2023
Nov 30, 2023
May 1, 2025
Jul 25, 2024
Jul 2, 2021
Oct 9, 2023
Apr 28, 2020
Jun 27, 2024
Jan 15, 2025
Nov 30, 2023
Feb 14, 2023
May 25, 2021

Repository files navigation

Ecwid java api client library

API documentation: https://api-docs.ecwid.com/reference/overview

Configure client library:

You can test this api client library on you local storage. For this you need to copy test/resources/test.properties.sample renamed to test.properties and configure it

For example: test.properties

storeId=2
apiToken=secret_4T6z...
apiHost=app.local.ecwid.com
apiPort=8443

Adding the Library to a Maven Project

To add the current library to a Maven project, you need to add the following block of code to your project's pom.xml file inside the <dependencies> tag:

<dependency>
    <groupId>com.ecwid.apiclient</groupId>
    <artifactId>api-client</artifactId>
    <version>0.326.0</version>
</dependency>

Adding the Library to a Gradle Project

To add the current library to a Gradle project using Kotlin DSL, you need to add the following line to your project's build.gradle.kts file inside the dependencies block:

implementation("com.ecwid.apiclient:api-client:0.326.0")

Examples

Simple example:

val apiClient = ApiClient.create(
		apiServerDomain = ApiServerDomain(),
		storeCredentials = ApiStoreCredentials(
				storeId = 1003,
				apiToken = "secret_mysecuretoken"),
		httpTransport = ApacheCommonsHttpClientTransport(),
		jsonTransformerProvider = GsonTransformerProvider())

val customer = apiClient.getCustomerDetails(CustomerDetailsRequest(customerId = 1))
println("api/v3 customer: $customer")

Batch api example:

val apiClient = ApiClient.create(
		apiServerDomain = ApiServerDomain(),
		storeCredentials = ApiStoreCredentials(
				storeId = 1003,
				apiToken = "secret_mysecuretoken"),
		httpTransport = ApacheCommonsHttpClientTransport(),
		jsonTransformerProvider = GsonTransformerProvider())

val requestsForBatch = listOf(CustomerDetailsRequest(1), CustomerDetailsRequest(2))
val batch = apiClient.createBatch(CreateBatchRequest(requestsForBatch, stopOnFirstFailure = true))

while (true) {
	val typedBatch = apiClient.getTypedBatch(GetEscapedBatchRequest(batch.ticket))
	if (typedBatch.status != BatchStatus.COMPLETED) {
		TimeUnit.SECONDS.sleep(2)
		continue
	}
	val customers = typedBatch.responses.orEmpty()
			.map { it.toTypedResponse(FetchedCustomer::class.java) }
			.mapNotNull { if (it is TypedBatchResponse.Ok<FetchedCustomer>) it.value else null }
	val errors = typedBatch.responses.orEmpty()
			.map { it.toTypedResponse(FetchedCustomer::class.java) }
			.mapNotNull { if (it !is TypedBatchResponse.Ok<FetchedCustomer>) it.toString() else null }
	println("api/v3 customers: ${customers.joinToString { it.id.toString() }}, errors: ${errors.joinToString()}")
	break
}