# C\#

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

Execute the following command to install the api package to your project:

```
dotnet add package MetaCopier.Api --version 1.2.5
```

You can also visit the package on the offical NuGet site:

{% embed url="<https://www.nuget.org/packages/MetaCopier.Api>" %}

## Option 2: Generate package with OpenAPI Generator CLI

### Install OpenAPI Generator CLI

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

### Execute CLI command

Execute the following command to generate the SDK package:

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

### Change Output Type

Open up generated project file *Org.OpenAPITools.csproj* and value of output type to the following:

```xml
<OutputType>Exe</OutputType>
```

### Install and Update NuGet Packages

First, run the following dotnet CLI command inside the generated project to restore the NuGet packages:

```powershell
dotnet restore
```

Then use the following command to list all installed NuGet Packages:

```powershell
dotnet list package
```

The following should be listed:

```
Project 'Org.OpenAPITools' has the following package references
   [net8.0]:
   Top-level Package      Requested   Resolved
   > JsonSubTypes         2.0.1       2.0.1
   > Newtonsoft.Json      13.0.3      13.0.3
   > Polly                8.1.0       8.1.0
   > RestSharp            110.2.0     110.2.0

Project 'Org.OpenAPITools.Test' has the following package references
   [net8.0]:
   Top-level Package                Requested   Resolved
   > Microsoft.NET.Test.Sdk         17.9.0      17.9.0
   > xunit                          2.7.0       2.7.0
   > xunit.runner.visualstudio      2.5.7       2.5.7 
```

Now navigate into the following directory "*src\Org.OpenAPITools*" and execute the following commands to install and update the necessary NuGet packages:

```powershell
dotnet add package JsonSubTypes --version 2.0.1
dotnet add package Newtonsoft.Json --version 13.0.3
dotnet add package RestSharp --version 112.0.0
dotnet add package System.ComponentModel.Annotations --version 5.0.0
```

After installing and updating the necessary NuGet packages assure your packages have at least the following version:

```
Project 'Org.OpenAPITools' has the following package references
   [net8.0]:
   Top-level Package                        Requested   Resolved
   > JsonSubTypes                           2.0.1       2.0.1
   > Newtonsoft.Json                        13.0.3      13.0.3
   > Polly                                  8.1.0       8.1.0
   > RestSharp                              112.0.0     112.0.0
   > System.ComponentModel.Annotations      5.0.0       5.0.0
```

## Run the following code

Create a *program.cs* file and insert the following code, then replace the "*YOUR-API-KEY*" with your own and run the code:

```csharp
internal class Program
{
    public static void Main(string[] args)
    {
        Configuration config = new Configuration();
        config.BasePath = "https://api.metacopier.io";

        // Configure API key authorization: ApiKeyAuth
        config.ApiKey.Add("X-API-KEY", "YOUR-API-KEY");
        
        // Uncomment below to setup prefix (e.g. Bearer) for API key, if needed
        // config.ApiKeyPrefix.Add("X-API-KEY", "Bearer");

        var apiInstance = new AccountAPIApi(config);

        try
        {
            var accounts = apiInstance.GetAccounts();
            Console.WriteLine(JsonConvert.SerializeObject(accounts));
        }
        catch (ApiException e)
        {
            Debug.Print("Exception when calling AccountAPIApi: " + e.Message);
            Debug.Print("Status Code: " + e.ErrorCode);
        }
    }
}
```

## 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/c.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.
