Closed tjarkmeyer closed 2 years ago
Hi @tjarkmeyer
You are missing the Servers
key on the struct.
conf := &client.Configuration{
Servers: []client.ServerConfiguration{
{
URL: "<project-url>",
},
},
DefaultHeader: map[string]string{
"Authorization": "Bearer <pat-token>",
},
}
The console also does not use the "default" schema ID. You will need to retrieve all of the schemas first to get the unique ID.
Hello @tjarkmeyer
edit: seems Benehiko was faster 😁
check out this snippet, it should work for Ory Cloud, your example is missing the
Servers: []client.ServerConfiguration{
{
URL: "<project-url>",
},
Also please use the new ory/client-go, we still have to document this and migrate or rather think of a good migration process from the old SDK. I will see to update the SDK snippets in the docs accordingly.
package main
import (
"context"
"fmt"
"github.com/ory/client-go"
)
func main() {
conf := &client.Configuration{
Servers: []client.ServerConfiguration{
{
URL: "<project-url>",
},
},
DefaultHeader: map[string]string{
"Authorization": "Bearer <pat-token>",
},
}
api := client.NewAPIClient(conf)
schemas, _, err := api.V0alpha2Api.ListIdentitySchemas(context.Background()).Execute()
if err != nil {
panic(err)
}
for _, schema := range schemas {
fmt.Printf("SchemaID: %s\n", schema.Id)
fmt.Printf("SchemaName: %s\n", schema.Name)
}
user := client.NewAdminCreateIdentityBody("<really-long-id>", map[string]interface{}{
"email": "a-new-test2-user@example.com",
})
identity, _, err := api.V0alpha2Api.AdminCreateIdentity(context.Background()).AdminCreateIdentityBody(*user).Execute()
if err != nil {
panic(err)
}
fmt.Printf("%v+\n", identity)
}
@Benehiko @vinckr Works now! Thanks!
Preflight checklist
Describe the bug
The following code is simply an example from the docs but it throws the error 'Index 0 out of range -1'. The response is
nil
.Reproducing the bug
Run the code from above.
Relevant log output
No response
Relevant configuration
No response
Version
kratos-client-go v0.10.1
On which operating system are you observing this issue?
Linux
In which environment are you deploying?
Ory Cloud
Additional Context
No response