---
title: "Grant a role on a resource to a subject"
---

> Documentation Index
> Fetch the complete documentation index at: https://docs.cloudraker.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Grant a role on a resource to a subject

Path: CloudRaker Workspace API › Authorization

`POST /authorization/grants`

Creates a role grant (a share) on a resource. Authorization: the caller must be an organization administrator, or hold the resource’s share permission on the target (`space:share` for `space`, `spacetype:share` for `spacetype`; `settings` has no share permission and is administrator-only); otherwise returns 403 `forbidden`. Body: `subject` (name exactly one of `organizationMembershipId` or `groupId`), `role` (role slug), `resourceType` (`space` | `spacetype` | `settings`), `resourceExternalId`. `settings` resources are created lazily (idempotent) before granting. Returns the created grant.

## Authentication

- `bearerAuth`, http, header `Authorization`

## Request body

_Required._

- `subject` (`createGrant.subject`; object, required)
  - `organizationMembershipId` (`createGrant.subject.organizationMembershipId`; string, optional)
    - minLength 1
  - `groupId` (`createGrant.subject.groupId`; string, optional)
    - minLength 1
- `role` (`createGrant.role`; string, required)
  - minLength 1
- `resourceType` (`createGrant.resourceType`; string, required)
  - one of `"space"`, `"spacetype"`, `"settings"`
- `resourceExternalId` (`createGrant.resourceExternalId`; string, required)
  - minLength 1

## Example request

```json
{
  "subject": {
    "organizationMembershipId": "string",
    "groupId": "string"
  },
  "role": "string",
  "resourceType": "space",
  "resourceExternalId": "string"
}
```

## Code samples

### cURL

```bash
curl --request POST \
  --url https://api.cloudraker.com/authorization/grants \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "subject": {
    "organizationMembershipId": "string",
    "groupId": "string"
  },
  "role": "string",
  "resourceType": "space",
  "resourceExternalId": "string"
}
'
```

### TypeScript

```typescript
const url = 'https://api.cloudraker.com/authorization/grants';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json', Authorization: 'Bearer <token>'},
  body: JSON.stringify({
    subject: {organizationMembershipId: 'string', groupId: 'string'},
    role: 'string',
    resourceType: 'space',
    resourceExternalId: 'string'
  })
};

fetch(url, options)
  .then(res => res.json())
  .then(json => console.log(json))
  .catch(err => console.error(err));
```

### Python

```python
import requests

url = "https://api.cloudraker.com/authorization/grants"

payload = {
    "subject": {
        "organizationMembershipId": "string",
        "groupId": "string"
    },
    "role": "string",
    "resourceType": "space",
    "resourceExternalId": "string"
}
headers = {
    "Content-Type": "application/json",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

## Responses

### 200

The role grant was created.

#### Example

```json
{
  "id": "string",
  "organizationMembershipId": "string",
  "role": {
    "slug": "space-member"
  },
  "resource": {
    "id": "string",
    "externalId": "string",
    "resourceTypeSlug": "space"
  }
}
```

- `id` (`createGrant.response.200.id`; string, required)
- `role` (`createGrant.response.200.role`; object, required)
  - `slug` (`createGrant.response.200.role.slug`; string, required)
    - example `"space-member"`
- `resource` (`createGrant.response.200.resource`; object, required)
  - `id` (`createGrant.response.200.resource.id`; string, required)
  - `externalId` (`createGrant.response.200.resource.externalId`; string, required)
  - `resourceTypeSlug` (`createGrant.response.200.resource.resourceTypeSlug`; string, required)
    - example `"space"`
- `organizationMembershipId` (`createGrant.response.200.organizationMembershipId`; string, optional)

### 400

Validation Error

#### Example

```json
{
  "success": false,
  "error": [
    null
  ],
  "data": null
}
```

- `success` (`createGrant.response.400.success`; boolean, required)
  - one of `false`
- `error` (`createGrant.response.400.error`; array<unknown>, required)
- `data` (`createGrant.response.400.data`; unknown, required)

### 403

Caller is not an admin and lacks the resource’s share permission


Source: https://docs.cloudraker.com/workspace/api/authorization/create-grant/index.md
