Skip to content

Create Resource

Create a new resource domain and define its permissions in a single request.

Endpoint

/api/v1/projects/{project_id}/resources

Method

POST

Path Parameters

ParameterTypeRequiredDescription
project_idstringYesUnique ID of the project

Headers

HeaderRequiredDescription
Content-TypeYesapplication/json
AuthorizationYesBearer access token: Bearer <access_token>

Request Body

FieldTypeRequiredDescription
namestringYesResource name (max 50 chars)
codestringYesResource code identifier (alphanumeric, dash, underscore, max 50 chars)
descriptionstringNoDescription (max 200 chars)
permissionsarray of objectsNoList of permissions (name, code, description)

Required Permission

resources:create

Examples

curl --request POST \
  --url https://auth.roled.io/api/v1/projects/2JUSLUee46xG6iEwG8JwPc/resources \
  --header 'Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJo...' \
  --header 'Content-Type: application/json' \
  --data '{
    "name": "Products",
    "code": "products",
    "description": "Product catalog",
    "permissions": [
      {
        "name": "Create",
        "code": "create",
        "description": "Create a new product"
      },
      {
        "name": "Read",
        "code": "read",
        "description": "List and view products"
      },
      {
        "name": "Update",
        "code": "update",
        "description": "Edit an existing product"
      },
      {
        "name": "Delete",
        "code": "delete",
        "description": "Remove a product"
      }
    ]
  }'

Error Codes

CodeHTTP StatusDescription
invalid_params400Invalid or missing request parameters, headers, or body.
invalid_authorization_token401Unauthorized request. The authorization token is missing or invalid.
insufficient_permission403Insufficient permissions to access this resource.
project_not_found404The requested project could not be found.
resource_code_already_used409A resource with this code already exists in the project.
system_error500An unexpected error occurred. Please try again later.