Download and install the java SDK and intro to its structure.

Live demo

Here you can find live demo of the Camera store sample application. This is the application we are going to build here.

Prerequisites

To follow along with this tutorial, you have to have:

  • Active account in Tradenity
  • Create the sample “Camera store”, and load the sample data (This option is available on the create store page).
  • Have a working Java development environment (JDK installed, IDE)
  • Basic familiarity with the Spring MVC framework, prior experience with Spring Boot will help.

Setup your credentials

First of all, you have to get API keys for your store, you can find it in your store Edit page. To get there navigate to the stores list page, click on the Edit button next to your store name, scroll down till you find the API Keys section.

In the application.yml file, insert the following properties, Make sure to replace the api keys with the ones for your store, otherwise you will get authentication error

grails-app/conf/application.yml



tradenity:
    secretKey: sk_1234567
    publicKey: pk_1234567

Initialize the library

You can easily initialize the library by adding @EnableTradenity annotation on any @Configuration class.

Our application uses Spring Boot framework, so it is appropriate to add this annotation to the application class

@SpringBootApplication
@EnableTradenity
public class ShopApplication {
    public static void main(String[] args) {
        SpringApplication.run(ShopApplication.class, args);
    }
}

Make your First call

When using spring framework support in Tradenity SDK, you do not need to initialize the TradenityClient or do HTTP REST calls yourself, The framework will create the necessary objects and wire them under the hood.

The tradenity SDK is organized into a group of *Service classes, each contains the operation for a specific entity model, for example to perform operations related to the Brand entity you can use the associated BrandService.

Using grails’s standard spring dependency injection mechanism you can inject any service by defining a field with the same name in your controller. Of course you can use the standard spring using either @Autowire or @Inject in your calling class.


def brandService

Now, just call any method in your code.


def brand = brandService.findById("1243-9786786-jhgjtu-789s6i")