# 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](/rest-api/sdk/generation.md) 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="/pages/3HakPo5rmjlgHIYpy5Yo" %}
[Readme.io](/rest-api/api/readme.io.md)
{% endcontent-ref %}

{% content-ref url="/pages/7KVz9yHPKLMm9yjqkThN" %}
[Swagger](/rest-api/api/swagger.md)
{% endcontent-ref %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.metacopier.io/rest-api/sdk/usage/java.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
