Creating Relations
After you've defined your schema and implemented it in Descope, you can start creating relations between resources and targets. Relations are the actual data that represents who has access to what resources in your authorization model.
Prerequisites
Before creating relations, make sure you have:
- Defined your FGA schema with relation definitions
- Implemented your schema
- Installed and initialized the Descope Management SDK (see setup below)
Data Types
When working with relations, you'll use the following data types:
FGARelation
The FGARelation type defines a relation between a resource and a target:
CheckResponseRelation
When checking relations (covered in Checking Relations), the response includes:
Creating Relations
You can create relations either through the Descope Console or programmatically using the SDKs.
Using the Console
You can create relations directly in the Descope Console:
- Navigate to Authorization > FGA > Relations
- Click Create Relation
- Fill in the relation details:
- Resource Type: The type of resource (e.g.,
Group,File,Folder) - Resource Name: The identifier for the specific resource (e.g.,
engineering-team,project-plan.pdf) - Relation: The relation name from your schema (e.g.,
member,owner,viewer) - Target Type: The type of target (e.g.,
user) - Target: The target identifier, usually a user ID (e.g.,
U2abc123def456)
- Resource Type: The type of resource (e.g.,
Here's an example of creating a relation for a user as a member of a group:
![]()
Using the SDK
Use createRelations to create one or more relations programmatically. This function accepts an array of FGARelation objects and creates them all in a single operation.
Install SDK
Initialize Management SDK
Initialize the Descope Management SDK with your project ID and management key. The management key must have FGA read/write permissions.
Create Relations Programmatically
Deleting Relations
Delete Specific Relations
Use deleteRelations to remove specific relations. This function accepts an array of FGARelation objects and deletes all matching relations.
Delete All Relations
Currently, this function is only available in the Node.js SDK.
Use deleteAllRelations to delete all relations in your project. Warning: This is a destructive operation that cannot be undone.
Resource Details
Resource details allow you to store additional metadata about resources that can be used for filtering, display, or other purposes. This is optional metadata that doesn't affect authorization decisions but can be useful for building user interfaces or generating reports.
Load Resource Details
Use loadResourcesDetails to retrieve metadata for one or more resources.
Save Resource Details
Use saveResourcesDetails to store or update metadata for resources. This metadata can include display names, descriptions, and custom metadata fields.
Next Steps
After creating relations, you can:
- Check relations to verify access permissions
- Use the relations in your application logic to enforce authorization