Cnpja (Cnpja v0.1.0)

Copy Markdown View Source

Elixir SDK for the CNPJá API.

All functions return {:ok, struct} on success or {:error, %Cnpja.Error{}} on failure.

Configuration

Via config.exs:

config :cnpja_ex, api_key: System.get_env("CNPJA_API_KEY")

Via option (multi-tenant):

Cnpja.get_office("37335118000180", api_key: "other-key")

Example

case Cnpja.get_office("37335118000180") do
  {:ok, office}                       -> office.alias
  {:error, %Cnpja.Error{status: 404}} -> "not found"
  {:error, %Cnpja.Error{status: 429, required: r}} -> "insufficient credits: #{r}"
  {:error, %Cnpja.Error{}}            -> "generic error"
end

Summary

Functions

Queries state registrations from the CCC for the given states.

Returns the CCC fiscal regularity certificate as a PDF binary.

Looks up a company by the first 8 digits of the CNPJ (root).

Returns the credit balance for the account associated with the API key.

Looks up an establishment by its full 14-digit CNPJ.

Returns the map image of the establishment location (PNG binary).

Returns the Street View image of the establishment (JPEG binary).

Looks up a person by their CNPJá ID.

Queries establishment data directly from the Receita Federal.

Returns the Comprovante de Inscrição e de Situação Cadastral as a PDF binary.

Queries Simples Nacional and MEI data for a company.

Returns the Simples Nacional enrollment declaration as a PDF binary.

Queries SUFRAMA enrollment data for an establishment.

Returns the SUFRAMA fiscal incentives certificate as a PDF binary.

Looks up a Brazilian postal code (CEP).

Searches establishments with filters.

Searches persons with filters.

Functions

get_ccc(tax_id, states, opts \\ [])

@spec get_ccc(String.t(), String.t(), keyword()) ::
  {:ok, Cnpja.Ccc.t()} | {:error, Cnpja.Error.t()}

Queries state registrations from the CCC for the given states.

Parameters

  • tax_id — full 14-digit CNPJ
  • states — comma-separated state codes or "ALL"

Example

{:ok, ccc} = Cnpja.get_ccc("37335118000180", "SP,MG")

get_ccc_certificate(tax_id, opts \\ [])

@spec get_ccc_certificate(
  String.t(),
  keyword()
) :: {:ok, binary()} | {:error, Cnpja.Error.t()}

Returns the CCC fiscal regularity certificate as a PDF binary.

get_company(company_id, opts \\ [])

@spec get_company(
  String.t(),
  keyword()
) :: {:ok, Cnpja.Company.t()} | {:error, Cnpja.Error.t()}

Looks up a company by the first 8 digits of the CNPJ (root).

Options

  • :simples — include Simples Nacional data
  • :simples_history — include Simples Nacional history

get_credit(opts \\ [])

@spec get_credit(keyword()) :: {:ok, Cnpja.Credit.t()} | {:error, Cnpja.Error.t()}

Returns the credit balance for the account associated with the API key.

get_office(tax_id, opts \\ [])

@spec get_office(
  String.t(),
  keyword()
) :: {:ok, Cnpja.Office.t()} | {:error, Cnpja.Error.t()}

Looks up an establishment by its full 14-digit CNPJ.

Options

  • :simples — include Simples Nacional data
  • :simples_history — include Simples Nacional history
  • :registrations — state registrations: "ALL", "NONE", or comma-separated state codes
  • :registrations_source — IE source: "CCC" (default) or "RECEIPTS"
  • :suframa — include SUFRAMA data
  • :geocoding — include geographic coordinates
  • :links — certificate links, comma-separated
  • :strategy — cache strategy: "CACHE_IF_ERROR" | "NO_CACHE" | "CACHE"

  • :max_age — maximum cache age in days
  • :max_stale — stale cache tolerance in days

get_office_map(tax_id, opts \\ [])

@spec get_office_map(
  String.t(),
  keyword()
) :: {:ok, binary()} | {:error, Cnpja.Error.t()}

Returns the map image of the establishment location (PNG binary).

get_office_street_view(tax_id, opts \\ [])

@spec get_office_street_view(
  String.t(),
  keyword()
) :: {:ok, binary()} | {:error, Cnpja.Error.t()}

Returns the Street View image of the establishment (JPEG binary).

get_person(person_id, opts \\ [])

@spec get_person(
  String.t(),
  keyword()
) :: {:ok, Cnpja.Person.t()} | {:error, Cnpja.Error.t()}

Looks up a person by their CNPJá ID.

get_rfb(tax_id, opts \\ [])

@spec get_rfb(
  String.t(),
  keyword()
) :: {:ok, Cnpja.Rfb.t()} | {:error, Cnpja.Error.t()}

Queries establishment data directly from the Receita Federal.

get_rfb_certificate(tax_id, opts \\ [])

@spec get_rfb_certificate(
  String.t(),
  keyword()
) :: {:ok, binary()} | {:error, Cnpja.Error.t()}

Returns the Comprovante de Inscrição e de Situação Cadastral as a PDF binary.

get_simples(tax_id, opts \\ [])

@spec get_simples(
  String.t(),
  keyword()
) :: {:ok, Cnpja.Simples.t()} | {:error, Cnpja.Error.t()}

Queries Simples Nacional and MEI data for a company.

get_simples_certificate(tax_id, opts \\ [])

@spec get_simples_certificate(
  String.t(),
  keyword()
) :: {:ok, binary()} | {:error, Cnpja.Error.t()}

Returns the Simples Nacional enrollment declaration as a PDF binary.

get_suframa(tax_id, opts \\ [])

@spec get_suframa(
  String.t(),
  keyword()
) :: {:ok, Cnpja.Suframa.t()} | {:error, Cnpja.Error.t()}

Queries SUFRAMA enrollment data for an establishment.

get_suframa_certificate(tax_id, opts \\ [])

@spec get_suframa_certificate(
  String.t(),
  keyword()
) :: {:ok, binary()} | {:error, Cnpja.Error.t()}

Returns the SUFRAMA fiscal incentives certificate as a PDF binary.

get_zip(code, opts \\ [])

@spec get_zip(
  String.t(),
  keyword()
) :: {:ok, Cnpja.Zip.t()} | {:error, Cnpja.Error.t()}

Looks up a Brazilian postal code (CEP).

Example

{:ok, zip} = Cnpja.get_zip("01310100")
zip.city  #=> "São Paulo"

search_offices(opts \\ [])

@spec search_offices(keyword()) ::
  {:ok, Cnpja.OfficeSearch.t()} | {:error, Cnpja.Error.t()}

Searches establishments with filters.

Common options

  • :q — search by company name
  • :state — filter by state code
  • :main_activity — filter by primary CNAE
  • :limit — results per page
  • :next — pagination cursor

search_persons(opts \\ [])

@spec search_persons(keyword()) ::
  {:ok, Cnpja.PersonSearch.t()} | {:error, Cnpja.Error.t()}

Searches persons with filters.

Common options

  • :q — search by name
  • :type"NATURAL" or "LEGAL"
  • :limit — results per page
  • :next — pagination cursor