.NET SDK
Install the official SDK and connect your C# backend to the Raims public API.
Use the Raims package to integrate a server application written in C# with
the public API. The SDK provides resource services, typed inputs and responses,
cursor pagination, and webhook signature verification. Methods have synchronous
and asynchronous variants, with the Async suffix.
The integration requires an x64 application running .NET Framework 4.8/4.8.1 or .NET 10. Do not distribute the API key in browser, desktop, or mobile apps provided to your customers. Keep it in the integration backend.
Install the package
To start a console project, run dotnet new console --framework net10.0 --name ConsultaRaims and enter ConsultaRaims. If you already have an application, use its directory.
From your application directory:
dotnet add package RaimsWithout a version argument, NuGet installs the latest stable version compatible with the project and records the reference in your application.
The package targets netstandard2.0 and net10.0. NuGet selects the appropriate
target; supported consumers are validated on x64 .NET Framework 4.8 and .NET 10.
Configure the client
Prepare the credential
Obtain a key through API keys and store it in a protected environment variable or your application's secret store. The validated credential determines the company, environment, and permissions in the API. Sandbox and Production use
https://api.raims.com.For this first read, use a Sandbox key with View customers permission. The request only reads one page; it does not create customers or request emails.
Save the read example
Use a .NET 10 console project for this first read.
Program.cs C#using System; using System.Threading.Tasks; using Raims; internal static class Program { public static async Task Main() { string apiKey = Environment.GetEnvironmentVariable("RAIMS_API_KEY") ?? throw new InvalidOperationException("Set RAIMS_API_KEY on the server."); using (var raims = new RaimsClient(apiKey)) { try { var customers = await raims.Customers.ListAsync(new ListCustomersOptions { PageSize = 10, }); Console.WriteLine($"HTTP status: {customers.LastResponse?.StatusCode}; items: {customers.Count}"); } catch (ApiErrorException error) { Console.Error.WriteLine($"HTTP status: {error.HttpStatus}; code: {error.ErrorCode}; Request-Id: {error.RequestId}"); Environment.ExitCode = 1; } } } }Run and check the result
From the project directory, with
RAIMS_API_KEYavailable to the process, run:Shelldotnet run --configuration Release --arch x64A successful read prints
HTTP status: 200and the number of items in this page.items: 0is a valid empty result for the key’s company and environment. It is not an authentication failure.
What to check
The SDK reads the list and page envelope below. In an empty page, has_next: false means there is no next page. A nonempty page also returns customer records; the program prints only their count.
No customers found
{
"list": [],
"page": {
"page_size": 10,
"has_next": false,
"has_previous": false,
"next_after": null,
"previous_before": null
}
}Reuse the client for the integration's lifetime to reuse HTTP connections, and
dispose it when no longer needed. The following snippets assume a raims
instance configured by your application.
Create a customer and a charge
This is a backend snippet, after loading the order from your application’s storage. Keep the customer key separate from the charge key. Save the entire request payload, including the amount and title, before sending; read it again on retries instead of generating new values.
| Input from the saved order | Source and purpose |
|---|---|
customerTaxId | Customer tax ID already authorized and saved by your application. |
customerIdempotencyKey | Idempotency key for creating this customer; saved before the first request. |
chargeIdempotencyKey | A different idempotency key for this charge; saved with the order. |
chargeDueDate | Chosen due date, saved in UTC Unix seconds. |
var customer = await raims.Customers.CreateAsync(new CreateCustomerOptions
{
TaxId = customerTaxId,
}, new RequestOptions { IdempotencyKey = customerIdempotencyKey });
var charge = await raims.Charges.CreateAsync(new CreateChargeOptions
{
CustomerId = customer.Id,
AmountCents = 15000,
DueDate = chargeDueDate,
Title = "Pedido 1234",
}, new RequestOptions { IdempotencyKey = chargeIdempotencyKey });
string chargeId = charge.Id;
int? httpStatus = charge.LastResponse?.StatusCode;
var requestId = charge.LastResponse?.RequestId;
bool pending = httpStatus == 202;Persist the returned customer ID and charge ID on the order before returning success to your caller. The charge ID is the value used to resume the read below; the SDK variables are not durable storage.
| Result | What to do next |
|---|---|
HTTP 201 | The charge was created. Save its ID; creation does not confirm payment. This snippet does not request email or payment issuance. |
HTTP 202 in a creation that requests payment issuance | Save the same returned ID and keep the order pending. Retrieve that charge; do not create another one to resolve the pending result. |
| Error or missing response | Handle the structured error. If execution is uncertain, keep the intent and reconcile before retrying with the original key and payload. |
The canonical creation example below shows only the ID and status fields:
Charge without a link or email request
{
"id": "ch_1Q2W3E4R5T6Y7U8I9O0P",
"status": 0
}If the CPF or CNPJ already exists in the same company and environment, the
customer record is updated and retains its identifier. 15000 represents
BRL 150.00. Review the fields and conditions in
Create a charge. To retry the same intent after a lost
response, keep the key and every parameter, including the due date. An external
order reference does not replace idempotency.
Pagination and pending results
The following backend snippet counts at most 100 customers across pages, without logging their records. Keep the configured client open during iteration.
var page = await raims.Customers.ListAsync(new ListCustomersOptions { PageSize = 50 });
int visited = 0;
foreach (var customer in page.GetAutoPagingEnumerable())
{
visited++;
if (visited == 100) break;
}
Console.WriteLine($"Items visited: {visited}");Items visited: 0 means the query found no customers. 100 means the chosen limit was reached; it does not prove there are no more records. A page error interrupts the count. Save progress only after processing a complete page if your job must resume later.
Enumerating one page does not make additional requests. Use NextPageAsync()
and PreviousPageAsync() to follow cursors; the SDK retains the query filters.
GetAutoPagingEnumerable() and GetAutoPagingAsyncEnumerable() load following
pages during enumeration and may make several requests. Bound your application
work and use cancellation when needed.
HTTP 202 keeps the result pending. It does not confirm payment and the SDK does not start polling. When resuming the saved order, load chargeId from storage and retrieve that same charge once:
var current = await raims.Charges.GetAsync(chargeId);
Console.WriteLine($"HTTP status: {current.LastResponse?.StatusCode}; charge status: {current.Status}");HTTP 200 here confirms that the read succeeded. Interpret the returned status and payment_information using the charge reference; a successful GET does not mean the charge was paid or that issuance completed. If issuance is still pending, keep the same ID. Repeated reads do not speed up processing or issue another payment; contact support if the condition persists.
Idempotency and errors
The SDK sends Idempotency-Key only when the application supplies it to an
endpoint that accepts that header. It does not generate keys or automatically
retry POST, PATCH, or DELETE requests. Read retries are optional and default to zero.
Use the HTTP status and ApiErrorException.ErrorCode to decide how to handle a
failure. RequestId helps identify the attempt. ErrorMessage is a human
explanation and must not be compared as a control code. Do not log complete
responses, credentials, personal documents, or temporary links. Review
Idempotency and the
SDK reference.
Options use Optional<T> to distinguish an omitted field from an explicit
value. For updates, omission retains the current value; null clears only
fields whose contract allows it. Review each endpoint's conditions.
For example, if the read above returns HTTP 403 with API_KEY_PERMISSION_DENIED, the key lacks access to list customers. Enable View customers on the appropriate key and retry the read. Repeating it with the same permissions will not resolve that error.
For field validation failures, use error.details[].field and error.details[].code to locate the input to correct. Check HTTP response codes for other failures.
For an uncertain write, recover the saved key and the entire original payload. If the charge ID was received, retrieve that ID first. Within the idempotency retention period, a compatible retry can return the preserved result, including a pending 202. A key with different parameters can be rejected; do not change the due date or create a new key to bypass the uncertainty. After retention expires, reconcile before another write.
Use Sandbox
Use a Sandbox key with the simulation services raims.Simulations.Charges and
raims.Simulations.Refunds. A Production key does not become a Sandbox key by
using these services. Conditions for each simulation are described in the
Simulations reference.
Requests that ask for email or webhook delivery can reach external destinations even in Sandbox. Use only destinations authorized for the integration.
Receive webhooks
Read the original body bytes and signing headers received by your server:
using System.Collections.Generic;
using Raims;
var headers = new Dictionary<string, string>
{
["webhook-id"] = receivedDeliveryId,
["webhook-timestamp"] = receivedTimestamp,
["webhook-signature"] = receivedSignature,
};
var webhookEvent = WebhookUtility.ConstructEvent(rawBodyBytes, headers, webhookSecret);webhookSecret is the secret_key returned when creating or rotating the
webhook, not the API Bearer key. Do not reserialize the JSON before verification.
A failure throws SignatureVerificationException; do not process the body then.
A valid signature does not prevent duplicate processing. Check type and
environment, deduplicate by the event's id, and durably record the work before
returning success. The webhook-id header identifies the delivery and does not
replace the event identifier. Review
Receive events.
Update the SDK
To get the latest stable version from NuGet, run the command again without a version argument:
dotnet add package RaimsNuGet updates the project reference. Review
releases and test the flows used
by your integration. The SDK version is independent of the API's HTTP /v1 version.
The complete configuration, pagination, error, and webhook guides are available in the SDK repository.