> For the complete documentation index, see [llms.txt](https://docs.metacopier.io/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://docs.metacopier.io/rest-api/sdk/usage/go.md).

# Go

## 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

Both packages from option 1 or option 2 are based on the following **OpenAPI** configuration:

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

### Option 1: Install with Go modules (pkg.go.dev)

#### Execute install command

Execute the following command to install the SDK package:

```bash
go get github.com/metacopier/go-package@v1.2.9
```

You can also visit the package on the official pkg.go.dev site:

{% embed url="<https://pkg.go.dev/github.com/metacopier/go-package>" %}

### Options 2: Install with OpenAPI Generator CLI

See instructions under [Generation](/rest-api/sdk/generation.md)

#### 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 go -o ./ --additional-properties packageName=metacopier,packageVersion=1.2.9,isGoSubmodule=false,withGoMod=true,structPrefix=false,useDefaultValuesForRequiredVars=false,disallowAdditionalPropertiesIfNotPresent=false
```

## Example

In the following Go program I will use the **metacopier** package to fetch all accounts of my MetaCopier project.

```go
package main

import (
    "context"
    "fmt"
    "log"
    
    metacopier "github.com/metacopier/go-package"
)

func main() {
    // Api Key from metacopier.io
    apiKey := "YOUR_API_KEY"
    
    // Create a new configuration
    cfg := metacopier.NewConfiguration()
    cfg.Host = "api.metacopier.io"
    cfg.Scheme = "https"
    
    // Set API key for authorization
    cfg.AddDefaultHeader("X-API-Key", apiKey)
    
    // Create API client
    client := metacopier.NewAPIClient(cfg)
    
    // Create an instance of the account API
    ctx := context.Background()
    
    // Send request to fetch accounts
    accounts, resp, err := client.AccountAPIApi.GetAccounts(ctx).Execute()
    if err != nil {
        log.Fatalf("Exception when calling AccountAPIApi->GetAccounts: %v\n", err)
    }
    
    // Print response
    fmt.Printf("Accounts: %+v\n", accounts)
    fmt.Printf("Status Code: %d\n", resp.StatusCode)
}
```

## 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 go
```

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 %}
