careful-honey-27437
05/10/2025, 4:15 AMbrief-egg-61061
05/10/2025, 4:15 AMbrief-egg-61061
05/10/2025, 4:15 AMArticle
, object article_abcdefg12345
, relation author
, and subject ID <tel:12345-5678-9087|12345-5678-9087>
. This example demonstrates how to create the relationship using the REST API client. go package main import ( "context" "fmt" "os" ory "<http://github.com/ory/client-go|github.com/ory/client-go>" ) func main() { // Set up the context with your Ory API Key oryAuthedContext := context.WithValue(context.Background(), ory.ContextAccessToken, os.Getenv("ORY_API_KEY")) // Define the relationship details namespace := "Article" object := "article_abcdefg12345" relation := "author" subjectId := "<tel:12345-5678-9087|12345-5678-9087>" // Create the relationship payload payload := ory.CreateRelationshipBody{ Namespace: &namespace, Object: &object, Relation: &relation, SubjectId: &subjectId, } // Configure the Ory API client configuration := ory.NewConfiguration() configuration.Servers = []ory.ServerConfiguration{ { URL: "https://<your-ory-project-url>", // Replace with your Ory project URL }, } client := ory.NewAPIClient(configuration) // Create the relationship _, r, err := client.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 relationship") }
Replace https://<your-ory-project-url>
with your actual Ory project URL and ensure your ORY_API_KEY
environment variable is set. This code is adapted from the official Ory documentation and demonstrates how to grant a permission by creating a relationship tuple using the Go SDK and the Permissions API [Ory Permissions Go SDK](https://www.ory.sh/docs/keto/sdk/go).