gray-machine-46287
03/06/2025, 8:35 AMmetadata_admin
field to set an object?
JsonPatch{
{
Op: "replace",
Path: "/metadata_admin/signup",
Value: dataMap,
}}
What type should be dataMap
in order to set metadata_admin
as something like
{
"signup": {
"foo": "bar"
}
}
brief-egg-61061
03/06/2025, 8:35 AMbrief-egg-61061
03/06/2025, 8:35 AMmetadata_admin
field using the Ory Kratos Go SDK, you can use the PatchIdentity
method. Based on the provided information and the Ory API documentation, here's how you can achieve this: The dataMap
should be of type map[string]interface{}
to represent the nested JSON structure you want to set for metadata_admin
. Here's an example of how you can use the Go SDK to set the metadata_admin
field: go import ( "context" "fmt" "os" client "<http://github.com/ory/client-go|github.com/ory/client-go>" ) func setMetadataAdmin(identityId string) error { cfg := client.NewConfiguration() cfg.Servers = client.ServerConfigurations{ {URL: fmt.Sprintf("<https://%s.projects.oryapis.com>", os.Getenv("ORY_PROJECT_SLUG"))}, } ory := client.NewAPIClient(cfg) dataMap := map[string]interface{}{ "foo": "bar", } patch := []client.JsonPatch{ { Op: "replace", Path: "/metadata_admin/signup", Value: dataMap, }, } _, _, err := ory.IdentityApi. PatchIdentity(context.Background(), identityId). JsonPatch(patch). Execute() return err }
In this example, dataMap
is of type map[string]interface{}
, which allows you to create a nested structure that will be serialized to JSON when sent to the API. This approach will set the metadata_admin
field to: json { "signup": { "foo": "bar" } }
The PatchIdentity
method uses JSON Patch to update the identity. The "replace" operation will create the signup
key in metadata_admin
if it doesn't exist, or replace its value if it does. Remember to handle errors and set up proper authentication for the API client. [Ory API Reference](https://www.ory.sh/docs/reference/api) provides more details on the PatchIdentity
method and its parameters.