<@U04UQ68083H> ory kratos, when i use api to edit ...
# ory-copilot
s
@chilly-king-10285 ory kratos, when i use api to edit identites profile i get error
Copy code
Property username is missing.
i am using this api to update
Copy code
curl --request POST \
  --url '<https://oathkeeper.md-dev.vnsilicon.cloud/proxy/kratos/self-service/settings?flow=89f04514-c254-45dd-91d3-d6560e8d90b7>' \
  --header 'accept: application/json' \
  --header 'content-type: application/json' \
  --header 'cookie: {{oryKratosSession}};{{settingFlowCookie}}' \
  --cookie '{{oryKratosSession}};{{settingFlowCookie}}' \
  --data '// {
//   "csrf_token": "{{settingFlowCsrf}}",
//   "method": "profile",
//   "traits": {
//     "email": "<mailto:new-email@example.com|new-email@example.com>",
//     "username": "VNSuser001"
//   }
// }

{
  "csrf_token": "{{settingFlowCsrf}}",
  "method": "profile",
  "traits": {
    "email": "<mailto:new-email@example.com|new-email@example.com>"
  }
}'
why did it need username to update? i do not want to update username, i just want to update email
b
A message from kapa.ai
The error
Property username is missing.
occurs because your identity schema likely requires the
username
field to be present in the traits, not just when creating but also when updating the profile. In Ory Kratos, the identity schema defines which fields are required for an identity. If
username
is marked as required in your schema, then every update to the profile (even if you only want to change the email) must include the
username
field in the payload, otherwise Kratos will reject the request with this error. For example, a schema like this:
Copy code
json {   "properties": {     "traits": {       "type": "object",       "properties": {         "email": { "type": "string", "format": "email" },         "username": { "type": "string" }       },       "required": ["email", "username"],       "additionalProperties": false     }   } }
means both
email
and
username
are required. When you update, you must send both fields, even if you only want to change one of them. This is standard JSON Schema behavior and is enforced by Kratos during profile updates [Customize identity schemas: Examples](https://www.ory.sh/docs/kratos/manage-identities/customize-identity-schema#username-and-email-and-password). Solution: When updating the profile, always include all required fields from your identity schema in the
traits
object. For your case, the payload should look like:
Copy code
json {   "csrf_token": "{{settingFlowCsrf}}",   "method": "profile",   "traits": {     "email": "<mailto:new-email@example.com|new-email@example.com>",     "username": "VNSuser001"   } }
If you do not want
username
to be required, you need to update your identity schema and remove
username
from the
required
array. Otherwise, you must always provide it in update requests [Customize identity schemas: Multiple identifiers](https://www.ory.sh/docs/kratos/manage-identities/customize-identity-schema#multiple-identifiers). Summary: Kratos enforces the identity schema on every update. All required fields must be present in the update payload, even if you are not changing them [Settings and profile updates](https://www.ory.sh/docs/kratos/self-service/flows/user-settings#settings-form-validation).
s
@chilly-king-10285 if i remove username from required, when create a new identity, it will not required username, is it right?
b
A message from kapa.ai
Yes, that's correct. If you remove username from the required array in your identity schema, then Ory Kratos will not require the username field when creating a new identity. Only the fields listed in the required array are mandatory during registration or identity creation. If username is not required, users can register without providing it [Mandatory fields for registration](https://www.ory.sh/docs/kratos/manage-identities/customize-identity-schema#mandatory-fields-for-registration).