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>4.0.0</version>
</dependency>

Prerequisites

This library now requires Java 11 and above and uses jakarta.xml-bind.

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());