Client Data Changes
There are several API endpoints for updating client data. In this section, we will look at only the most commonly used ones.
For the others, please see the /api/v1/users endpoint.
Attention
When updating client data, if you pass a NULL value, the previous value will be replaced with NULL.
Changing all
The following example shows how to change the client data:
// Assuming this is our client ID
var userId = 226;
var clientUpdateInputModel = new
{
Name = name,
Surname = surname,
Email = email,
PhoneNumberPrefix = phoneNumberPrefix,
PhoneNumberNumber = phoneNumberNumber,
BirthDate = birthDate,
GenderId = genderId,
LanguageId = languageId,
Nationality1Id = nationalityId,
DeliverTaxStatement = deliverTaxStatement,
PensionSituationId = pensionSituationId
};
var clientUpdateInputModelAsString = JsonConvert.SerializeObject(clientUpdateInputModel);
_ = await httpClient.PutAsync($"api/v1/users/user-id/{userId}", new StringContent(clientUpdateInputModelAsString, Encoding.UTF8, "application/json"));
// Assuming this is our client ID
var userId = 226;
StringBuilder clientChangeDataPayload = new StringBuilder("{");
clientChangeDataPayload.append("'Name': '" + name + "',");
clientChangeDataPayload.append("'Surname': '" + surname + "',");
clientChangeDataPayload.append("'PhoneNumberPrefix': '0041',");
clientChangeDataPayload.append("'PhoneNumberNumber': '767965367',");
clientChangeDataPayload.append("'BirthDate': '2001-12-25',");
clientChangeDataPayload.append("'GenderId': " + genderId + ",");
clientChangeDataPayload.append("'LanguageId': " + languageId + ",");
clientChangeDataPayload.append("'Nationality1Id': " + nationalityId + ",");
clientChangeDataPayload.append("'DeliverTaxStatement': true,");
clientChangeDataPayload.append("'PensionSituationId': " + pensionSituationId);
clientChangeDataPayload.append("}");
HttpRequest clientDataChangeRequest = HttpRequest.newBuilder()
.timeout(Duration.ofMinutes(1))
.uri(URI.create(Settings.BASE_WMS_URL + "users/user-id/" + userId))
.header("Accept-Language", "de-DE")
.header("Authorization", "Bearer " + Settings.ADMIN_TOKEN) // or CLIENT ACCESS TOKEN
.header("Content-Type", "application/json")
.PUT(HttpRequest.BodyPublishers.ofString(clientChangeDataPayload.toString()))
.build();
var response = httpClient.send(clientDataChangeRequest, BodyHandlers.ofString());
if (response.statusCode() != 200 && response.statusCode() != 201) {
System.out.println(response.body());
throw new Exception("Update client data ==> response.statusCode() = " + response.statusCode());
}
Changing address
The following example shows how to change the client’s address:
var userAddressInputModel = new
{
Street = street,
StreetNr = streetNr,
City = city,
CountryId = countryId,
Zip = zip
};
var userId = 226;
var userAddressInputModelAsString = JsonConvert.SerializeObject(userAddressInputModel);
_ = httpClient.PutAsync($"api/v1/users/update-address/user-id/{userId}", new StringContent(userAddressInputModelAsString, Encoding.UTF8, "application/json")).Result;
HttpRequest countryRequest = HttpRequest.newBuilder()
.timeout(Duration.ofMinutes(1))
.uri(URI.create(Settings.BASE_WMS_URL + "countries/code/FR"))
.header("Accept-Language", "de-DE")
.header("Authorization", "Bearer " + Settings.GUEST_TOKEN) // or CLIENT/ADMIN ACCESS TOKEN
.header("Content-Type", "application/json")
.build();
var response = httpClient.send(countryRequest, BodyHandlers.ofString());
CountryOutputModel countryObj = new Gson().fromJson(response.body().toString(), CountryOutputModel.class);
var newCountryId = countryObj.Id;
// Assuming this is our client ID
var userId = 226;
StringBuilder newAddressPayload = new StringBuilder("{");
newAddressPayload.append("'Street': 'Nowhere',");
newAddressPayload.append("'StreetNr': '1',");
newAddressPayload.append("'City': 'Elsewhere',");
newAddressPayload.append("'CountryId': " + newCountryId + ",");
newAddressPayload.append("'Zip': '6000'");
newAddressPayload.append("}");
HttpRequest theRequest = HttpRequest.newBuilder()
.timeout(Duration.ofMinutes(1))
.uri(URI.create(Settings.BASE_WMS_URL + "update-address/user-id/" + userId))
.header("Accept-Language", "de-DE")
.header("Authorization", "Bearer " + Settings.ADMIN_TOKEN) // or CLIENT ACCESS TOKEN
.header("Content-Type", "application/json")
.PUT(HttpRequest.BodyPublishers.ofString(newAddressPayload.toString()))
.build();
response = httpClient.send(theRequest, BodyHandlers.ofString());