Page cover image

Java

Instructions on how to install and use the MetaCopier API Client package

Working on it... well be published soon

Install OpenAPI Generator CLI

See instructions under Generation

Create API Key from metacopier.io

To generate yourself an API Key please navigate to metacopier.io > Your Projects > (Choose a project) > API Keys

Note: Please do not share your API Key to people whom you don't trust.

Requirements

Building the API client library requires:

  1. Java 1.8+

  2. Maven/Gradle

Execute CLI command

Execute the following command to generate the SDK package:

openapi-generator-cli generate -i https://api.metacopier.io/rest/api/documentation/v3/api-docs -g java --library apache-httpclient --api-package com.example --model-package com.example.client.model --invoker-package com.example.api --group-id com.example --artifact-id api --artifact-version 1.0.0

Using the package

To install the API client library to your local Maven repository, simply execute:

mvn clean install

To deploy it to a remote Maven repository instead, configure the settings of the repository and execute:

mvn clean deploy

Refer to the OSSRH Guide for more information.

Maven users

Add this dependency to your project's POM:

<dependency>
  <groupId>com.example</groupId>
  <artifactId>api</artifactId>
  <version>1.0.0</version>
  <scope>compile</scope>
</dependency>

Gradle users

Add this dependency to your project's build file:

compile "com.example:api:1.0.0"

Others

At first generate the JAR by executing:

mvn clean package

Then manually install the following JARs:

  • target/api-1.0.0.jar

  • target/lib/*.jar

Example Program

Replace the "YOUR-API-KEY" with your own and run the code:

import com.example.AccountApiApi;
import com.example.api.ApiClient;
import com.example.api.ApiException;
import com.example.api.Configuration;
import com.example.api.auth.ApiKeyAuth;
import com.example.client.model.AccountDTO;

import java.util.List;

public class Main {
    public static void main(String[] args) {
        ApiClient defaultClient = Configuration.getDefaultApiClient();
        defaultClient.setBasePath("https://api.metacopier.io");

        // Configure API key authorization: ApiKeyAuth
        String apiKey = "YOUR-API-KEY";
        ApiKeyAuth ApiKeyAuth = (ApiKeyAuth) defaultClient.getAuthentication("ApiKeyAuth");
        ApiKeyAuth.setApiKey(apiKey);
        // Uncomment the following line to set a prefix for the API key, e.g. "Token" (defaults to null)
        //ApiKeyAuth.setApiKeyPrefix("Token");

        AccountApiApi apiInstance = new AccountApiApi(defaultClient);
        AccountDTO accountDTO = new AccountDTO(); // AccountDTO |
        try {
            List<AccountDTO> results = apiInstance.getAccounts();
            System.out.println(results);
        } catch (ApiException e) {
            System.err.println("Exception when calling AccountApiApi#createAccount");
            System.err.println("Status code: " + e.getCode());
            System.err.println("Reason: " + e.getResponseBody());
            System.err.println("Response headers: " + e.getResponseHeaders());
            e.printStackTrace();
        }
    }
}

What endpoints can I call?

To check all available endpoints see REST API

Need more help?

Check the README.md for further information

Last updated