API reference

Objects and relationships

Sync your app's objects, how they relate, and the roles users hold on single objects.

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:

Statuserror_codeWhen
404unknown_resourceNo resource type with that slug
404not_foundNo such instance, relationship or role
404user_not_foundNo user with that ID in the app
422invalidA validation failed, or expires_at is not in the future

Instances#

List instances#

GET/v1/apps/:app_id/authz/instances/:typeApp key or M2M token
typestring
Path. The resource type. Leave it out (/authz/instances) to list every type, by type then key, or pass it as the type query parameter.
prefixstring
Query. Keys starting with this.
qstring
Query. Keys containing this, any case.
limitinteger
Query. Default 100, at most 200.
offsetinteger
Query. Default 0.
Requestbash
curl "https://api.scute.io/v1/apps/$SCUTE_APP_ID/authz/instances/document?prefix=4" \  -H "Authorization: Bearer $SCUTE_APP_SECRET"
Response 200json
{  "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.*.

PUT/v1/apps/:app_id/authz/instances/:type/:keyApp key or M2M token
attributesobject
Up to 16 KB as JSON.
Requestbash
curl -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" } }'
Response 200json
{ "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).

GET/v1/apps/:app_id/authz/instances/:type/:keyApp key or M2M token
Response 200json
{  "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.

DELETE/v1/apps/:app_id/authz/instances/:type/:keyApp key or M2M token

Returns 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.

POST/v1/apps/:app_id/authz/relationshipsApp key or M2M token
subjectstring or objectrequired
The instance at the other end, type:key or an object with type and key.
relationstringrequired
A relation of the object's type.
objectstring or objectrequired
The instance the relation belongs to.
Requestbash
curl -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" }'
Response 201json
{ "subject": "folder:7", "relation": "parent", "object": "document:42" }
Statuserror_codeWhen
422invalidA field is missing, or the subject is not the type the relation expects
422unknown_relationThe object's type has no such relation

Delete a relationship#

DELETE/v1/apps/:app_id/authz/relationshipsApp key or M2M token

Takes subject, relation and object in the body. Returns 204, or 404 not_found.

List relationships#

GET/v1/apps/:app_id/authz/relationshipsApp key or M2M token
objectstring
Query. type:key.
subjectstring
Query. type:key.
relationstring
Query. A relation slug.
limitinteger
Query. Default 100, at most 200.
offsetinteger
Query. Default 0.

Without object or subject, lists every relationship in the app, oldest first.

Response 200json
{  "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.

POST/v1/apps/:app_id/authz/instances/:type/:key/rolesApp key or M2M token
user_idstringrequired
The user's ID in the app.
rolestringrequired
A resource role of this type, like owner.
expires_atstring
ISO 8601 time in the future. Without it the role does not expire.
Requestbash
curl -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" }'
Response 201json
{  "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#

DELETE/v1/apps/:app_id/authz/instances/:type/:key/users/:user_id/roles/:roleApp key or M2M token

Returns 204, or 404 not_found when the user does not hold the role there.