Skip to content

AI translation

This page was translated from German with AI. If in doubt, the German original applies.

Getting started

This page takes you from zero to your first successful call against ZEDAL — once via REST/JSON and once via the .NET SDK. Both paths lead to the same backend methods and use the same auth model; you only need one of them.

Path When Section
REST / JSON Any language with an HTTP client. No codegen, no SDK. First call via REST
.NET SDK C# applications. Encapsulates token refresh, document lifecycles, retries. First call via the .NET SDK

If you want to generate native gRPC code, you will find the basics under API reference → gRPC; the auth flow on this page applies there unchanged.

Prerequisites and access

To make a call, you need four things:

Item What it is Where from
Provider Numeric provider_id of the ZEDAL instance your account resides on. It applies to exactly one environment. from the access email; DiscoveryApi/ListProvider returns the list, see Step 0
Subscriber + account + password Contract tenant and the user account within it. ZEDAL support
App token JWT that identifies your application and defines its permission profile. It mirrors the permission table from the portal — whatever the app token does not unlock, the account cannot do via the API. ZEDAL support
Environment Test / Preview / Production, see Environments. your decision

App tokens and account data are not distributed publicly. Send an email to erp-tools@zedal.de. So that the request can be answered in one go, include:

  1. Integrating company — name and address.
  2. Application — name and version. Both are included in every call as clientName / clientVersion and therefore appear in the server-side logs; choose values you want to keep permanently.
  3. Target environment — Test, Preview or Production. To get started: Test.
  4. Provider — if already known, the provider short name or the provider_id; otherwise “please assign”.
  5. Business scope — which roles and processes you want to cover (e.g. DiWaSS notification and movement documents from the company perspective, or the authority perspective). The permission profile of the app token is derived from this.
  6. Login type — interactive user login (UsernameCredentials) or process without a user. For processes without a user, you use API keys; you create them yourself in the ZEDAL portal under “Mein ZEDAL” → “API-Keys” for the account.
  7. Contacts — technical and business.

You receive in return: app token, subscriber, account, initial password and the provider_id.

Environments

Environment Purpose Native gRPC REST / JSON and gRPC-Web
Production production operation api.live.zedal.de openapi.live.zedal.de
Preview staging and beta systems api.preview.zedal.de openapi.preview.zedal.de
Test test and integration systems api.test.zedal.de openapi.test.zedal.de

Develop against Test. This environment is intended for integrations and is operated as such. Preview is the preview state ahead of a production release; testing there only makes sense once your integration runs against Test.

Each environment serves only its own providers. A provider_id that works on Test is not served on Production and vice versa — not even if DiscoveryApi/ListProvider lists it on both hosts: the discovery list is a cross-environment directory, not a routing promise. What counts is the provider_id you were given for this environment.

The auth model

The flow has three stages and is identical for REST, gRPC and the SDK.

  1. Login. AuthApi/IssueRefreshToken with the app token and credentials returns the first refresh token. The application stores it securely; it no longer needs the credentials after that.
  2. Get access. RequestAccess with the refresh token as bearer returns an access token and a new refresh token. The submitted one loses its validity at the same moment – the new one is stored before anything else happens.
  3. Business call. Every further operation carries the access token as bearer.
  4. The access token expires. The expiry time is in the token's exp claim; the .NET SDK renews as soon as less than five minutes remain.
  5. Renew instead of logging in again. RequestAccess with the current refresh token returns a new pair again, and again the submitted token is invalidated.
  6. Keep working with the new access token.
  7. Logout. RevokeRefreshToken with the refresh token ends the session.
  1. Login. AuthApi/IssueRefreshToken returns the first refresh token, and the application stores it.
  2. Get access – without storing the new refresh token. The store still holds the old token, which ZEDAL has just invalidated.
  3. The first run works. The business call with the access token goes through.
  4. The access token expires.
  5. The second run fails at stage 2. RequestAccess with the old token ends with HTTP 401 and {"code":16,"message":"The token '…' is invalid."}. It looks like an expired token but is an overwritten one; the stored token is dead, and only a new login gets things going again.
sequenceDiagram
    participant App as Your application
    participant Z as ZEDAL

    App->>Z: AuthApi/IssueRefreshToken<br/>appToken + credentials
    Z-->>App: refreshToken
    Note over App: Store refreshToken securely

    App->>Z: AuthApi/RequestAccess<br/>Authorization: Bearer refreshToken
    Z-->>App: accessToken + newRefreshToken
    Note over App,Z: The submitted refreshToken is invalid from here on.<br/>Persist newRefreshToken before continuing.

    App->>Z: Business call<br/>Authorization: Bearer accessToken
    Z-->>App: Result

    App->>Z: AuthApi/RevokeRefreshToken (logout)
Stage Operation Authentication Result
1 — Login AuthApi/IssueRefreshToken none (appToken + credentials in the body) refreshToken
2 — Get access AuthApi/RequestAccess Authorization: Bearer <refreshToken> accessToken and newRefreshToken
3 — Business call every other operation Authorization: Bearer <accessToken> —
Logout AuthApi/RevokeRefreshToken Authorization: Bearer <refreshToken> session ended

Besides the app token, the login carries the usernameCredentials with subscriberId, accountId, and password. Processes without a user do not need the login: with an API key, they exchange the key directly for an access token.

Validity

Token Renewal Where you find the validity
Access token via RequestAccess with the current refresh token — no new login exp claim in the token
Refresh token every use returns a new token exp claim in the token

Do not assume a fixed lifetime in the client

Both tokens are JWTs and carry their expiry time in the exp claim. The actual duration is set server-side at issuance and can change — read it from the token instead of storing it in the client. A hard-coded assumption leads either to expired calls or to unnecessary refreshes.

In the .NET SDK, the expiry time is in Jwt.ValidTo. The SDK renews the access token on its own as soon as less than five minutes of remaining lifetime are left.

As long as your process uses the refresh token before it expires, the session persists. After that, you no longer need the original credentials and should not store them permanently in the application.

Token rotation — where most integrations fail

Every RequestAccess invalidates the submitted refresh token

Stage 2 always returns a new refresh token (newRefreshToken), and the submitted one loses its validity at the same moment. Persist the new token before you make the next business call.

Symptom if you don’t: the first run works, the second fails at stage 2 with HTTP 401 and {"code":16,"message":"The token '…' is invalid."}. From the outside, this looks like an expired token — in fact, it is an overwritten one.

Parallel processes lock each other out

Two processes using the same stored refresh token invalidate each other on refresh: the second RequestAccess submits a token that the first has already consumed. Sooner or later both end up with HTTP 401, and a restart does not help — the stored token is dead; only a new login with credentials helps.

Two viable patterns:

  • One refresher. Exactly one component holds the session and renews it; all other processes get the current access token from it. Within a single process, a lock around the refresh is sufficient.
  • One session per process. Each process logs in once on its own and keeps its own refresh token in its own storage. Sessions run independently of each other.

What does not work: the same refresh token in multiple processes or on multiple machines.

Some operations additionally require a scope — for example usermgt for the administrative operations of the AuthApi. Scopes are tied to the app token and the subscriber assignment and are carried as a claim in the access token; they are not requested per call.

Processes without a user: API key

A process without a user — integration, ERP connection, script — needs neither a login nor rotation. It exchanges an API key together with the app token in AuthApi/RequestAccess directly for an access token. No refresh token is created.

sequenceDiagram
    participant App as Your application
    participant Z as ZEDAL

    App->>Z: AuthApi/RequestAccess<br/>apiKeyCredentials: apiKey + appToken
    Z-->>App: accessToken + accessTokenExpiresOn + notGrantedScopes
    Note over App: No refresh token. The key does not change.

    App->>Z: Business call<br/>Authorization: Bearer accessToken
    Z-->>App: Result

    Note over App,Z: Shortly before the access token expires, exchange the same key again.
Login with credentials API key
Get the access token IssueRefreshToken, then RequestAccess with the refresh token RequestAccess with apiKeyCredentials, without an Authorization header
Renew RequestAccess with the latest refresh token RequestAccess again with the same key
Store permanently the rotating refresh token the key
Scopes in the access token from the app token and the subscriber assignment only those that both the key and the app token have
End RevokeRefreshToken nothing; you revoke the key itself in the portal

You create API keys in the ZEDAL portal under “Mein ZEDAL” → “API-Keys”, for the account logged in there; they cannot be created via the API. To create one, the portal asks for the account’s password again, because the key remains valid beyond the session. When creating a key, you choose the scopes it may grant and optionally an expiration date. Available are core, dataexport, and wastemanager, and nothing is implied: a key without a scope only identifies the account. Revoking also happens in the portal. After that, the key no longer yields a new access token; access tokens already issued may remain valid until they expire.

An API key is no JWT but a string of the form zedal_ak_<provider_id>_<key_id>_<secret>. The fixed prefix lets secret scanners recognize a key that accidentally ends up in a repository or a log. The provider_id in it is that of the provider that issued the key, i.e. the value for the provider_id header. Account, scopes, and expiration are not part of the key; only ZEDAL knows them. The portal shows the key exactly once. Keep it like a password.

Every account creates keys only for itself, the main account included. In the portal, the main account also sees the keys of its users and can revoke them. A key acts with the permissions of its account. If it should not depend on a person’s login, create it for a separate account for the integration.

The response of RequestAccess states in accessTokenExpiresOn when the access token expires, and lists in notGrantedScopes the scopes of the app token that a key could grant but this key does not. The granted scopes are in the scope claim of the access token.

Don’t exchange the key before every call

The server limits how often a key can be exchanged within a period of time. Beyond that, RequestAccess responds with HTTP 429 (gRPC status RESOURCE_EXHAUSTED). Use the access token until accessTokenExpiresOn approaches, and only then exchange the key.

An unknown, revoked, or expired key results in HTTP 401 (UNAUTHENTICATED), as does a locked account.

First call via REST

The base URL is the openapi.* host of the selected environment; the path is the fully qualified gRPC method name:

<HTTP verb> https://openapi.<environment>.zedal.de/<service.FullName>/<method>

The complete list of all 131 operations is in the API reference; details on the call format are under REST / JSON.

The provider_id header is mandatory on every call

All providers of an environment share the same API host. Without provider_id, the platform cannot assign the call to an instance — not even at login.

Symptom: HTTP 501 with the body {"code":12,"message":"Bad gRPC response. HTTP status code: 404","details":[]}. The text suggests a wrong path; in fact, the call cannot be assigned. Two causes are possible: the header is missing — or it names a provider that this environment does not serve.

The only exception is DiscoveryApi/ListProvider — the operation is cross-provider and unauthenticated.

The following steps use curl and jq against the Test environment. First, set the base values:

export ZEDAL_HOST=https://openapi.test.zedal.de
export ZEDAL_APP_TOKEN='<app token from the access email>'
export ZEDAL_PASSWORD='<account password>'

Step 0: Determine the provider

The only call that works without a token and without provider_id. It is also the fastest connectivity test.

curl -s "$ZEDAL_HOST/infotech.zedal.provider_discovery.v1.api.DiscoveryApi/ListProvider" \
  | jq '.provider[] | {id, shortName, type}'
{ "id": 1, "shortName": "PROD", "type": "PROD" }
{ "id": 2, "shortName": "TEST", "type": "TEST" }

Set the id you were given for this environment:

export ZEDAL_PROVIDER='<your provider_id>'

The full response additionally contains name, vendor, portalUrl, soapUrl and grpcUrl for each provider.

Step 1: Login — get a refresh token

REFRESH=$(curl -s -X POST \
  "$ZEDAL_HOST/infotech.zedal.core.v1.api.AuthApi/IssueRefreshToken" \
  -H 'Content-Type: application/json' \
  -H "provider_id: $ZEDAL_PROVIDER" \
  -d '{
        "appToken": "'"$ZEDAL_APP_TOKEN"'",
        "usernameCredentials": {
          "subscriberId": "mysubscriber",
          "accountId":    "myaccount",
          "password":     "'"$ZEDAL_PASSWORD"'"
        }
      }' \
  | jq -r .refreshToken)

With an API key, a process without a user skips this step and step 2, see Variant: access token with an API key.

Step 2: Get an access token

RESPONSE=$(curl -s -X POST \
  "$ZEDAL_HOST/infotech.zedal.core.v1.api.AuthApi/RequestAccess" \
  -H 'Content-Type: application/json' \
  -H "provider_id: $ZEDAL_PROVIDER" \
  -H "Authorization: Bearer $REFRESH" \
  -d "{\"refreshToken\": \"$REFRESH\"}")

ACCESS=$(echo "$RESPONSE"  | jq -r .accessToken)
REFRESH=$(echo "$RESPONSE" | jq -r .newRefreshToken)   # mandatory: the old one is now dead

The refresh token goes into both the Authorization header and the refreshToken body field; put the same token in both.

The last line is where an integration stands or falls: in a real application, it has to be a write to the same storage from which the next process start reads the token — not a shell variable.

Variant: access token with an API key

With an API key, a single call replaces steps 1 and 2. RequestAccess receives the key and the app token in the body; no Authorization header is needed.

export ZEDAL_API_KEY='<API key from the portal, zedal_ak_…>'

ACCESS=$(curl -s -X POST \
  "$ZEDAL_HOST/infotech.zedal.core.v1.api.AuthApi/RequestAccess" \
  -H 'Content-Type: application/json' \
  -H "provider_id: $ZEDAL_PROVIDER" \
  -d '{
        "apiKeyCredentials": {
          "apiKey":   "'"$ZEDAL_API_KEY"'",
          "appToken": "'"$ZEDAL_APP_TOKEN"'"
        }
      }' \
  | jq -r .accessToken)

Here, ZEDAL_PROVIDER is the number after zedal_ak_ in the key. The response contains no refresh token; there is nothing to store except the key. Continue with step 3.

Step 3: Business call

QueryApi/ListInboxDocuments lists the incoming entries in the inbox that are still to be taken over. A POST with the query parameter qpar in the body — the verb is listed per operation in the reference and is not always POST.

curl -s "$ZEDAL_HOST/infotech.zedal.core.v1.api.QueryApi/ListInboxDocuments" \
  -H "provider_id: $ZEDAL_PROVIDER" \
  -H "Authorization: Bearer $ACCESS" \
  -H "Content-Type: application/json" \
  -d '{
        "qpar": {
          "filter": [ { "path": "removed", "op": "EQUAL", "operands": [ { "b": false } ] } ],
          "pageSize": 50
        }
      }'
{ "entries": [ { "doc": { "documentId": { "id": "…" }, … }, … } ], "total": 1 }

Always include the filter removed = false: without it, the list also returns incoming entries that have already been taken over and removed. Further filters, sorting and paging are described under Query fields; how to take incoming entries over is described under Calls and synchronization.

Reading errors

The response body always has the form {"code": <grpc-status>, "message": "…", "details": []}. The HTTP status is derived from the gRPC status.

HTTP Body Cause
501 {"code":12,"message":"Bad gRPC response. HTTP status code: 404"} provider_id header missing, or the named provider is not served by this environment
400 {"code":3,"message":"MISSING_CREDENTIALS"} the login body contains no usernameCredentials
401 {"code":16,"message":"The token '…' is invalid."} token expired, rotated, revoked — or not a JWT at all
401 {"code":16,"message":"The given authentication token is invalid."} Authorization header missing entirely

This is the transport level. Business rejections from DiWaSS have their own error codes and can be contained in an HTTP 200 response, because the call was technically successful — see Error codes.

Make calls traceable

The .NET SDK sends the clientName and clientVersion headers with every call; they end up in the server-side logs. Via REST, you set them as HTTP headers. Use the same values you provided at registration; this shortens every support request considerably.

First call via the .NET SDK

Installation

dotnet add package Zedal.Sdk

The target is netstandard2.0; versioning follows Semantic Versioning (1.3.0). The package pulls in the generated gRPC types transitively.

Create the client

using Zedal.Sdk;
using Zedal.Sdk.Impl;   // TargetSystem
using Zedal.Sdk.Jwt;    // AppToken, RefreshToken

var client = ZedalClientFactory.Default.CreateClient(
    system:        TargetSystem.Test,      // Production | Preview | Test
    clientName:    "MyIntegrationApp",     // appears server-side as the caller
    clientVersion: "1.0.0");

The SDK sets the addresses itself from TargetSystem; it attaches provider_id to every call once the session is established. You do not need to manage either yourself.

Transport — usually nothing to do

The transport parameter defaults to ZedalTransport.Auto: when the connection is established, a one-time check determines whether the native host speaks HTTP/2. Only if an HTTP/1.x restriction is confirmed does the SDK switch to ZedalTransport.GrpcWeb via the openapi.* host; if the check gets no response (offline, timeout), it stays with native gRPC. The check is a blocking network call in the constructor.

In environments where HTTP/2 is known to be blocked — old corporate proxies, .NET Framework — you can skip the detour and set transport: ZedalTransport.GrpcWeb directly. If traffic goes through a proxy, specify it via the proxyUrl parameter or the INFOTECH_GRPC_PROXY_URL environment variable.

Register the rotation callback — before login

SetAccessTokenChanged is called on every token rotation: after CreateSession, after ContinueSession and on every automatic refresh.

client.SetAccessTokenChanged(tokens =>
    SecureStorage.Save("zedal-refresh-token", tokens.refreshToken.Jwt.EncodedToken));

tokens is a tuple (AccessToken accessToken, RefreshToken refreshToken). The encoded JWT string is in Jwt.EncodedToken; alternatively, ToByteArray() returns the same string as UTF-8 bytes.

In the examples, SecureStorage stands in for your protected storage — DPAPI, Keychain, a secret store. The refresh token allows any number of new access tokens to be issued; treat it like a password.

Without this callback, the session does not survive a restart

The SDK rotates the refresh token on every refresh. If you only store the token from the login, it will long since have been invalidated by the next program start — ContinueSession then fails with RpcException, status Unauthenticated, and you need the credentials again.

Register the callback before CreateSession and before ContinueSession: both already rotate on their own, and a callback registered afterwards misses exactly this first rotation.

Login and first call

await client.CreateSession(
    providerId:   int.Parse(Environment.GetEnvironmentVariable("ZEDAL_PROVIDER")),
    subscriberId: "mysubscriber",
    accountId:    "myaccount",
    password:     Environment.GetEnvironmentVariable("ZEDAL_PASSWORD"),
    appToken:     new AppToken(Environment.GetEnvironmentVariable("ZEDAL_APP_TOKEN")));

var inbox = await client.CoreApi.Query.ListInboxDocuments(new QueryParameter
{
    Filter = { new FilterCondition { Path = "removed", Op = Operator.Equal, Operands = { new Variant { B = false } } } },
    PageSize = 50,
});

foreach (var entry in inbox.Entries)
{
    Console.WriteLine($"{entry.Doc.DocumentId.Id} {entry.Doc.DocumentType}");
}

This is the same call as Step 3 in the REST example; QueryParameter, FilterCondition, Operator and Variant are in the namespace Infotech.Zedal.Query.V1. Two details:

  • The easiest way to take incoming entries over is the SDK’s inbox importer, see Importing incoming documents.
  • The SDK renews access tokens automatically as soon as less than five minutes of remaining lifetime are left. You do not need to call RequestAccess yourself.

Besides the variant with separate fields, there is CreateSession(userId, appToken) with the combined pattern <subscriber>-<account>@<provider>:<password>. Processes without a user log in with CreateSession(apiKey, appToken) and an API key. Details in the .NET SDK documentation.

Restart: continue the session

var client = ZedalClientFactory.Default.CreateClient(
    system:        TargetSystem.Test,
    clientName:    "MyIntegrationApp",
    clientVersion: "1.0.0");

// Callback first — ContinueSession already rotates.
client.SetAccessTokenChanged(tokens =>
    SecureStorage.Save("zedal-refresh-token", tokens.refreshToken.Jwt.EncodedToken));

var refreshToken = new RefreshToken(SecureStorage.Load("zedal-refresh-token"));
await client.ContinueSession(refreshToken);

No credential login, no stored passwords. ContinueSession reads the provider_id from the token; you do not need to specify it again.

Logout

await client.EndSession();

Ends the session server-side and renders the refresh token unusable. After that, only a login with credentials is possible — delete the stored token at the same time.

Timeouts

The client’s default timeout is 30 seconds. For calls that are forwarded to DiWaSS on the server side, this is too short; set the time limit per call:

await client.DiwassApi.AttachmentApi.GetAttachment(attachmentIdentifier,
    ZedalCallContext.Default.WithTimeout(600));

ZedalCallContext controls the deadline, CancellationToken and additional headers. WithoutDeadline() disables the time limit entirely — only sensible together with a CancellationToken. A missed deadline comes back as RpcException with StatusCode.DeadlineExceeded and looks like a server error, but is not one. Concrete guideline values per process are in the DiWaSS guides.

Where to go next

  • DiWaSS guides — transboundary shipment of waste: notification, movement documents, authority perspective
  • REST / JSON — call format, header pass-through, streaming limits, code generation
  • Field rules — formats and value ranges that the schema does not express
  • Error codes — what a business rejection means and what to do
  • Code lists — permitted values for controlled fields