<@U04UQ68083H> how do I get relationships in my pr...
# ory-copilot
b
@chilly-king-10285 how do I get relationships in my project in the format
Copy code
group:admins#member@user:john
b
A message from kapa.ai
To create relationships in your Ory project in the format
group:admins#member@user:john
, you can use the Ory CLI. Here's how to do it: ## Creating Relationships You can create relationships using the Ory CLI in several ways: 1. Using echo and pipe:
Copy code
bash    echo "groups:devs#member@tom" \      | ory parse relation-tuples --project <project-id> --workspace <workspace-id> --format=json \      | ory create relation-tuples --project <project-id> --workspace <workspace-id>
[Configure Ory Permissions](https://www.ory.sh/docs/guides/cli/configure-permission-service#manage-relation-tuples) 2. Using a JSON file: Create a JSON file with your relationships and then use the
ory create relationships
command:
Copy code
bash    ory create relationships relationships.json
[Get started with Ory Permissions](https://www.ory.sh/docs/guides/permissions/overview#example) The JSON file should contain your relationships in the proper format. 3. Using the
ory create relationships
command
: This command allows you to create relationships from JSON files. You can either provide a file or use standard input:
Copy code
bash    ory create relationships [flags]
[Ory CLI Reference](https://www.ory.sh/docs/cli/ory-create-relationships#ory-create-relationships) ## Relationship Format The relationship format you're looking for follows this pattern:
Copy code
namespace:object#relation@subject
Where: -
namespace
is the type of object (like "group") -
object
is the specific instance (like "admins") -
relation
is the relationship type (like "member") -
subject
is who has this relationship (like "user:john") ## Viewing Relationships After creating relationships, you can list them to verify they were created correctly:
Copy code
bash ory list relation-tuples --project <project-id> --workspace <workspace-id>
[Configure Ory Permissions](https://www.ory.sh/docs/guides/cli/configure-permission-service#manage-relation-tuples) Remember to replace
<project-id>
and
<workspace-id>
with your actual project and workspace IDs.
b
@chilly-king-10285 I want to GET relationships from my project in this format: group:admins#member@user:john
b
A message from kapa.ai
To retrieve relationships from your Ory project in the format
group:admins#member@user:john
, you can use the Ory API or the Ory CLI. Here's how to do it: ## Using the Ory CLI You can list relationships using the Ory CLI with the following command:
Copy code
bash ory list relation-tuples --project <project-id> --workspace <workspace-id>
[Configure Ory Permissions](https://www.ory.sh/docs/guides/cli/configure-permission-service#manage-relation-tuples) This will return your relationships in a tabular format:
Copy code
NAMESPACE    OBJECT    RELATION NAME    SUBJECT groups       devs      member           tom  NEXT PAGE TOKEN IS LAST PAGE    true
## Using the Ory API You can also retrieve relationships using the Ory API by making a GET request to the
/relation-tuples
endpoint: ### API Endpoint
Copy code
GET /relation-tuples
[Ory API Reference](https://www.ory.sh/docs/reference/api) ### Query Parameters You can filter the relationships by providing these optional parameters: -
namespace
- Namespace of the Relationship -
object
- Object of the Relationship -
relation
- Relation of the Relationship -
subject_id
- SubjectID of the Relationship -
subject_set.namespace
,
subject_set.object
,
subject_set.relation
- For Subject Set filtering -
page_token
- For pagination -
page_size
- Number of results per page ### Example Request
Copy code
GET /relation-tuples?namespace=group&object=admins&relation=member
The API will return a JSON response with the relationships that match your query criteria. ### Authentication To perform this operation, you must be authenticated using an Ory Access Token:
Copy code
Authorization: Bearer <your-access-token>
[Ory API Reference](https://www.ory.sh/docs/reference/api) ## Response Format The API response will be in JSON format, which you may need to parse to get the specific format you want (
group:admins#member@user:john
). The response structure includes:
Copy code
json {   "relation_tuples": [     {       "namespace": "group",       "object": "admins",       "relation": "member",       "subject_id": "user:john"     }   ],   "next_page_token": "" }
You would need to transform this JSON response into your desired string format. Remember to replace
<project-id>
and
<workspace-id>
with your actual project and workspace IDs when using the CLI.