<@U04UQ68083H> using the REST API, how to remove o...
# ory-copilot
b
@chilly-king-10285 using the REST API, how to remove organization_id from an identity
b
A message from kapa.ai
To remove an organization_id from an identity in Ory, you can use the PATCH API endpoint for identities. This allows you to update specific fields of an identity using JSON Patch format. You can use the
patchIdentity
endpoint with a "replace" operation to set the organization_id to null:
Copy code
bash curl -X PATCH --location "https://{your-project-slug}.<http://projects.oryapis.com/admin/identities/{identity_id}|projects.oryapis.com/admin/identities/{identity_id}>" \      -H "Authorization: Bearer {your_api_key}" \      -H "Content-Type: application/json" \      -d '[            {              "op": "replace",              "path": "/organization_id",              "value": null            }          ]'
This PATCH operation will set the organization_id field to null, effectively removing the identity's association with any organization. The API endpoint follows the [JSON Patch](https://jsonpatch.com/) standard (RFC 6902), which allows you to perform partial updates on resources. Note that you need to authenticate your request with an API key that has the appropriate permissions to modify identities. [Ory API Reference](https://www.ory.sh/docs/reference/api) provides more details about the patchIdentity endpoint and other identity management operations.
b
@chilly-king-10285 In ory, we have some generic namespaces that can be used across a variety of applications Is it considered "clean" to create our own system for sub-namespacing objects under an application? For example, with this permission model, should we have permissions like <user-id-1> is entitled of Featureapplication1feature1 <user-id-1> is entitled of Featureapplication2feature1 So that each feature is functionally different? class Package implements Namespace { related: { // Users or customers entitled for this package (and all the features it contains) // We can also add a package to another package to enable package "inheritance" entitled: (User | SubjectSet<Customer, "members"> | SubjectSet<Package, "entitled">)[]; }; permits = { entitled: (ctx: Context): boolean => this.related.entitled.includes(ctx.subject), }; } class Feature implements Namespace { related: { // Users, customers, or package subscribers entitled for this Feature entitled: (User | SubjectSet<Customer, "members"> | SubjectSet<Package, "entitled"> | SubjectSet<Application, "users">)[]; // Feature flag is enabled for these users - could be by role in the future enabled: (User | SubjectSet<Customer, "members"> | SubjectSet<Application, "users">)[]; // For now only superadmins can edit features. This will probably change once roles are implemented editors: (SubjectSet<Application, "superadmins">)[]; }; permits = { entitled: (ctx: Context): boolean => this.related.entitled.includes(ctx.subject), enabled: (ctx: Context): boolean => this.related.enabled.includes(ctx.subject), // Feature flag is enabled AND feature is entitled active: (ctx: Context): boolean => this.permits.enabled(ctx) && this.permits.entitled(ctx), edit: (ctx: Context): boolean => this.related.editors.includes(ctx.subject), }; }
b
A message from kapa.ai
Your approach—using a naming convention like
Feature:application1:feature1
and
Feature:application2:feature1
to sub-namespace features under applications—is consistent with Ory’s flexible data model and is considered a "clean" and valid pattern. Ory Permissions (Keto) is designed to be highly adaptable, allowing you to model your objects and namespaces in a way that fits your application's needs. The documentation explicitly states that you can use arbitrary strings as objects, and that namespaces are used to scope objects and subjects. This means you are free to encode application-specific context (like application name or ID) into the object identifier if it helps you organize and manage permissions more effectively. However, Ory recommends using unique identifiers (like UUIDs) for objects and subjects to ensure a single source of truth and to avoid encoding too much application data directly in the object string. Still, for sub-namespacing or distinguishing features across applications, your approach is valid and aligns with Ory’s intended flexibility[Namespaces](https://www.ory.sh/docs/keto/concepts/namespaces), [Subjects](https://www.ory.sh/docs/keto/concepts/subjects). Your permission model using the Ory Permission Language (OPL) is also correct. You can define relationships and permissions as you have shown, and use subject sets to express inheritance and group-based entitlements. The OPL is designed to allow such expressive and hierarchical permission models, and your use of
entitled
,
enabled
, and
edit
permissions is idiomatic[Ory Permission Language Examples](https://www.ory.sh/docs/keto/reference/ory-permission-language#examples). Summary: - Sub-namespacing objects (e.g.,
Feature:application1:feature1
) is a clean and supported approach in Ory. - Ory’s model is intentionally flexible to support such patterns. - Prefer unique, stable identifiers for objects, but encoding application context in object IDs for clarity and separation is acceptable and common. If you want to ensure maximum maintainability and avoid potential issues with string parsing or object renaming, consider using unique IDs and storing application context in your own metadata, but your current approach is fully supported by Ory’s design principles.