# Grant End User Role

`POST /end-user-role-grants` · Core · Members & End Users

Grants a project-level role to an end-user, creating a `eur_`-prefixed role grant record. The role must be within the project's configured role ladder (minimum `PROJECT_END_USER`). Role grants are privilege-escalation operations and require a checker by default under the Maker-Checker policy framework. Requires `PROJECT_ADMIN` authority.

## Parameters

| Name | In | Required | Description |
|---|---|---|---|
| `projectSlug` | path | yes | The project's slug: the path segment after `@`. It is unique within the org. Example: `"storefront"`. |

## Request body

| Field | Type | Required | Description |
|---|---|---|---|
| `endUserId` | string | yes | The end user to grant the role to (`eu_...`). An id with no end user in this project gets 404 `K9O_NOT_FOUND`. |
| `role` | string | yes | The role name, as your application defines it. The platform does not check it against a list. An end user holds each role at most once: granting a role they already hold gets 400 `K9O_INVALID_FIELD_VALUE`. |

```json
{
  "endUserId": "string",
  "role": "string"
}
```

## Responses

- **200**: Success

| Field | Type | Required | Description |
|---|---|---|---|
| `data` | object | yes | The grant that was created. |
| `data.grant` | object | yes | An active role grant. |
| `data.grant.id` | string | yes | The grant's id (`eurg_...`). Use it to revoke the grant. |
| `data.grant.endUserId` | string | yes | The end user who holds the role (`eu_...`). |
| `data.grant.role` | string | yes | The role name. |
| `data.grant.grantedAt` | string (date-time) | yes | When the role was granted. |
| `data.grant.grantedBy` | string | yes | Who granted it: the subject id of the caller that made the grant (an operator's user id, `usr_...`), or `invitation` when the end user received it by redeeming an invitation. |
| `meta` | object | yes | Request metadata: cost, timing and the request and trace ids. |


## Errors

| HTTP | Code | When |
|---|---|---|
| 401 | `K9O_SESSION_EXPIRED` | Your session has expired; sign in again to continue. |
| 403 | `K9O_ACCESS_DENIED` | You do not hold the required role to grant roles to end-users. |
| 404 | `K9O_END_USER_NOT_FOUND` | The specified end-user does not exist in this project. |

## Code samples

### cURL

```bash
curl -X POST 'https://<org>.api-<region>.k9o.io/@storefront/end-user-role-grants' \
  -H 'Authorization: Bearer $K9O_TOKEN' \
  -H 'Content-Type: application/json' \
  -d '{
  "endUserId": "string",
  "role": "string"
}'
```

### fetch

```javascript
const res = await fetch('https://<org>.api-<region>.k9o.io/@storefront/end-user-role-grants', {
  method: 'POST',
  headers: {
    'Authorization': `Bearer ${process.env.K9O_TOKEN}`,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
  "endUserId": "string",
  "role": "string"
}),
});
const { data, meta } = await res.json();
```

### k9o CLI

```bash
k9o end-user role-grant grant --end-user <id> --role <role>
```

### @k9o/core

```typescript
// const k9o = new K9o({ orgSlug: 'playground', projectSlug: 'storefront', apiKey: 'k9o_…' })
const { data } = await k9o.endUsers.roleGrants.grant({
  endUserId: 'string',
  role: 'string'
})
```

### k9o

```python
# k9o = create_client(org_slug="playground", project_slug="storefront", api_key="k9o_…")
response = k9o.end_users.role_grants.grant({
    "endUserId": "string",
    "role": "string"
})
```

### sdk-go

```go
// ctx := context.Background()
// client, _ := k9o.NewClient(k9o.ClientOpts{OrgSlug: "playground", ProjectSlug: "storefront", APIKey: "k9o_…"})
data, _, kerr := client.EndUsers.RoleGrants.Grant(ctx, map[string]any{"endUserId": "string", "role": "string"})
```

### k9o

```rust
// let k9o = Client::new(ClientOpts { org_slug: "playground".into(), project_slug: "storefront".into(), api_key: "k9o_…".into() })?;
let resp = k9o.end_users.role_grants.grant(json!({"endUserId": "string", "role": "string"})).await?
```

### dev.k9o:core

```java
// K9o k9o = K9o.createClient(K9o.Opts.builder().orgSlug("playground").projectSlug("storefront").apiKey("k9o_…").build());
var response = k9o.endUsers().roleGrants().grant(Map.of("endUserId", "string", "role", "string"))
```

### K9o.Core

```c#
// var k9o = K9oClient.Create(new K9oOptions { OrgSlug = "playground", ProjectSlug = "storefront", ApiKey = "k9o_…" });
var response = await k9o.EndUsers.RoleGrants.GrantAsync(new Dictionary<string, object> { ["endUserId"] = "string", ["role"] = "string" })
```

### k9o

```ruby
# k9o = K9o.create_client(org_slug: "playground", project_slug: "storefront", api_key: "k9o_…")
response = k9o.end_users.role_grants.grant({ endUserId: "string", role: "string" })
```

### k9o/sdk

```php
// $k9o = K9oClient::create(['org_slug' => 'playground', 'project_slug' => 'storefront', 'api_key' => 'k9o_…']);
$response = $k9o->end_users->role_grants->grant(['endUserId' => 'string', 'role' => 'string'])
```


Canonical page: https://docs.kilimanjaro.dev/api-playground/core/grant-end-user-role
