---
title: "Set role-based access control for a script."
method: PUT
path: "/api/v1/script/{script_id}/access/roles"
---

# Set role-based access control for a script.

`PUT /api/v1/script/{script_id}/access/roles`

**Authentication**: JWT token required
**Authorization**: Admin level access required (ADMIN or SUPERADMIN)
**Purpose**: Configure which user roles can access and execute a script

**Path Parameters**:
- `script_id`: Script identifier/slug or numeric ID

**Request Schema**:
```json
{
  "roles": ["ADMIN", "SUPERADMIN"]
}
```

**Request Fields**:
- `roles`: Array of role names that should have access
  (empty array removes restrictions)

**Valid Roles**:
- `USER`: Regular users
- `ADMIN`: Administrator users
- `SUPERADMIN`: Super administrator users

**Response Schema**:
```json
{
  "data": {
    "script_id": "12345",
    "restricted": true,
    "allowed_roles": ["ADMIN", "SUPERADMIN"],
    "allowed_users": [],
    "access_type": "role_restricted"
  }
}
```

**Behavior**:
- Empty roles array removes all role restrictions
- Non-empty array restricts access to specified roles only
- Users with specified roles can access script regardless of user-specific
  restrictions
- Higher privilege roles (SUPERADMIN) can access scripts restricted to
  lower roles

**Use Cases**:
- Restrict sensitive analysis scripts to admin users only
- Make scripts available to all authenticated users
- Create role-based script catalogs
- Implement script security policies

**Error Responses**:
- `400 Bad Request`: Missing 'roles' field or invalid role names
- `401 Unauthorized`: JWT token required
- `403 Forbidden`: Admin privileges required
- `404 Not Found`: Script does not exist
- `500 Internal Server Error`: Failed to update access controls

## Path parameters

- `script_id` string, required

## Request body

- object

## Response `200`

Success

- object

## Other responses

- `400` — Bad Request
- `401` — Unauthorized
- `403` — Forbidden
- `404` — Not Found
- `500` — Internal Server Error

---

[API](https://skmtc.dev/trends/apis/trends-earth-api.md) · [All operations](https://skmtc.dev/trends/apis/trends-earth-api/llms.txt) · [OpenAPI document](https://skmtc-service-production.skmtc.workers.dev/v1/apis/trends/trends-earth-api/revisions/6bdbc0b84666/schema)
