// clientEmail, clientName and clientSurname are entered by the client.
HttpRequest languageRequest = HttpRequest.newBuilder()
.timeout(Duration.ofMinutes(1))
.uri(Settings.wmsUri("languages/code/DE"))
.header("Accept-Language", "de-DE")
.header("Authorization", "Bearer " + Settings.GUEST_TOKEN)
.header("Content-Type", "application/json")
.build();
var response = httpClient.send(languageRequest, BodyHandlers.ofString());
Api.requireSuccess(response);
LanguageOutputModel languageObj = new Gson().fromJson(response.body(), LanguageOutputModel.class);
var languageId = languageObj.Id;
HttpRequest legalAcceptanceRequest = HttpRequest.newBuilder()
.timeout(Duration.ofMinutes(1))
.uri(Settings.wmsUri("legal-acceptances/active"))
.header("Accept-Language", "de-DE")
.header("Authorization", "Bearer " + Settings.GUEST_TOKEN)
.header("Content-Type", "application/json")
.build();
response = httpClient.send(legalAcceptanceRequest, BodyHandlers.ofString());
Api.requireSuccess(response);
LegalAcceptanceOutputModel legalAcceptanceObj = new Gson().fromJson(response.body(), LegalAcceptanceOutputModel.class);
var legalAcceptanceId = legalAcceptanceObj.Id;
HttpRequest nationalityRequest = HttpRequest.newBuilder()
.timeout(Duration.ofMinutes(1))
.uri(Settings.wmsUri("nationalities/code/CH"))
.header("Accept-Language", "de-DE")
.header("Authorization", "Bearer " + Settings.GUEST_TOKEN)
.header("Content-Type", "application/json")
.build();
response = httpClient.send(nationalityRequest, BodyHandlers.ofString());
Api.requireSuccess(response);
NationalityOutputModel nationalityObj = new Gson().fromJson(response.body(), NationalityOutputModel.class);
var nationalityId = nationalityObj.Id;
HttpRequest countryRequest = HttpRequest.newBuilder()
.timeout(Duration.ofMinutes(1))
.uri(Settings.wmsUri("countries/code/CH"))
.header("Accept-Language", "de-DE")
.header("Authorization", "Bearer " + Settings.GUEST_TOKEN)
.header("Content-Type", "application/json")
.build();
response = httpClient.send(countryRequest, BodyHandlers.ofString());
Api.requireSuccess(response);
CountryOutputModel countryObj = new Gson().fromJson(response.body(), CountryOutputModel.class);
var countryId = countryObj.Id;
HttpRequest pensionRequest = HttpRequest.newBuilder()
.timeout(Duration.ofMinutes(1))
.uri(Settings.wmsUri("pension-situations/code/PENSION-FUND"))
.header("Accept-Language", "de-DE")
.header("Authorization", "Bearer " + Settings.GUEST_TOKEN)
.header("Content-Type", "application/json")
.build();
response = httpClient.send(pensionRequest, BodyHandlers.ofString());
Api.requireSuccess(response);
PensionSituationOutputModel pensionObj = new Gson().fromJson(response.body(), PensionSituationOutputModel.class);
var pensionId = pensionObj.Id;
HttpRequest taxLiabilityRequest = HttpRequest.newBuilder()
.timeout(Duration.ofMinutes(1))
.uri(Settings.wmsUri("tax-liabilities/code/CH"))
.header("Accept-Language", "de-DE")
.header("Authorization", "Bearer " + Settings.GUEST_TOKEN)
.header("Content-Type", "application/json")
.build();
response = httpClient.send(taxLiabilityRequest, BodyHandlers.ofString());
Api.requireSuccess(response);
TaxLiabilityOutputModel taxLiabilityObj = new Gson().fromJson(response.body(), TaxLiabilityOutputModel.class);
var taxLiabilityId = taxLiabilityObj.Id;
HttpRequest civilStatusRequest = HttpRequest.newBuilder()
.timeout(Duration.ofMinutes(1))
.uri(Settings.wmsUri("civil-statuses/code/SINGLE"))
.header("Accept-Language", "de-DE")
.header("Authorization", "Bearer " + Settings.GUEST_TOKEN)
.header("Content-Type", "application/json")
.build();
response = httpClient.send(civilStatusRequest, BodyHandlers.ofString());
Api.requireSuccess(response);
CivilStatusOutputModel civilStatusObj = new Gson().fromJson(response.body(), CivilStatusOutputModel.class);
var civilStatusId = civilStatusObj.Id;
HttpRequest genderRequest = HttpRequest.newBuilder()
.timeout(Duration.ofMinutes(1))
.uri(Settings.wmsUri("genders/code/MALE"))
.header("Accept-Language", "de-DE")
.header("Authorization", "Bearer " + Settings.GUEST_TOKEN)
.header("Content-Type", "application/json")
.build();
response = httpClient.send(genderRequest, BodyHandlers.ofString());
Api.requireSuccess(response);
GenderOutputModel genderObj = new Gson().fromJson(response.body(), GenderOutputModel.class);
var genderId = genderObj.Id;
// Preparing payload
JsonObject registrationPayload = new JsonObject();
registrationPayload.addProperty("ManagementPersonalDataConsent", consentTimestamp);
registrationPayload.addProperty("CivilStatusId", civilStatusId);
registrationPayload.addProperty("Name", clientName);
registrationPayload.addProperty("Surname", clientSurname);
registrationPayload.addProperty("Email", clientEmail);
registrationPayload.addProperty("PhoneNumberPrefix", phoneNumberPrefix);
registrationPayload.addProperty("PhoneNumberNumber", phoneNumberNumber);
registrationPayload.addProperty("PensionSituationId", pensionId);
registrationPayload.addProperty("LanguageId", languageId);
registrationPayload.addProperty("LegalAcceptanceId", legalAcceptanceId);
registrationPayload.addProperty("GenderId", genderId);
registrationPayload.addProperty("BirthDate", clientBirthDate);
registrationPayload.addProperty("Nationality1Id", nationalityId);
registrationPayload.addProperty("TaxLiabilityId", taxLiabilityId);
JsonObject address = new JsonObject();
address.addProperty("City", "Baar");
address.addProperty("Zip", "6340");
address.addProperty("Street", "Neugasse");
address.addProperty("StreetNr", "1");
address.addProperty("CountryId", countryId);
registrationPayload.add("Address", address);
HttpRequest createRequest = HttpRequest.newBuilder()
.timeout(Duration.ofMinutes(1))
.uri(Settings.wmsUri("users"))
.header("Accept-Language", "de-DE")
.header("Authorization", "Bearer " + Settings.ADMIN_TOKEN)
.header("Content-Type", "application/json")
.POST(HttpRequest.BodyPublishers.ofString(registrationPayload.toString()))
.build();
response = httpClient.send(createRequest, BodyHandlers.ofString());
Api.requireSuccess(response);
ClientOutputModel clientObj = new Gson().fromJson(response.body(), ClientOutputModel.class);
var userId = clientObj.Id;
// Continue using the existing administrative access token.
var accessToken = Settings.ADMIN_TOKEN;