---
title: "C# / .NET SDK"
lang: en
canonical: https://doc.apibrasil.io/sdks/csharp
markdown: https://doc.apibrasil.io/sdks/csharp.md
source: apibrasil-documentation
---

# C# / .NET SDK

- **Status:** published
- **Install:** `dotnet add package ApiBrasil`
- **Registry:** NuGet — https://www.nuget.org/packages/ApiBrasil
- **Repository:** https://github.com/APIBrasil/apigratis-nuget-dotnet

## Do not make up the signature

DO NOT INVENT THE C# / .NET SDK's API. Every library in this catalogue has its own constructor, method names and return shape, and none of them can be deduced from the package name. Open the README of the repository above and use exactly what is written there. If you cannot open the repository, DO NOT GUESS: write the client in plain HTTP, following the section below, and say in your answer that this is what you did and why.

## How to authenticate

The Bearer goes in the Authorization header, on every call. The DeviceToken only on plan-billed APIs — credit-billed ones don't ask for it. It's the same pair the SDK sets for you.

With homolog set to true in the body, the gateway answers from a fixed dataset. The document number 00000000000 belongs to that dataset and to no one.

## The repository on GitHub

- **Stars:** 2
- **Forks:** 0
- **Open issues:** 0
- **Language:** Not detected
- **Licence:** Not declared
- **Last push:** July 11, 2023
- **git clone:** `https://github.com/APIBrasil/apigratis-nuget-dotnet.git`

## Repository README

Reproduced from the repository, on the default branch. It is the documentation written by whoever maintains the library: the SDK's signature is what is written here, not what is deduced from the package name.

# Pacote NuGet Dotnet - APIGratis by API BRASIL
Conjunto de API, para desenvolvedores.

Transforme seus projetos em soluções inteligentes com nossa API. Com recursos como API do WhatsApp, geolocalização, rastreamento de encomendas, verificação de CPF/CNPJ e mais, você pode criar soluções eficientes e funcionais.

# Canais de suporte (Comunidade)
[![WhatsApp Group](https://img.shields.io/badge/WhatsApp-Group-25D366?logo=whatsapp)](https://chat.whatsapp.com/KsxrUGIPWvUBYAjI1ogaGs)
[![Telegram Group](https://img.shields.io/badge/Telegram-Group-32AFED?logo=telegram)](https://t.me/apigratisoficial)

# Obtenha suas credenciais
https://apibrasil.com.br/

# Exemplo 

AppSettings.Json
```
"ApiBrasilConfiguration": {
        "SecretKey": "mySecretKey",
        "PublicToken": "myPublicToken",
        "DeviceToken": "myDeviceToken",
        "Authorization": "myAuthorization"
    }
```

Option Pattern importing ApiBrasil.Domain
Program.cs
```
builder.Services.Configure<ApiBrasilConfiguration>(builder.Configuration.GetSection("ApiBrasilConfiguration"));
```

Example
```
import ApiBrasil;

private readonly ApiBrasilConfiguration _apiBrasil;

public Construct(IOptions<ApiBrasilConfiguration> apibrasil)
{
    _apiBrasil = apibrasil.Value;
}

public class ApiBrasilDto
{
    public string Type { get; set; }
    public string Action { get; set; }
    public object Content { get; set; }
}

[HttpPost("v1/apibrasil")]
public async Task<IActionResult> TestApiBrasil([FromBody] ApiBrasilDto var)
{
    try
    {
        var result = await ApiBrasil.GenericCaller.Call(var.Type, var.Action, var.Content, _apiBrasil);

        return Ok(result);
    }
    catch (Exception ex)
    {
        return StatusCode(500, ex);
    }
}
```

## The same API over HTTP

Base URL: https://gateway.apibrasil.io/api/v2
Each endpoint's path and method are on that API's page in this documentation. Do not deduce a route from the service name.

### Authentication, as HTTP headers
- `Authorization: Bearer YOUR_TOKEN` — on every call.
- `DeviceToken: YOUR_DEVICE_TOKEN` — only on plan-billed APIs; credit-billed ones don't ask for it. The exact header name is whatever the endpoint's page declares.

```bash
curl -X POST https://gateway.apibrasil.io/api/v2/dados/cpf \
  -H "Authorization: Bearer $APIBRASIL_TOKEN" \
  -H "Content-Type: application/json" \
  -d '{"cpf": "00000000000", "homolog": true}'
```

With `homolog` set to true in the body, the gateway answers from a fixed dataset and spends no credit. The document number 00000000000 belongs to that dataset and to no one — use it in tests, never in production.

## The other languages

- [C++](https://doc.apibrasil.io/sdks/cpp.md): `git clone https://github.com/APIBrasil/apigratis-sdk-cpp`
- [Python](https://doc.apibrasil.io/sdks/python.md): `pip install api-brasil`
- [Lua](https://doc.apibrasil.io/sdks/lua.md): `luarocks install apibrasil`
- [PHP](https://doc.apibrasil.io/sdks/php.md): `composer require jhowbhz/apigratis-sdk-php`
- [Java](https://doc.apibrasil.io/sdks/java.md): `mvn dependency:get -Dartifact=br.com.apibrasil:apigratis-sdk-java:0.0.1`
- [Ruby](https://doc.apibrasil.io/sdks/ruby.md): `gem install apigratis-sdk-ruby`
- [Node.js / TypeScript](https://doc.apibrasil.io/sdks/javascript.md): `npm install apigratis-sdk-nodejs`
- [Go](https://doc.apibrasil.io/sdks/go.md): `go get github.com/APIBrasil/apigratis-sdk-go`
- [Rust](https://doc.apibrasil.io/sdks/rust.md): `cargo add apibrasil`
- [Dart / Flutter](https://doc.apibrasil.io/sdks/flutter.md): `flutter pub add apigratis_sdk_flutter`
- [Elixir](https://doc.apibrasil.io/sdks/elixir.md): `mix deps.get  # com {:apibrasil, "~> 0.0.1"} no mix.exs`

## See also

- Official SDKs: [Official SDKs](https://doc.apibrasil.io/sdks.md)
- Documentation index: https://doc.apibrasil.io/llms.txt
- HTML version of this page: https://doc.apibrasil.io/sdks/csharp
