Skip to main content

Quickstart

This guide will quickly get you up and running with Complero using Java.

Requirements​

Setting up your project​

Create your Maven project (see Maven quick start guide here).

mvn archetype:generate -DgroupId=com.mycompany.app -DartifactId=my-app -DarchetypeArtifactId=maven-archetype-quickstart -DarchetypeVersion=1.5 -DinteractiveMode=false && \
cd my-app/

To add the SDK to the project generate it from the Swagger specification.

Add the generator to your project specification by changing the pom.xml to the following:

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>com.mycompany.app</groupId>
<artifactId>my-app</artifactId>
<version>1.0-SNAPSHOT</version>

<name>my-app</name>
<url>http://www.example.com</url>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<maven.compiler.release>11</maven.compiler.release>
<maven.test.skip>true</maven.test.skip>
<openapi-generator.version>7.7.0</openapi-generator.version>
<openapi-generator.input>https://api.complero.com/redocusaurus/swagger.yaml</openapi-generator.input>
</properties>

<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit</groupId>
<artifactId>junit-bom</artifactId>
<version>5.11.0</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<dependencies>
<dependency>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator.version}</version>
</dependency>

<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>

<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<version>4.9.3</version>
</dependency>

<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>

<dependency>
<groupId>io.gsonfire</groupId>
<artifactId>gson-fire</artifactId>
<version>1.9.0</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>${openapi-generator.version}</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${openapi-generator.input}</inputSpec>
<generatorName>java</generatorName>
<output>${project.build.directory}/generated-sources/openapi</output>
<apiPackage>com.complero.api</apiPackage>
<modelPackage>com.complero.api.models</modelPackage>
<invokerPackage>com.complero.invoker</invokerPackage>
<configOptions>
<groupId>com.complero</groupId>
<artifactId>cpl-sdk</artifactId>
<artifactVersion>1.0-SNAPSHOT</artifactVersion>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
<pluginManagement>
<plugins>
<plugin>
<artifactId>maven-clean-plugin</artifactId>
<version>3.4.0</version>
</plugin>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<version>3.3.1</version>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
</plugin>
<plugin>
<artifactId>maven-jar-plugin</artifactId>
<version>3.4.2</version>
</plugin>
<plugin>
<artifactId>maven-install-plugin</artifactId>
<version>3.1.2</version>
</plugin>
</plugins>
</pluginManagement>
</build>
</project>

Generate the packages:

mvn clean install

Let's also add the following work directories:

mkdir -p src/main/java/com/complero/examples/

Hello Complero​

Now let's ping the Complero API to check if the network works by adding the following file to your project:

src/main/java/com/complero/examples/QuickStartPing.java
package com.complero.examples;

import com.complero.invoker.*;
import com.complero.api.DefaultApi;

public class QuickStartPing {
public static void main(String[] args) {
ApiClient apiClient = new ApiClient();
DefaultApi defaultApi = new DefaultApi(apiClient);

try {
defaultApi.ping();

System.out.println("Succesfully connected to Complero!");
} catch (ApiException e) {
System.out.println(e.getMessage());
System.out.println(e.getResponseBody());
}
}
}

Let's run the application:

mvn clean install exec:java -Dexec.mainClass="com.complero.examples.QuickStartPing"

Upload First Contact​

Now let's authenticate with the Complero API and upload our first contact.

Set your Complero API key as an environment variable:

export COMPLERO_API_KEY="<your_api_key_here>"

Add the following file to the project:

src/main/java/com/complero/examples/QuickStartUpload.java
package com.complero.examples;

import com.complero.api.models.*;
import com.complero.invoker.*;
import com.complero.api.ContactsApi;
import com.complero.invoker.auth.ApiKeyAuth;
import com.complero.invoker.auth.Authentication;
import java.util.List;
import java.util.ArrayList;

public class QuickStartUpload {
public static void main(String[] args) {
ApiClient apiClient = new ApiClient();

// Insert add credentials
String apiToken = System.getenv("API_KEY");

Authentication auth = apiClient.getAuthentications().get("ApiKeyAuth");
((ApiKeyAuth) auth).setApiKey("Bearer ".concat(apiToken));

ContactsApi contactsApi = new ContactsApi(apiClient);

ContactUpload ctc = new ContactUpload();
ctc.id("n1");
ctc.employeeId("1");
ctc.firstName("John");
ctc.lastName("Doe");
ctc.birthday("1991-05-05");

List<ContactUpload> contactList = new ArrayList<ContactUpload>();
contactList.add(ctc);

try {
contactsApi.bulkUploadContacts(contactList);
System.out.println("Succesfully uploaded contact to Complero!");
} catch (ApiException e) {
System.out.println(e.getMessage());
System.out.println(e.getResponseBody());
}
}
}

Let's run the application:

mvn clean install exec:java -Dexec.mainClass="com.complero.examples.QuickStartUpload"