# Java

## Create API Key from metacopier.io

You can use two types of API keys:

* **Project-level API key**: Navigate to **Your Projects > (Choose a project) > API Keys** (provides access to all accounts in the project)
* **Account API key**: Automatically generated when an account is created (provides access only to that specific account). Retrieve using the [getAccountApiKeys](https://api.metacopier.io/rest/api/documentation/swagger-ui/index.html#/Account%20API/getAccountApiKeys) endpoint.

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

## Package Information

The library is based on the following **OpenAPI** configuration:

{% embed url="<https://api.metacopier.io/rest/api/documentation/v3/api-docs>" %}

## Install with Maven

Add the following dependency to your pom.xml:

```
<dependency>
    <groupId>io.metacopier</groupId>
    <artifactId>api</artifactId>
    <version>1.2.5</version>
</dependency>
```

You can also visit the package on the official Maven Central Repository:

{% embed url="<https://central.sonatype.com/artifact/io.metacopier/api>" %}

## Example Program

Replace the "*YOUR\_API\_KEY*" with your own and run the code:

```java
import io.metacopier.AccountApiApi;
import io.metacopier.api.ApiClient;
import io.metacopier.api.ApiException;
import io.metacopier.api.Configuration;
import io.metacopier.api.auth.ApiKeyAuth;
import io.metacopier.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
        ApiKeyAuth ApiKeyAuth = (ApiKeyAuth) defaultClient.getAuthentication("ApiKeyAuth");
        ApiKeyAuth.setApiKey("YOUR_API_KEY");
        AccountApiApi apiInstance = new AccountApiApi(defaultClient);
        
        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();
        }

    }
}

```

## Generate your own package

With the following command, you can generate your own package for the metacopier api:

{% hint style="info" %}
Be sure that you have installed the OpenAPI Generator.\
See [generation](https://docs.metacopier.io/rest-api/sdk/generation "mention") page for more information.
{% endhint %}

```bash
openapi-generator-cli generate -i https://api.metacopier.io/rest/api/documentation/v3/api-docs -g java
```

For more information regarding the Open API generator, please visit their offical page:

{% embed url="<https://openapi-generator.tech/>" %}

## What endpoints can I call?

To check all available endpoints see either of the two pages:

{% content-ref url="../../api/readme.io" %}
[readme.io](https://docs.metacopier.io/rest-api/api/readme.io)
{% endcontent-ref %}

{% content-ref url="../../api/swagger" %}
[swagger](https://docs.metacopier.io/rest-api/api/swagger)
{% endcontent-ref %}
