Arbeidstilsynet.Saksarkiv.Client 0.5.2

Prefix Reserved
dotnet add package Arbeidstilsynet.Saksarkiv.Client --version 0.5.2
                    
NuGet\Install-Package Arbeidstilsynet.Saksarkiv.Client -Version 0.5.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Arbeidstilsynet.Saksarkiv.Client" Version="0.5.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Arbeidstilsynet.Saksarkiv.Client" Version="0.5.2" />
                    
Directory.Packages.props
<PackageReference Include="Arbeidstilsynet.Saksarkiv.Client" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Arbeidstilsynet.Saksarkiv.Client --version 0.5.2
                    
#r "nuget: Arbeidstilsynet.Saksarkiv.Client, 0.5.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Arbeidstilsynet.Saksarkiv.Client@0.5.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Arbeidstilsynet.Saksarkiv.Client&version=0.5.2
                    
Install as a Cake Addin
#tool nuget:?package=Arbeidstilsynet.Saksarkiv.Client&version=0.5.2
                    
Install as a Cake Tool

Arbeidstilsynet.Saksarkiv.Client

Generated client for Saksarkivtjeneste (API v2 and v3) with dependency injection, resilience and health check support.

Installation

dotnet add package Arbeidstilsynet.Saksarkiv.Client

What the package contains

  • SaksarkivClientV3 (namespace Arbeidstilsynet.Saksarkiv.Client.V3): generated client and models for API v3
  • SaksarkivClientV2 (namespace Arbeidstilsynet.Saksarkiv.Client.V2): generated client and models for the legacy API v2
  • AddSaksarkivClientV3(...) / AddSaksarkivClientV2(...) for dependency injection
  • SaksarkivConfiguration for base URL, scope and health check timeout
  • ISaksarkivTokenProvider so the consuming app can decide how access tokens are fetched
  • A health check named Saksarkiv

The clients are generated with Kiota from the OpenAPI documents produced by Saksarkivtjeneste itself. Both documents are included in the package as openApiV2.json and openApiV3.json.

Versioning

The package is on a 0.x version line while the v3 API is still evolving. Minor versions may contain breaking changes. See CHANGELOG.md in the package release notes.

Registering the client

The package does not depend on Texas or any other project-specific token provider. Consumers must register an ISaksarkivTokenProvider implementation themselves.

Register the API version(s) you use:

using Arbeidstilsynet.Saksarkiv.Client.DependencyInjection;
using Arbeidstilsynet.Saksarkiv.Client.DependencyInjection.Configuration;
using Arbeidstilsynet.Saksarkiv.Client.Ports;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddScoped<ISaksarkivTokenProvider, MySaksarkivTokenProvider>();

builder.Services.AddSaksarkivClientV3(
    new SaksarkivConfiguration
    {
        BaseUrl = "https://saksarkiv.example.no/",
        Scope = "api://saksarkiv/.default",
    }
);

Using both v2 and v3

Both methods can be called. They share the same HTTP client, resilience pipeline, authentication and health check, which are only registered once. When both are called, the configuration and resilience callback from the first call are used.

builder.Services.AddSaksarkivClientV2(configuration); // resolves SaksarkivClientV2
builder.Services.AddSaksarkivClientV3(configuration); // resolves SaksarkivClientV3

Resilience

If you need to customize the retry/timeouts/circuit-breaker behavior, use the resilience callback:

builder.Services.AddSaksarkivClientV3(
    configuration,
    options =>
    {
        options.Retry.MaxRetryAttempts = 2;
        options.AttemptTimeout.Timeout = TimeSpan.FromSeconds(15);
        options.TotalRequestTimeout.Timeout = TimeSpan.FromMinutes(1);
    }
);

The default resilience settings are:

  • 2 retry attempts
  • 5 seconds retry delay
  • 15 seconds per-attempt timeout
  • 1 minute total request timeout
  • no retries for unsafe HTTP methods (POST, PUT, PATCH, DELETE, CONNECT), since a retried write could be applied twice
  • no retries for the health probe /api/health*

Health check

Both registration methods add a health check named Saksarkiv. It calls GET /api/health/authPing through the same authenticated HTTP client as the API calls, so it verifies token acquisition, network access and that Saksarkivtjeneste accepts the token. The endpoint is shared by all API versions.

The check reports Degraded (never Unhealthy) on failure or when it does not respond within SaksarkivConfiguration.HealthCheckTimeout (default 800 ms). Keep the timeout comfortably below your readiness probe timeout.

Token provider example

The client only sends the token to the configured BaseUrl (same scheme, host and port). A request to another origin, for example via WithUrl(...), throws InvalidOperationException.

using Arbeidstilsynet.Saksarkiv.Client.Ports;

public sealed class MySaksarkivTokenProvider : ISaksarkivTokenProvider
{
    public async Task<string> GetAccessToken(
        string scope,
        CancellationToken cancellationToken = default
    )
    {
        // Replace with the token source used by your application.
        return await Task.FromResult("access-token");
    }
}

Usage

You can use SaksarkivClientV3 directly, but it is highly recommended that you wrap it in your own narrow interface that matches the intended use in that service or bounded context. That keeps tests simpler, avoids coupling every consumer to the full Saksarkiv API surface, and gives you a stable seam if the generated fluent API changes later.

Define an interface for only the operations your service needs, and implement it as a thin adapter over SaksarkivClientV3:

using Arbeidstilsynet.Saksarkiv.Client.V3;
using Arbeidstilsynet.Saksarkiv.Client.V3.Models.AT.EArkiv.Entiteter.API.V3;

public interface IArchiveClient
{
    Task<List<Mappetype>?> GetCaseTypes(CancellationToken cancellationToken);
}

public sealed class SaksarkivArchiveClient(SaksarkivClientV3 saksarkivClient) : IArchiveClient
{
    public async Task<List<Mappetype>?> GetCaseTypes(CancellationToken cancellationToken)
    {
        return await saksarkivClient.Api.V3.Metadata.Sakstyper.GetAsync(
            cancellationToken: cancellationToken
        );
    }
}

Register the adapter alongside the client:

builder.Services.AddScoped<ISaksarkivTokenProvider, MySaksarkivTokenProvider>();
builder.Services.AddSaksarkivClientV3(...);
builder.Services.AddScoped<IArchiveClient, SaksarkivArchiveClient>();

The rest of your application then depends on IArchiveClient, not on SaksarkivClientV3 directly.

Creating a case (opprett sak)

The v3 endpoint accepts a multipart/form-data body with a JSON payload part and optional files. The generated Api.V3.Saker.PostAsync(...) takes a MultipartBody; the package ships a typed OpprettSakAsync(...) extension that serializes OpprettSakRequest into the payload part and attaches any files.

using Arbeidstilsynet.Saksarkiv.Client.V3;
using Arbeidstilsynet.Saksarkiv.Client.V3.Models.AT.EArkiv.Entiteter.API.V3;

public sealed class ArchiveService(SaksarkivClientV3 client)
{
    public async Task<string?> CreateCase(
        string sakEksternId,
        string journalpostEksternId,
        CancellationToken ct
    )
    {
        var request = new OpprettSakRequest
        {
            Tittel = "Min sak",
            Saksbehandler = new Saksbehandler
            {
                Brukernavn = "ETTERNAVN_F",
                Avdeling = "ABC",
            },
            EksternId = sakEksternId, // e.g. "minapp-sak-123", see below
            Sakstype = "...",
            Arkivkode = "...",
            Tilgangskode = "...",
            Journalposter =
            [
                new OpprettJournalpostRequest
                {
                    EksternId = journalpostEksternId, // e.g. "minapp-journalpost-456"
                    JournalpostType = Journalposttype.Inngaaende,
                    Tittel = "Brev",
                    Hoveddokument = new OpprettDokumentRequest { Filnavn = "hoved.pdf" },
                    KorrespondansePart = new OpprettJournalpostRequestKorrespondansePart { Navn = "Ola Nordmann" },
                },
            ],
        };

        await using var pdf = File.OpenRead("hoved.pdf");
        var files = new[]
        {
            new SaksarkivFile
            {
                FileName = "hoved.pdf", // must match the document Filnavn values
                Content = pdf,
                ContentType = "application/pdf",
            },
        };

        // Asynchronous (202): returns a queued message you can track via Api.V3.Meldinger[id].
        var status = await client.OpprettSakAsync(request, files, cancellationToken: ct);
        return status?.MeldingId;
    }
}

File names in SaksarkivFile.FileName must match the Filnavn values in the main document and attachments, and be unique within the request.

File names

File names must be unique within a request (ordinal comparison) and match the Filnavn values in the payload. OpprettSakAsync throws ArgumentException on duplicates.

If you build a MultipartBody yourself, for example for Api.V3.Saker[eksternId].Journalpost, check for duplicates first: AddOrReplacePart keys parts by name and file name, so a second file with the same name silently replaces the first. The server then receives a valid request and archives the wrong document.

Choosing EksternId

EksternId identifies a case or journalpost in Saksarkivtjeneste. It is generated by your system and must be globally unique, across all fagsystemer and across cases and journalposts. Max 200 characters. Prefix it with the name of your fagsystem, for example minapp-sak-{id} and minapp-journalpost-{id}, so it cannot collide with ids from other systems.

After the case is created, the v3 API addresses it by this value: get (Api.V3.Saker[eksternId]), update, close, reopen and add journalposts. Messages for the same EksternId are processed in the order they were received.

Build it from an identifier your system already stores, such as the id of the entity the case belongs to. If you generate one (for example a Guid), persist it before calling OpprettSakAsync and reuse it for retries and later operations. A value generated per call cannot be used to find the case again.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.5.2 197 11/26/2026
0.5.1 137 11/25/2026
0.5.0 90 11/24/2026
0.4.1 81 11/24/2026
0.4.0 245 11/23/2026
0.3.1 368 11/20/2026
0.3.0 259 11/17/2026
0.2.0 89 11/17/2026
0.1.1 92 11/17/2026
0.1.0 160 11/12/2026
0.1.0-beta.1 60 11/11/2026

# Changelog

All notable changes to `Arbeidstilsynet.Saksarkiv.Client` are documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). While on `0.x`, minor
versions may contain breaking changes.

Every released version must have a `## <version>` heading matching `<Version>` in
`Saksarkiv.Client.csproj`; CI fails otherwise.

## 0.5.2

### Changed

- Updated Microsoft.Extensions.Http.Resilience to 10.11.1.

## 0.5.1

### Changed

- Updated Microsoft.Kiota.Bundle to 2.2.0.

## 0.5.0

### Changed

- Remove various fields from QueueMelding
- Rename MeldingStatus to MeldingInfo
- Rename MeldingStatusType to MeldingStatus
- Rename EksternId to SekvensId in MeldingInfo

## 0.4.1

### Changed

- The v3 `Personnummer` fields now document and validate support for D-numbers.

## 0.4.0

### Changed

- **Breaking:** In the v3 API, `PersonInfo` on journalposter is renamed to `KorrespondansePart`
 (Noark 5 term). `OpprettJournalpostRequest.PersonInfo` is now `KorrespondansePart` of type
 `OpprettJournalpostRequestKorrespondansePart`, and `HentSakResponseJournalpost.PersonInfo` is now
 `KorrespondansePart` of type `HentSakResponseKorrespondansePart`.

## 0.3.1

### Changed

- Regenerated the v2 and v3 client specifications with OpenAPI 3.1.2. The HTTP API is unchanged.

## 0.3.0

### Changed

- **Breaking:** `MeldingId` is now a Guid wherever applicable, and `MeldingStatus.Fullfort` has been
 renamed to `MeldingStatus.SistEndret`

## 0.2.0

### Changed

- **Breaking:** The v2 models `AvskrivRestanseRequest`, `AvskrivRestanseForBrukerRequest` and
 `HentSaksarkivKorrespondanselisteParams` moved from
 `Arbeidstilsynet.Saksarkiv.Client.V2.Models.AT.EArkiv.RestApi` to
 `Arbeidstilsynet.Saksarkiv.Client.V2.Models.AT.EArkiv.RestApi.V2`. The HTTP API is unchanged.

## 0.1.1

### Changed

- Updated Microsoft.Extensions dependency packages to 10.0.15.

## 0.1.0

First version, replacing `Arbeidstilsynet.Common.Saksarkiv` (from
[dotnet-common](https://github.com/Arbeidstilsynet/dotnet-common)), now published from this
repository.

### Added

- `SaksarkivClientV3` in `Arbeidstilsynet.Saksarkiv.Client.V3`, generated for API v3.
- `OpprettSakAsync(...)` extension and `SaksarkivFile` for creating a case with files over v3.
 It throws `ArgumentException` if two files have the same `FileName`.
- `AddSaksarkivClientV3(...)`.
- The OpenAPI documents (`openApiV2.json`, `openApiV3.json`) are included in the package.

### Changed

- Package renamed from `Arbeidstilsynet.Common.Saksarkiv` to `Arbeidstilsynet.Saksarkiv.Client`,
 and the root namespace from `Arbeidstilsynet.Common.Saksarkiv` to
 `Arbeidstilsynet.Saksarkiv.Client`.
- The v2 client is renamed from `SaksarkivClient` to `SaksarkivClientV2` and moved to
 `Arbeidstilsynet.Saksarkiv.Client.V2`. Register it with `AddSaksarkivClientV2(...)` (previously
 `AddSaksarkivClient(...)`).
- The clients are generated at build time from the OpenAPI documents produced by
 Saksarkivtjeneste, instead of a copy of the document. For v2 this means:
 - Model namespaces gained an `AT.EArkiv` segment, e.g. `V2.Models.AT.EArkiv.Entiteter.Meldinger`
   (previously `Models.Entiteter.Meldinger`).
 - `Apiv2.Sak.Validersaksnummer` is split into `ValiderSaksnummer` (`POST`) and
   `ValidersaksnummerEscaped` (`GET`).
 - `Apiv2.Saker.FinnMedReferanser` accepts the `KunUtgaatteSaker` query parameter.
 - `Apiv2.Health.ArkivStatus` and `Api.Health.Ping`/`AuthPing` are available.
- Unsafe HTTP methods (`POST`, `PUT`, `PATCH`, `DELETE`, `CONNECT`) are no longer retried.
 Previously only `POST` was excluded.
- Retries for the health probe are also skipped when the request fails with an exception.
- The `Saksarkiv` health check is registered by both `AddSaksarkivClientV2(...)` and
 `AddSaksarkivClientV3(...)`, and only once when both are called.
- The access token is only sent to the configured `BaseUrl` origin (scheme, host and port).
 Requests to another origin, for example via Kiota's `WithUrl(...)`, throw
 `InvalidOperationException`.
- Targets `net10.0` only (previously also `net8.0`).