Creating permissions

In this section we'll cover how to make an API call to add permissions to a resource.

Before you start you must have a user account on Morta, and you must have owner level access to a project.

Adding a user as an owner of a process

To add a user as an owner, you'll need to know the publicId of the user, and the publicId of the resource.

In the JSON request below the attributeId maps to the user's publicId, and the resourceId maps to the process's publicId

import requests

OWNER_ROLE = 4

headers = {
  "Authorization": "Bearer YourToken"
}
payload = {
  "attributeKind": "user",
  "attributeId": "xxxxxx-xxxxx-xxxxx-xxxxx",
  "resourceId": "4e687ada-900a-4562-b493-6c6f67ffca6e",
  "resourceKind": "process",
  "role": OWNER_ROLE
}

response = requests.post("https://api.morta.io/v1/permissions", json=payload, headers=headers)

if response.ok:
  # do something here

Allowing anyone with a specific tag to access a resource

Granting a tag access to a resoruce works slightly different than when working with users and projects.

As tags are infact references to a cell in a table, we use tagReferenceId instead of attributeId when making the create permission request

To use tags you must have a table with a tag column type in your project, and that column must have at least one value

import requests

VIEWER_ROLE = 0

headers = {
  "Authorization": "Bearer YourToken"
}
payload = {
  "attributeKind": "tag",
  "tagReferenceId": "table/9b634c18-8c13-4644-82e4-dcf149474a6c/83ccdb2a-82e0-4c1f-aabc-9817183add5b/42943c17-c869-499f-ab81-e296a70fc9d8",
  "resourceId": "4e687ada-900a-4562-b493-6c6f67ffca6e",
  "resourceKind": "process",
  "role": VIEWER_ROLE
}

response = requests.post("https://api.morta.io/v1/permissions", json=payload, headers=headers)

if response.ok:
  # do something here