Class Using


public class Using extends Object
Table of content

Using SDK

SDK follows a builder pattern when creating requests and model entities. Category resource will be used to demonstrate how to use the SDK. This behaviour is the same for all resources.

Models and Builders

Models are defined as interfaces. For each model a Builder class exists which builds the implementation class of a model. The model builder has a build method which checks that required properties have been set. The buildUnchecked method creates a new instance without checking for required properties

Classes of a model
CategoryDraft categoryDraft = CategoryDraftBuilder.of()
        .name(LocalizedStringBuilder.of().addValue("en", "name").build())
        .slug(LocalizedStringBuilder.of().addValue("en", "slug").build())
        .description(LocalizedStringBuilder.of().addValue("en", "description").build())
        .metaDescription(LocalizedStringBuilder.of().addValue("en", "metaDescription").build())


return categoryDraft;

See the test code.

Request DSL

Building request can be done with the help of an ApiRoot, e.g. ProjectApiRoot. The DSL mirrors the directory structure and HTTP methods of the API and allows navigating and discovering the commercetools Composable Commerce API while typing. The HTTP method builders includes methods for every query parameter. Additionally there are the ApiMethod.execute() and RequestCommand.executeBlocking() methods which are sending the request using the configured ApiHttpClient and mapping the result to the correct response class. In case the raw JSON is needed ApiMethod.send() and ApiMethod.sendBlocking() will return an ApiHttpResponse with the byte array.

ProjectApiRoot apiRoot = createProjectClient();

// Use in the previous step configured ApiRoot instance to send and receive a newly created Category
Category category = apiRoot.categories().post(draftBuilder()).executeBlocking().getBody();

// Get Category by id
Category queriedCategory = apiRoot.categories().withId(category.getId()).get().executeBlocking().getBody();

// Get Category by key
Category queriedCategoryByKey = apiRoot.categories()

// Query Categories
CategoryPagedQueryResponse response = apiRoot.categories()
        .withWhere("id = :catId")
        .withPredicateVar("catId", category.getId())

// Update Category
Category updatedCategory = apiRoot.categories()
                        .name(LocalizedStringBuilder.of().addValue("key-Temp", "value-Temp").build())

// Delete Category by key
Category deletedCategoryByKey = apiRoot.categories()

See the test code.

  • Constructor Details

    • Using

      public Using()