<@U04UQ68083H> How can i change password of identi...
# ory-copilot
p
@chilly-king-10285 How can i change password of identity via HTTP API(admin) on selfhost kratos?
c
A message from kapa.ai
To change the password of an identity via the HTTP API in a self-hosted Kratos environment, you can use the Identity Management API. However, the exact details or code examples for this operation are not provided in the given extracts. For API clients, Ory Identities responds with a JSON payload which includes the updated identity. Here is an example of how to use the API:
Copy code
bash password=ByS8NWuFSkDgMjbe      actionUrl=$(curl -s -H "Accept: application/json" \    -H "Authorization: bearer $sessionToken" \    '<https://playground.projects.oryapis.com/self-service/settings/api>' | jq -r '.ui.action')      curl -s -X POST -H "Accept: application/json" -H "Content-Type: application/json" \    -H "Authorization: bearer $sessionToken" \    -d '{"password": "'$password'", "method": "password"}' \    "$actionUrl" | jq
In this example,
sessionToken
is the session token for the user whose password you want to change, and
password
is the new password. The
actionUrl
is obtained by making a GET request to the settings API endpoint. Please note that this is a general example and might need to be adjusted based on your specific setup and requirements. For more detailed information, please refer to the [Ory Kratos documentation](https://www.ory.sh/docs/kratos/self-service/flows/user-settings#api-clients-and-clients-without-browsers).
p
@chilly-king-10285 You used flow api, i should use admin http api like /admin/identities/{id}
c
A message from kapa.ai
To update an identity's password using the admin HTTP API, you can use the
PUT /admin/identities/{id}
endpoint. However, the extracts provided do not include specific details on how to update the password field. Here is a general example of how you might use this endpoint:
Copy code
bash curl -X PUT "<https://your-kratos-server.com/admin/identities/{id}>" \ -H "Accept: application/json" \ -H "Content-Type: application/json" \ -d '{     "schema_id": "default",     "traits": {         //... other traits     },     "credentials": {         "password": {             "config": {                 "hashed_password": "new-hashed-password"             }         }     } }'
In this example, replace
{id}
with the ID of the identity you want to update, and
new-hashed-password
with the new hashed password. Please note that Kratos expects the password to be hashed. However, it's important to note that the Kratos documentation recommends updating credentials (including passwords) via the relevant flows (like the settings flow) rather than directly through the admin API. This is because the flows handle things like validation, and ensure that related hooks and strategies are correctly executed. For more detailed information, please refer to the [Ory Kratos documentation](https://www.ory.sh/docs/kratos/).