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
Functions
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}.
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}.
Fetches the pre-filled tax return draft from Skatteetaten.
Returns {:ok, %{xml: xml, dokumentidentifikator: id}} or {:error, reason}.
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 typeskattemeldingUpersonlig.naering_id—<id>of<naeringsspesifikasjondokument>(optional in the schema; may be nil if not present).
Creates a new SKD skattemelding client.
Options
:env—"test"or"prod"(default:"prod"):req_options— extra options passed toReq(default:[])
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}.