careful-honey-27437
06/05/2025, 2:20 AMbrief-egg-61061
06/05/2025, 2:20 AMbrief-egg-61061
06/05/2025, 2:21 AMjs import { IdentityApi, Configuration } from "@ory/client-fetch" const ory = new IdentityApi( new Configuration({ basePath: "https://<your-ory-project-slug>.<http://projects.oryapis.com|projects.oryapis.com>", accessToken: process.env.ORY_API_KEY, }) ) const createIdentityBody = { schema_id: "<preset://basic>", traits: { email: "<mailto:foo@example.com|foo@example.com>", name: { first: "foo", last: "bar", }, }, } async function createIdentity() { try { const { data } = await ory.createIdentity({ createIdentityBody }) console.log("Created identity with ID:", data.id) } catch (error) { console.error("Error creating identity:", error) } } createIdentity()
To use "Magic Link" as the authentication method, you must configure your Ory project to use the magic link strategy for login or verification flows. This is not set per identity, but rather in your project’s configuration (for example, in the Ory Console under Authentication settings). The SDK call for creating an identity does not include an option to specify the authentication method directly for that identity. For more details, see the Go SDK example, which is analogous in structure to the Node.js SDK usage [Ory Identity Management Go SDK](https://www.ory.sh/docs/kratos/sdk/go#identity-api). Summary: - Use the SDK to create an identity as shown above. - Configure "Magic Link" as the authentication method in your Ory project settings, not in the identity creation call. If you need to enable Magic Link authentication, refer to your project’s authentication flow configuration. The knowledge sources do not provide a direct way to set Magic Link per identity at creation time.careful-honey-27437
06/05/2025, 2:40 AMcareful-honey-27437
06/05/2025, 2:40 AMbrief-egg-61061
06/05/2025, 2:41 AMbrief-egg-61061
06/05/2025, 2:41 AMgetIdentity
, require the identity's unique ID, not a trait value like email [Ory API Reference](https://www.ory.sh/docs/reference/api). If you attempt to create an identity with an email that already exists, Ory will return an error message indicating that an account with the same identifier exists. For example, you may receive an error like: json { "id": 4000007, "text": "An account with the same identifier (email, phone, username, ...) exists already.", "type": "error" }
or json { "id": 4000027, "text": "An account with the same identifier (email, phone, username, ...) exists already. Please sign in to your existing account to link your social profile.", "type": "error" }
[UI Error Messages](https://www.ory.sh/docs/kratos/concepts/ui-messages#an-account-with-the-same-identifier-email-phone-username--exists-already-4000007) Summary: - There is no documented way to check for an existing identity by trait (e.g., email) via the SDK or API. - Attempting to create a duplicate identity will result in an error indicating the identity already exists. If you need to avoid this error, you must handle it in your application logic by catching the error response when creating an identity. The knowledge sources do not provide a more direct or efficient method.careful-honey-27437
06/05/2025, 2:51 AMbrief-egg-61061
06/05/2025, 2:51 AMbrief-egg-61061
06/05/2025, 2:51 AMerror
, message
, code
, reason
, and more. These fields are present in the error response body returned by the API [Ory API Reference – Error Response](https://www.ory.sh/docs/reference/api). If you are only seeing { response: {}, name: "ResponseError" }
when logging the error, it suggests that the error object may contain additional information in a property such as response.data
or response.body
, but the knowledge sources do not specify the exact structure for the SDK error object. Summary: - The Ory API returns errors in a standard JSON format with detailed fields. - The knowledge sources do not specify how to access these fields in the client-fetch SDK error object. - If you need to access the error details, you may need to inspect properties like error.response.data
or similar, but this is not confirmed in the documentation. I'm sorry, but the knowledge sources do not contain enough information to provide a definitive answer on how to extract detailed error information from the IndentitiesAPI error object in the client-fetch Node.js SDK.careful-honey-27437
06/05/2025, 10:39 PMbrief-egg-61061
06/05/2025, 10:39 PMbrief-egg-61061
06/05/2025, 10:40 PMgo package main import ( "context" "fmt" "os" ory "<http://github.com/ory/client-go|github.com/ory/client-go>" ) func main() { // Set up authentication context with your Ory API Key oryAuthedContext := context.WithValue(context.Background(), ory.ContextAccessToken, os.Getenv("ORY_API_KEY")) // Define the namespace, object, and relation you want to expand namespace := "files" object := "ec788a82-a12e-45a4-b906-3e69f78c94e4" relation := "access" configuration := ory.NewConfiguration() configuration.Servers = []ory.ServerConfiguration{ { URL: "https://<your-ory-project-slug>.<http://projects.oryapis.com|projects.oryapis.com>", // Replace with your Ory project URL }, } client := ory.NewAPIClient(configuration) // Call the Expand API result, resp, err := client.PermissionApi.ExpandPermissions(oryAuthedContext). Namespace(namespace). Object(object). Relation(relation). Execute() if err != nil { fmt.Fprintf(os.Stderr, "Error calling ExpandPermissions: %v\n", err) fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", resp) return } fmt.Printf("Expand result: %+v\n", result) }
Note: - This example expands the subject set for a specific object and relation (e.g., "who has access to this file?"). - To list all permissions for a specific identity, you would need to query all possible objects and relations and check if the identity is included in the expansion, which is not directly supported by a single API call. For more details and examples, see the [Ory Permissions Go SDK documentation](https://www.ory.sh/docs/keto/sdk/go) and the [Expand API guide](https://www.ory.sh/docs/keto/guides/expand-api-display-who-has-access)[^1]. [^1]: [Expand API: display who has access to an object](https://www.ory.sh/docs/keto/guides/expand-api-display-who-has-access)