Wenche.SkdSkattemeldingClient (wenche v0.3.0)

Copy Markdown View Source

Skatteetaten API client for skattemeldingen (corporate tax return).

Endpoints:

  • GET /{year}/{orgNr} — fetch pre-filled draft (contains partsnummer)
  • GET /utkast/{year}/{orgNr} — legacy alias for the pre-filled draft
  • POST /valider/{year}/{orgNr} — validate tax return XML

Authentication uses a raw Maskinporten token (no Altinn exchange) with the skatteetaten:formueinntekt/skattemelding scope and systemuser authorization for the target organisation. See Wenche.Maskinporten.get_skd_skattemelding_token/2.

Summary

Functions

Fetches the pre-filled skattemelding XML from Skatteetaten.

Fetches and extracts the company's partsnummer from Skatteetaten.

Fetches the pre-filled tax return draft from Skatteetaten.

Fetches the pre-filled draft AND the document identifiers that the request envelope must reference back via <dokumentreferanseTilGjeldendeDokument>.

Creates a new SKD skattemelding client.

Validates a tax return XML against Skatteetaten's validation service.

Types

t()

@type t() :: %Wenche.SkdSkattemeldingClient{
  base: String.t(),
  req_options: keyword(),
  token: String.t()
}

Functions

hent_forhandsutfylt(client, year, org_nr)

Fetches the pre-filled skattemelding XML from Skatteetaten.

Calls GET /{year}/{orgNr} with Accept: application/xml. If the response is wrapped in a forespoerselResponse envelope with base64-encoded <content>, the wrapper is unpacked and the inner XML returned.

Returns {:ok, inner_xml :: binary} or {:error, reason}.

hent_partsnummer(client, year, org_nr)

Fetches and extracts the company's partsnummer from Skatteetaten.

Convenience wrapper around hent_forhandsutfylt/3 + SkattemeldingXml.hent_partsnummer/1.

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

hent_utkast(client, year, org_nr)

Fetches the pre-filled tax return draft from Skatteetaten.

Returns {:ok, %{xml: xml, dokumentidentifikator: id}} or {:error, reason}.

hent_utkast_referanse(client, year, org_nr)

Fetches the pre-filled draft AND the document identifiers that the request envelope must reference back via <dokumentreferanseTilGjeldendeDokument>.

Skatteetaten's /valider and /innsendelse endpoints both reject a request envelope that lacks a reference to the current draft, with the error innkommendeForespoerselManglerReferanseTilGjeldendeSkattemelding.

Returns {:ok, %{partsnummer: integer, skattemelding_id: binary, naering_id: binary | nil}} or {:error, reason}.

  • partsnummer — Skatteetaten's internal integer ID for the company, extracted from the inner skattemelding XML.
  • skattemelding_id<id> of <skattemeldingdokument> in the response wrapper; goes into <dokumentreferanseTilGjeldendeDokument> with type skattemeldingUpersonlig.
  • naering_id<id> of <naeringsspesifikasjondokument> (optional in the schema; may be nil if not present).

new(token, opts \\ [])

Creates a new SKD skattemelding client.

Options

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

valider(client, year, org_nr, xml)

Validates a tax return XML against Skatteetaten's validation service.

The xml should be the full skattemeldingOgNaeringsspesifikasjonRequest envelope.

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