<@U04UQ68083H> Using the Ory SDK for node.js, show...
# ory-copilot
c
@chilly-king-10285 Using the Ory SDK for node.js, show an example of a function that accepts a
subject-id
and an
object
(string) and creates a new relationship tuple with the relation set to
member
b
A message from kapa.ai
I apologize, but I don't have specific information about creating a relationship tuple using the Ory SDK for Node.js in the provided knowledge sources. The examples and documentation I have are primarily for the Go SDK and REST API. However, I can provide you with some general guidance based on the available information: 1. The structure of a relationship tuple typically includes a namespace, object, relation, and subject (which can be a subject ID or subject set) [Ory API Reference](https://www.ory.sh/docs/reference/api). 2. The relation "member" is commonly used in Ory Permissions, as seen in examples [Creating relationships](https://www.ory.sh/docs/guides/permissions/overview#creating-relationships). 3. To create a relationship, you would typically use an endpoint similar to
PUT /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.
c
Show me the Go SDK
@chilly-king-10285 Show me the Go SDK example
b
A message from kapa.ai
Sure, here is an example of creating a relationship using the Ory Permissions Go SDK:
Copy code
go 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).
c
Does the JS SDK
RelationshipApi
have a
createRelationship
method?
@chilly-king-10285
b
Sorry @careful-honey-27437, I'm not sure what you mean. Please try again. 👋
c
@chilly-king-10285 does the JS SDK
RelationshipApi
have a
createRelationship
method?
b
A message from kapa.ai
Yes, the JavaScript SDK does have a
createRelationship
method under the
RelationshipApi
. This method is used to create a new relationship. Here is an example of how it's used:
Copy code
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).
c
@chilly-king-10285 Show an example of the
createRelationshipBody
method
b
A message from kapa.ai
New message text here