<@U04UQ68083H> how do I update the `metadata_publi...
# ory-copilot
g
@chilly-king-10285 how do I update the
metadata_public
field using the admin api?
b
A message from kapa.ai
To update the
metadata_public
field of an identity, you can use the
PUT /admin/identities/{id}
endpoint of the Ory Admin API. This endpoint allows you to update an identity's data, including its metadata. Here is an example of how you might structure your request body:
Copy code
json {   "identity": {     "metadata_public": {       "key1": "value1",       "key2": "value2"     }   } }
Please note that this method replaces the entire metadata object. You can't update only a single value in
metadata_public
. For more information, you can refer to the [Ory API Reference](https://www.ory.sh/docs/reference/api#operation/updateIdentity) and the [Ory Kratos Identity Metadata & Traits Guide](https://www.ory.sh/docs/kratos/manage-identities/managing-users-identities-metadata).
g
@chilly-king-10285 But how to do it using the Go client?
b
A message from kapa.ai
To update the
metadata_public
field of an identity using the Go client, you would use the
UpdateIdentity
function provided by the Ory Client Go SDK. However, the exact method to update the
metadata_public
field is not explicitly mentioned in the provided knowledge sources. Here is a general example of how you might use the
UpdateIdentity
function:
Copy code
go package main  import (  "context"  "fmt"  "os"   "<http://github.com/ory/client-go/client|github.com/ory/client-go/client>"  "<http://github.com/ory/client-go/models|github.com/ory/client-go/models>" )  func main() {  cfg := client.NewConfiguration()  cfg.Servers = client.ServerConfigurations{   {URL: fmt.Sprintf("<https://%s.projects.oryapis.com>", os.Getenv("ORY_PROJECT_SLUG"))},  }   oryClient := client.NewAPIClient(cfg)  authed := context.WithValue(context.Background(), client.ContextAccessToken, os.Getenv("ORY_API_KEY"))   identity, _, err := oryClient.IdentityApi.GetIdentity(authed, "identity-id").Execute()  if err != nil {   panic(err)  }   identity.MetadataPublic = models.IdentityMetadataPublic(map[string]interface{}{   "key1": "value1",   "key2": "value2",  })   updatedIdentity, _, err := oryClient.IdentityApi.UpdateIdentity(authed, "identity-id").Identity(identity).Execute()  if err != nil {   panic(err)  }   fmt.Printf("Updated identity: %+v\n", updatedIdentity) }
Please replace
"identity-id"
with the actual ID of the identity you want to update, and replace
"key1"
and
"key2"
with the actual keys you want to update in the
metadata_public
field. Please note that this is a general example and might need adjustments based on your specific use case. For more information, you can refer to the [Ory Client Go SDK Documentation](https://www.ory.sh/docs/kratos/sdk/go).