Checks on one instance (document:42) count the roles a user holds on it, directly or through relationships. Your backend keeps that data in sync with these endpoints. Instances are created on first use by a relationship or a role assignment, so most apps never call the instance endpoints directly.
These endpoints take the app key or an M2M token. Reads take the token's read scope, writes take write. Keys can contain dots; URL-encode a /.
Common errors:
| Status | error_code | When |
|---|---|---|
| 404 | unknown_resource | No resource type with that slug |
| 404 | not_found | No such instance, relationship or role |
| 404 | user_not_found | No user with that ID in the app |
| 422 | invalid | A validation failed, or expires_at is not in the future |
Instances#
List instances#
/v1/apps/:app_id/authz/instances/:typeApp key or M2M tokencurl "https://api.scute.io/v1/apps/$SCUTE_APP_ID/authz/instances/document?prefix=4" \ -H "Authorization: Bearer $SCUTE_APP_SECRET"{ "type": "document", "total": 1, "instances": [ { "type": "document", "key": "42", "attributes": { "amount": 1200 } } ]}Create or update an instance#
Creates the instance when it does not exist. attributes replaces the stored attributes, which conditions read as resource.*.
/v1/apps/:app_id/authz/instances/:type/:keyApp key or M2M tokencurl -X PUT https://api.scute.io/v1/apps/$SCUTE_APP_ID/authz/instances/invoice/881 \ -H "Authorization: Bearer $SCUTE_APP_SECRET" \ -H "Content-Type: application/json" \ -d '{ "attributes": { "amount": 1200, "region": "eu" } }'{ "type": "invoice", "key": "881", "attributes": { "amount": 1200, "region": "eu" } }Get an instance#
The instance, its relationships (up to 200) and who holds roles on it (up to 200).
/v1/apps/:app_id/authz/instances/:type/:keyApp key or M2M token{ "type": "document", "key": "42", "attributes": {}, "relationships": [ { "subject": "folder:7", "relation": "parent", "object": "document:42" } ], "roles": [ { "user_id": "0193f900-aaaa-bbbb-cccc-eeeeeeeeeeee", "user": { "id": "0193f900-aaaa-bbbb-cccc-eeeeeeeeeeee", "email": "alice@example.com", "name": "Alice" }, "role": "owner", "resource": "document:42", "expires_at": null, "active": true } ]}Delete an instance#
Its relationships and role assignments are deleted with it.
/v1/apps/:app_id/authz/instances/:type/:keyApp key or M2M tokenReturns 204.
Relationships#
A relationship links two instances through a relation defined on the object's type: folder:7 is the parent of document:42. See relations.
Create a relationship#
Creates missing instances. Idempotent: an existing relationship answers 200 instead of 201.
/v1/apps/:app_id/authz/relationshipsApp key or M2M tokencurl -X POST https://api.scute.io/v1/apps/$SCUTE_APP_ID/authz/relationships \ -H "Authorization: Bearer $SCUTE_APP_SECRET" \ -H "Content-Type: application/json" \ -d '{ "subject": "folder:7", "relation": "parent", "object": "document:42" }'{ "subject": "folder:7", "relation": "parent", "object": "document:42" }| Status | error_code | When |
|---|---|---|
| 422 | invalid | A field is missing, or the subject is not the type the relation expects |
| 422 | unknown_relation | The object's type has no such relation |
Delete a relationship#
/v1/apps/:app_id/authz/relationshipsApp key or M2M tokenTakes subject, relation and object in the body. Returns 204, or 404 not_found.
List relationships#
/v1/apps/:app_id/authz/relationshipsApp key or M2M tokenWithout object or subject, lists every relationship in the app, oldest first.
{ "total": 1, "relationships": [ { "subject": "folder:7", "relation": "parent", "object": "document:42" } ]}Roles on an instance#
Assign a role on an instance#
Creates the instance when it does not exist. Assigning again updates expires_at and answers 200.
/v1/apps/:app_id/authz/instances/:type/:key/rolesApp key or M2M tokencurl -X POST https://api.scute.io/v1/apps/$SCUTE_APP_ID/authz/instances/document/42/roles \ -H "Authorization: Bearer $SCUTE_APP_SECRET" \ -H "Content-Type: application/json" \ -d '{ "user_id": "0193f900-aaaa-bbbb-cccc-eeeeeeeeeeee", "role": "owner" }'{ "user_id": "0193f900-aaaa-bbbb-cccc-eeeeeeeeeeee", "user": { "id": "0193f900-aaaa-bbbb-cccc-eeeeeeeeeeee", "email": "alice@example.com", "name": "Alice" }, "role": "owner", "resource": "document:42", "expires_at": null, "active": true}Revoke a role on an instance#
/v1/apps/:app_id/authz/instances/:type/:key/users/:user_id/roles/:roleApp key or M2M tokenReturns 204, or 404 not_found when the user does not hold the role there.