You are viewing the documentation for Digipost API Client 3.x, which is not the most recently released version. The newest version is 4.x and can be browsed here.

Introduction

This API makes it possible to access agreements between Digipost users and third parties, and followingly perform certain operations which the user has granted the third party. For instance, the user may permit that certain information may be provided to a third party in order to receive a service. The user may also grant the sender access to documents through an agreement. The agreement governs which documents the sender can access and what operations it can perform.

Download

The library can be acquired from Maven Central Repository, using the dependency management tool of your choice. For Maven you can use the following dependency:

<dependency>
    <groupId>no.digipost</groupId>
    <artifactId>digipost-useragreements-api-client-java</artifactId>
    <version>3.0.0</version>
</dependency>

Prerequisites

The library requires Java Cryptography Extension (JCE) Unlimited Strength Jurisdiction Policy Files for JDK/JRE to be installed: www.oracle.com/technetwork/java/javase/downloads/index.html

Starting from Java 8 build 152 the unlimited strength cryptography policy files are bundled with the JDK/JRE, and may be enabled by setting the security property security.policy to "unlimited". How this is set depends on how you deploy your application, but if done early enough, i.e. before the JCE framework is initialized, it can be set programatically like this:

Security.setProperty("crypto.policy", "unlimited"); // only effective on Java 8 b152 or newer

More details are available in the Java 8u152 Release Notes.

Instantiate and configure client

InputStream key = getClass().getResourceAsStream("certificate.p12");

HttpHost proxy = new HttpHost("proxy.example.com", 8080, "http");

BrokerId brokerId = BrokerId.of(1234L);

DigipostUserAgreementsClient client = new DigipostUserAgreementsClient
		.Builder(brokerId, key, "password")
		.useProxy(proxy) 					//optional
		.setHttpClientBuilder(HttpClientBuilder.create())	//optional
		.serviceEndpoint(URI.create("https://api.digipost.no")) //optional
		.build();

Identify Digipost user

final SenderId senderId = SenderId.of(1234L);
final UserId userId = UserId.of("01017012345");

final IdentificationResult identificationResult = client.identifyUser(senderId, userId);
boolean isDigipost = identificationResult.getResult() == IdentificationResultCode.DIGIPOST;

Messages sent to user

The agreement type FETCH_MESSAGES allows a sender to retrieve metadata for documents that sender has previously sent to the user, that e.g. can be used to present a synthetic inbox to the user. The metadata includes a deep-link the user can use to access the document in Digipost.

Create, read, update and delete agreement

final SenderId senderId = SenderId.of(1234L);
final UserId userId = UserId.of("01017012345");

//CreateAgreement
client.createOrReplaceAgreement(senderId, Agreement.createAgreement(userId, AgreementType.FETCH_MESSAGES));

//GetAgreement
final GetAgreementResult agreement = client.getAgreement(senderId, AgreementType.FETCH_MESSAGES, userId);

//UpdateAgreement
client.createOrReplaceAgreement(senderId, Agreement.createAgreement(userId, AgreementType.FETCH_MESSAGES));

//DeleteAgreement
client.deleteAgreement(senderId, AgreementType.FETCH_MESSAGES, userId);

Get and verify agreement

final SenderId senderId = SenderId.of(1234L);
final UserId userId = UserId.of("01017012345");

final GetAgreementResult agreementResult = client.getAgreement(senderId, AgreementType.FETCH_MESSAGES, userId);
if (agreementResult.isSuccess()) {
	final Agreement agreement = agreementResult.getAgreement();
} else {
	switch (agreementResult.getFailedReason()) {
		case UNKNOWN_USER: //User does not have a Digipost account
		case NO_AGREEMENT: //No agreement exists for user
	}
}

Get documents

final SenderId senderId = SenderId.of(1234L);
final UserId userId = UserId.of("01017012345");

final List<Document> previouslyDeliveredDocs = client.getDocuments(senderId, AgreementType.FETCH_MESSAGES,
	userId, GetDocumentsQuery.empty());

final ZoneId OSLO_ZONE = ZoneId.of("Europe/Oslo");
final List<Document> withinTimeWindow = client.getDocuments(senderId, AgreementType.FETCH_MESSAGES, userId,
	GetDocumentsQuery.builder()
		.deliveryTimeFrom(ZonedDateTime.of(2020, 1, 1, 0, 0, 0, 0, OSLO_ZONE))
		.deliveryTimeTo(ZonedDateTime.now(OSLO_ZONE))
		.build());