careful-honey-27437
10/25/2024, 3:42 AMsubject-id
and an object
(string) and creates a new relationship tuple with the relation set to member
brief-egg-61061
10/25/2024, 3:42 AMbrief-egg-61061
10/25/2024, 3:42 AMPUT /admin/relation-tuples
[Ory API Reference](https://www.ory.sh/docs/reference/api). To create a function for the Node.js SDK, you would likely need to: 1. Initialize the Ory client with your API key. 2. Use a method similar to createRelationship
or putAdminRelationTuples
. 3. Provide the necessary parameters: namespace, object, relation (in this case, "member"), and subject_id. Unfortunately, without specific Node.js SDK documentation, I can't provide an exact code example. If you need a precise implementation, I recommend checking the official Ory documentation for the Node.js SDK or reaching out to Ory support for more detailed guidance.careful-honey-27437
10/25/2024, 3:43 AMcareful-honey-27437
10/25/2024, 3:43 AMbrief-egg-61061
10/25/2024, 3:43 AMbrief-egg-61061
10/25/2024, 3:43 AMgo package main import ( "context" "fmt" "os" ory "<http://github.com/ory/client-go|github.com/ory/client-go>" ) // Use this context to access Ory APIs which require an Ory API Key. var oryAuthedContext = context.WithValue(context.Background(), ory.ContextAccessToken, os.Getenv("ORY_API_KEY")) var namespace = "Blog" var object = "secret_post" var relation = "view" var subjectId = "Bob" func main() { payload := ory.CreateRelationshipBody{ Namespace: &namespace, Object: &object, Relation: &relation, SubjectId: &subjectId, } configuration := ory.NewConfiguration() configuration.Servers = []ory.ServerConfiguration{ { URL: "<https://practical-swirles-whg26u2ofh.projects.oryapis.com>", // Write API }, } ory := ory.NewAPIClient(configuration) _, r, err := ory.RelationshipApi.CreateRelationship(oryAuthedContext).CreateRelationshipBody(payload).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) panic("Encountered error: " + err.Error()) } fmt.Println("Successfully created tuple") check, r, err := ory.PermissionApi.CheckPermission(oryAuthedContext). Namespace(*&namespace). Object(*&object). Relation(*&relation). SubjectId(*&subjectId).Execute() if err != nil { fmt.Fprintf(os.Stderr, "Full HTTP response: %v\n", r) panic("Encountered error: " + err.Error()) } if check.Allowed { fmt.Println(*&subjectId + " can " + *&relation + " the " + *&object) } }
In this example, a relationship is created where the subject "Bob" can "view" the "secret_post" in the "Blog" namespace. The relationship is then checked to confirm that "Bob" has the "view" permission for the "secret_post" [Ory Permissions Go SDK](https://www.ory.sh/docs/keto/sdk/go#createrelationship-and-checkpermission).careful-honey-27437
10/25/2024, 3:44 AMRelationshipApi
have a createRelationship
method?careful-honey-27437
10/25/2024, 3:45 AMbrief-egg-61061
10/25/2024, 3:45 AMcareful-honey-27437
10/25/2024, 3:45 AMRelationshipApi
have a createRelationship
method?brief-egg-61061
10/25/2024, 3:45 AMbrief-egg-61061
10/25/2024, 3:45 AMcreateRelationship
method under the RelationshipApi
. This method is used to create a new relationship. Here is an example of how it's used: javascript // Create a relationship await ory .relationship .createRelationship({createRelationshipBody: {/* ... */}})
This example is part of the SDK V1 upgrade guide, which shows how to transition from the old createRelationTuple
method to the new createRelationship
method [SDK V1 upgrade guide](https://www.ory.sh/docs/guides/upgrade/sdk-v1#permissions--access-control).careful-honey-27437
10/25/2024, 3:46 AMcreateRelationshipBody
methodbrief-egg-61061
10/25/2024, 3:46 AMbrief-egg-61061
10/25/2024, 3:46 AM