Wenche.AltinnClient (wenche v0.3.0)

Copy Markdown View Source

Altinn 3 API client for creating instances, uploading data, and completing submissions.

Ported from wenche/altinn_client.py in the original Python Wenche project.

Handles instance creation, data submission, and completion for all three submission types: annual accounts, tax return, and shareholder register.

Summary

Functions

Moves the instance to the next process step.

Advances the instance to the signing step and returns the Altinn inbox URL where the user can sign with BankID/ID-Porten.

Gets the current status of an instance.

Gets the current status of an instance.

Uploads the skattemelding envelope (skattemeldingOgNaeringsspesifikasjon) as a new data element on the instance.

Adds a new data element to an instance with POST.

Advances the instance one process step (PUT /process/next) without returning the inbox URL. Use fullfoor_instans/3 for the final step.

Creates a new AltinnClient with the given token and environment.

Updates an existing data element in the instance with PUT.

Creates a new instance for the given submission type and organization.

Types

t()

@type t() :: %Wenche.AltinnClient{
  apps_base: String.t(),
  env: String.t(),
  inbox_url: String.t(),
  req_options: keyword(),
  token: String.t()
}

Functions

complete_instance(altinn_token, instance_id, app_id, opts \\ [])

Moves the instance to the next process step.

Returns {:ok, response_body} or {:error, reason}.

create_instance(altinn_token, org_number, app_id, opts \\ [])

Creates a new Altinn 3 app instance.

Returns {:ok, instance_body} or {:error, reason}.

fullfoor_instans(client, app_key, instans)

Advances the instance to the signing step and returns the Altinn inbox URL where the user can sign with BankID/ID-Porten.

Signing requires ID-Porten and cannot be done programmatically.

Returns {:ok, inbox_url} or {:error, reason}.

get_status(altinn_token, instance_id, app_id, opts \\ [])

Gets the current status of an instance.

Returns {:ok, response_body} or {:error, reason}.

hent_status(client, app_key, instans)

Gets the current status of an instance.

Returns {:ok, response_body} or {:error, reason}.

last_opp_skattemelding_konvolutt(client, instans, konvolutt)

Uploads the skattemelding envelope (skattemeldingOgNaeringsspesifikasjon) as a new data element on the instance.

The SKD formueinntekt-skattemelding-v2 app expects:

  • POST (not PUT) to /instances/{id}/data?dataType=skattemeldingOgNaeringsspesifikasjon
  • Content-Type: text/xml
  • Content-Disposition: attachment; filename=skattemelding.xml — no quotes around the filename; the app's parser is sensitive to this.

Returns {:ok, response_body} or {:error, reason}.

legg_til_data_element(client, app_key, instans, data_type, data, content_type)

Adds a new data element to an instance with POST.

Unlike oppdater_data_element/6 which updates an existing element, this creates a new data element on the instance.

Returns {:ok, response_body} or {:error, reason}.

neste_prosesssteg(client, app_key, instans)

Advances the instance one process step (PUT /process/next) without returning the inbox URL. Use fullfoor_instans/3 for the final step.

Returns {:ok, response_body} or {:error, reason}.

new(altinn_token, opts \\ [])

Creates a new AltinnClient with the given token and environment.

Options

  • :env"test" or "prod" (default: "prod")
  • :req_options — extra options passed to Req (default: [])

oppdater_data_element(client, app_key, instans, data_type, data, content_type)

Updates an existing data element in the instance with PUT.

Altinn creates data elements automatically upon instance creation; we find the correct element via dataType and replace its contents.

Returns {:ok, response_body} or {:error, reason}.

opprett_instans(client, app_key, org_nummer)

Creates a new instance for the given submission type and organization.

App keys

  • "aarsregnskap" — Annual accounts (BRG)
  • "aksjonaerregister" — Shareholder register (SKD)
  • "skattemelding" — Tax return (SKD)

Returns {:ok, instance_map} or {:error, reason}.

update_data_element(altinn_token, instance_id, app_id, data_type, content_type, data, opts \\ [])

Uploads/updates a data element on an existing instance.

Returns {:ok, response_body} or {:error, reason}.