Docs
Checking Raims account
Integrations

Elixir SDK

Install through Hex and connect Elixir applications to the public API with the official modules.

The official Elixir SDK connects server applications to the Raims public API. Use resource modules, response models, pagination, and webhook verification. Keep the API key in your backend, outside applications distributed to customers and routine logs.

The SDK reference lists each resource's methods and parameters.

Install the SDK

Use Elixir 1.18 or later with Erlang/OTP 27 or later. The official raims package is available on Hex.

If Hex is not installed yet, install it once:

Shell
mix local.hex

From your project directory, check the current stable version and configuration:

Shell
mix hex.info raims

Insert the line labeled Config: as an item in the list returned by deps/0, keeping your other dependencies. The structure in mix.exs is:

mix.exs
elixir
defp deps do
  [
    # Paste the complete {:raims, ...} tuple shown by mix hex.info raims here.
  ]
end

The comment marks the insertion point; replace it with the actual Hex tuple before running mix deps.get.

Then fetch the dependencies and compile:

Shell
mix deps.get
mix compile

Mix resolves dependencies according to the configuration and records their versions in mix.lock. Keep that file for repeatable installation.

Configure the client

  1. Prepare the credential

    Obtain a key through API keys and store it in a protected variable or your application's secret store. It determines company, environment, and permissions. 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.

  2. Save the read example

    Save the script at the root of the project containing mix.exs.

    read_customers.exs
    elixir
    client =
      Raims.Client.new(System.fetch_env!("RAIMS_API_KEY"),
        timeout: 30_000,
        max_network_retries: 0
      )
    
    case Raims.Customers.list(client, %{page_size: 10}) do
      {:ok, response} ->
        IO.puts("HTTP status: #{response.status_code}; items: #{length(response.data["list"])}")
    
      {:error, error} ->
        IO.puts(:stderr, "kind: #{error.kind}; HTTP status: #{error.status_code}; code: #{error.code}; Request-Id: #{error.request_id}")
        System.halt(1)
    end
  3. Run and check the result

    From the project directory, with RAIMS_API_KEY available to the process, run:

    Shell
    mix run read_customers.exs

    A successful read prints HTTP status: 200 and the number of items in this page. items: 0 is 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.

HTTP 200 response example excerptGET /v1/customers

No customers found

JSON
{
  "list": [],
  "page": {
    "page_size": 10,
    "has_next": false,
    "has_previous": false,
    "next_after": null,
    "previous_before": null
  }
}

Timeouts use milliseconds. The client is immutable and reusable; it does not own a process that needs stopping. Each HTTP attempt closes its connection when finished. The following examples use this client.

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 orderSource and purpose
customer_tax_idCustomer tax ID already authorized and saved by your application.
customer_keyIdempotency key for creating this customer; saved before the first request.
charge_keyA different idempotency key for this charge; saved with the order.
due_date_unixChosen due date, saved in UTC Unix seconds.
elixir
with {:ok, customer} <-
       Raims.Customers.create(client, %{tax_id: customer_tax_id},
         idempotency_key: customer_key
       ),
     {:ok, charge} <-
       Raims.Charges.create(
         client,
         %{
           customer_id: customer.data["id"],
           amount_cents: 15000,
           due_date: due_date_unix,
           title: "Pedido 1234"
         },
         idempotency_key: charge_key
       ) do
  {:ok, %{charge_id: charge.data["id"], pending: charge.status_code == 202}}
else
  {:error, error} -> {:error, error.kind, error.request_id}
end

If the CPF or CNPJ already exists in the same company and environment, the customer record is updated and keeps its ID.

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.

ResultWhat to do next
HTTP 201The 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 issuanceSave 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 responseHandle 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:

HTTP 201 response example excerptPOST /v1/charges

Charge without a link or email request

JSON
{
  "id": "ch_1Q2W3E4R5T6Y7U8I9O0P",
  "status": 0
}

15000 represents BRL 150.00. Maps accept atom or string keys with JSON names. Omission keeps a field absent; nil sends null where allowed. During an update, %{external_reference: nil} can clear the reference; omission preserves it. Responses use response.data; Access.fetch/2 distinguishes an absent field from one containing nil.

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.

elixir
{:ok, first_page} = Raims.Customers.list(client, %{page_size: 50})

visited =
  first_page
  |> Raims.Page.stream()
  |> Enum.take(100)
  |> length()

IO.puts("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.

A response list contains only the received page. Raims.Page.stream/1 fetches further pages on demand; Enum.take/2 bounds collection. The stream raises Raims.Error if a page fails. next_page/1 and previous_page/1 return {:ok, response}, {:ok, nil}, or {:error, error}, preserving filters and options. Do not send after and before together.

HTTP 202 keeps the result pending. It does not confirm payment and the SDK does not start polling. When resuming the saved order, load charge_id from storage and retrieve that same charge once:

elixir
case Raims.Charges.retrieve(client, charge_id) do
  {:ok, response} ->
    IO.puts("HTTP status: #{response.status_code}; charge status: #{response.data["status"]}")
  {:error, error} ->
    IO.puts(:stderr, "kind: #{error.kind}; code: #{error.code}; Request-Id: #{error.request_id}")
end

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

elixir
case Raims.Customers.list(client, %{page_size: 10}) do
  {:ok, response} ->
    IO.puts("HTTP status: #{response.status_code}; items: #{length(response.data["list"])}")
  {:error, error} ->
    IO.puts(:stderr, "kind: #{error.kind}; HTTP status: #{error.status_code}; code: #{error.code}; Request-Id: #{error.request_id}")
    for %{"field" => field, "code" => code} <- error.details || [] do
      IO.puts(:stderr, "field: #{field}; code: #{code}")
    end
end

Functions return {:ok, response} or {:error, %Raims.Error{}} tuples; ! variants raise the exception. Use error.code to decide how to handle an API error, alongside error.kind, the HTTP status, and error.request_id. error.api_message contains the API's diagnostic text. error.message and Exception.message(error) are generic and do not include that text. Do not use message text to control the integration.

error.details returns the API's details list, or nil when the field is absent or is not a list. The example reads the string keys "field" and "code" from each validation detail. Invalid local arguments raise ArgumentError. Do not log bodies or credentials.

The SDK does not generate idempotency keys or retry writes. After a lost response, retrieve the operation; when retrying is permitted, use the same key and parameters. max_network_retries enables eligible GET/HEAD read retries only, with a default of zero. Waits, Retry-After, and attempts share the timeout budget. See Idempotency.

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.

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 and a resource from that environment:

elixir
sandbox = Raims.Client.new(System.fetch_env!("RAIMS_SANDBOX_API_KEY"))
{:ok, result} = Raims.Simulations.Charges.confirm_payment(sandbox, sandbox_charge_id)

The SDK does not select or change a credential's environment. Financial simulations accept Sandbox only; a Production key remains Production on a local host. See Simulations. Email requests and webhooks may reach external destinations even in Sandbox; use authorized destinations only.

Receive webhooks

Use the original raw_body binary and a list of received header pairs containing webhook-id, webhook-timestamp, and webhook-signature. The list preserves duplicates so the verifier can reject ambiguity.

elixir
case Raims.Webhook.construct_event(raw_body, signing_headers, webhook_secret) do
  {:ok, event} -> MyApp.persist_event(event)
  {:error, error} -> MyApp.reject_delivery(error)
end

webhook_secret is the webhook's secret_key held in your secret store; the MyApp handlers belong to your application. Do not parse and rebuild JSON before verifying its signature. The default tolerance is 300 seconds, with a synchronized clock. verify_signature/4 verifies without decoding JSON.

After verification, check type and environment, deduplicate the event id, and store the work durably before returning success. A valid signature does not prevent redelivery; webhook-id identifies the delivery. See Receive events.

Update the SDK

Check the current stable version and configuration:

Shell
mix hex.info raims

If needed, adjust the declaration in deps/0 using the Config: line shown by Hex. Then update the SDK within the declared constraints:

Shell
mix deps.update raims
mix compile

If the dependency used github:, git:, or path:, replace that declaration with the current Hex configuration and run the same commands. Also remove Git-only options such as ref:, branch:, and tag:. The Raims modules stay the same.

Review and keep the updated mix.lock. Read the release notes and test the flows used by your integration before updating the application. Installation does not apply future updates automatically.