<@U04UQ68083H> how to use the Go SDK to set the `m...
# ory-copilot
g
@chilly-king-10285 how to use the Go SDK to set the
metadata_admin
field to set an object?
Copy code
JsonPatch{
		{
			Op:    "replace",
			Path:  "/metadata_admin/signup",
			Value: dataMap,
		}}
What type should be
dataMap
in order to set
metadata_admin
as something like
Copy code
{
  "signup": {
    "foo": "bar"
  }
}
b
A message from kapa.ai
To set the
metadata_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:
Copy code
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:
Copy code
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.