Skip to main content
This is an introduction to adding and deleting relationship tuples.

Before you start

  1. You have obtained FGA API credentials and set FGA_API_URL, FGA_STORE_ID, FGA_API_TOKEN_ISSUER, FGA_API_AUDIENCE, FGA_CLIENT_ID, and FGA_CLIENT_SECRET.
  2. You have installed the SDK.
  3. You have configured the authorization model.
  4. You have loaded FGA_API_URL, FGA_STORE_ID, FGA_API_TOKEN_ISSUER, FGA_API_AUDIENCE, FGA_CLIENT_ID and FGA_CLIENT_SECRET as environment variables.

Step by step

Assume that you want to add user user:anne to have relationship reader with object document:Z

01. Configure the Auth0 FGA API client

Before calling the write API, you will need to configure the API client.

02. Calling write API to add new relationship tuples

To add the relationship tuples, we can invoke the write API.

03. Calling write API to delete relationship tuples

To delete relationship tuples, we can invoke the write API. Assume that you want to delete user user:anne’s reader relationship with object document:Z

04. Writing and deleting relationship tuples in the same request

You can combine both writes and deletes in a single transactional API request. This is useful when you need to update multiple relationships atomically. All operations in the request will either succeed together or fail together. The Write API allows you to send up to 100 unique tuples in the request. (This limit applies to the sum of both writes and deletes in that request). For example, you might want to remove user:anne as a writer of document:Z while simultaneously updating user:anne as an reader of document:Z: This approach ensures that both operations succeed or fail together, maintaining transactional data consistency.
When using the Write API, you cannot include the same tuple (same user, relation, and object) in the writes or deletes arrays within a single request. The API will return an error with code cannot_allow_duplicate_tuples_in_one_request if detected.

05. Ignoring duplicate or missing tuples

Sometimes you might need to write a tuple that already exists, which would normally cause the whole request to fail. You can use the on_duplicate: "ignore" parameter to handle this gracefully. This is particularly useful for high-volume data imports, migrations, or ensuring certain permissions exist without complex error handling logic. For example, if you want to ensure user:anne has reader access to document:Z without worrying about whether the relationship already exists in Auth0 FGA: Similarly, you can use on_missing: "ignore" when deleting tuples that might not exist. The behavior of on_duplicate: "ignore" is more nuanced for tuples with conditions.
  • Identical Tuples: If a tuple in the request is identical to an existing tuple (same user, relation, object, condition name, and condition context), it will be safely ignored.
  • Conflicting Tuples: If a tuple key (user, relation, object) matches an existing tuple, but the condition name or parameters are different, this is a conflict. The write attempt will be rejected, and the entire transaction will fail with a 409 Conflict error.