First-factor registration
During initial registration, the client's gender, first name, last name, and e-mail address are requested.
In this case, the HTTP proxy may use a GUEST token.
As a result, the client receives an e-mail with a code that is used for the second registration.
var clientEmail = $"{Guid.NewGuid().ToString().Replace("-", string.Empty)}@gmail.com";
var clientName = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(4, 6);
var clientSurname = Guid.NewGuid().ToString().Replace("-", string.Empty).Substring(1, 7);
var day = new Random().Next(1, 28);
var month = new Random().Next(1, 12);
var year = new Random().Next(1965, 2005);
var clientBirthDate = new DateTime(year, month, day);
var gender = await httpClient.GetFromJsonAsync<GenderOutputModel>("/api/v1/genders/code/MALE");
var payload = JsonConvert.SerializeObject(new { GenderId = gender.Id, Name = clientName, Surname = clientSurname, EmailAddress = clientEmail });
var sContent = new StringContent(payload, Encoding.UTF8, "application/json");
var httpResponseMessage = await httpClient.PostAsync("api/v1/users/registration/first-factor", sContent);
var resultAsString = await httpResponseMessage.Content.ReadAsStringAsync();
var firstFactorRegistrationResult = JsonConvert.DeserializeObject<RegistrationFirstFactorOutputModel>(resultAsString);
Second-factor registration
At this stage, the client enters the code received by e-mail and the mobile phone:
payload = JsonConvert.SerializeObject(new { PhoneNumberPrefix = "0041", PhoneNumberNumber = "767676000" });
sContent = new StringContent(payload, Encoding.UTF8, "application/json");
httpResponseMessage = await httpClient.PostAsync("api/v1/users/registration/second-factor", sContent);
resultAsString = await httpResponseMessage.Content.ReadAsStringAsync();
var secondFactorRegistrationResult = JsonConvert.DeserializeObject<RegistrationSecondFactorOutputModel>(resultAsString);
Third-factor registration
This step completes the registration process. The response contains a CLIENT token that must be used for subsequent HTTP calls:
var language = await httpClient.GetFromJsonAsync<LanguageOutputModel>("/api/v1/languages/code/DE");
var legalAcceptance = await httpClient.GetFromJsonAsync<LegalAcceptanceOutputModel>("/api/v1/legal-acceptances/active");
payload = JsonConvert.SerializeObject(new
{
ManagementPersonalDataConsent = DateTime.Now,
SmsToken = secondFactorRegistrationResult.Token,
EmailToken = firstFactorRegistrationResult.Token,
GenderId = gender.Id,
Name = clientName,
Surname = clientSurname,
EmailAddress = clientEmail,
PhoneNumberPrefix = "0041",
PhoneNumberNumber = "767676000",
Password = "Ast@LaVist@!",
LanguageId = language.Id,
LegalAcceptanceId = legalAcceptance.Id,
});
sContent = new StringContent(payload, Encoding.UTF8, "application/json");
httpResponseMessage = await httpClient.PostAsync("api/v1/users/registration/third-factor", sContent);
resultAsString = await httpResponseMessage.Content.ReadAsStringAsync();
var thirdFactorRegistrationResult = JsonConvert.DeserializeObject<RegistrationThirdFactorOutputModel>(resultAsString);
Note
The CLIENT token is valid for 60 minutes/one hour.
Once this period has expired, a new CLIENT token can be obtained by following the refreshing token procedure.
Single call
The following example shows how to register a client and all its data in a single call. In this case, the HTTP proxy must use an ADMIN token.
var language = await httpClient.GetFromJsonAsync<LanguageOutputModel>("/api/v1/languages/code/DE");
var legalAcceptance = await httpClient.GetFromJsonAsync<LegalAcceptanceOutputModel>("/api/v1/legal-acceptances/active");
var nationality = await httpClient.GetFromJsonAsync<NationalityOutputModel>("api/v1/nationalities/code/CH");
var country = await httpClient.GetFromJsonAsync<CountryOutputModel>("api/v1/countries/code/CH");
var pensionSituation = await httpClient.GetFromJsonAsync<PensionSituationOutputModel>("api/v1/pension-situations/code/PENSION-FUND");
var taxLiability = await httpClient.GetFromJsonAsync<TaxLiabilityOutputModel>("api/v1/tax-liabilities/code/CH");
var civilStatus = await httpClient.GetFromJsonAsync<CivilStatusOutputModel>("api/v1/civil-statuses/code/SINGLE");
var gender = await httpClient.GetFromJsonAsync<GenderOutputModel>("/api/v1/genders/code/MALE");
var payload = JsonConvert.SerializeObject(new
{
ManagementPersonalDataConsent = DateTime.Now,
Name = clientName,
Surname = clientSurname,
Email = clientEmail,
PhoneNumberPrefix = "0041",
PhoneNumberNumber = "767965365",
PensionSituationId = pensionSituation.Id,
LanguageId = language.Id,
LegalAcceptanceId = legalAcceptance.Id,
Address = new
{
City = "Baar",
Zip = "6340",
Street = "Neugasse",
StreetNr = "28A",
CountryId = country.Id,
CoName = "Zoo",
CoSurname = "Zurich"
},
GenderId = gender.Id,
Nationality1Id = nationality.Id,
BirthDate = DateTime.Now.AddYears(-23)
});
var httpResponseMessage = await httpClient.PostAsync("api/v1/users", new StringContent(payload, Encoding.UTF8, "application/json"));
var userId = UriHelper.GetIdFromLocationUri(httpResponseMessage.Headers.Location);