The Management API uses a tri-state logic for PATCH requests to distinguish between three states: a value is provided, a value is explicitly set to null (to clear the field), or a value is not provided at all (to leave the field unchanged).
To achieve this, request models use the Optional<T> wrapper.
- To update a field: Assign the desired value to the
Optional<T> property. - To clear a field (set to null on server): Use
Optional<T>.Of(null). - To leave a field unchanged: Do not assign any value to the property (it remains
Optional<T>.Undefined).
Warning: Do not assign a raw null to an Optional<T> field, as this creates ambiguous intent and can lead to clobbering server data.
// ✅ Good: Only sending what you mean
var request = new UpdateUserRequestContent
{
Name = "John Doe" // sent
// Email left as Optional<string?>.Undefined — not sent
};
var clear = new UpdateUserRequestContent
{
Nickname = Optional<string?>.Of(null) // sent as null → clears the field
};
// ❌ Bad: Ambiguous intent or incorrect clearing
var request = new UpdateUserRequestContent
{
Name = "John Doe",
Email = null, // Ambiguous; don't assign raw null to an Optional<T> field
Nickname = "" // Empty string is not the same as "clear"
};