
# Assign an application in an organization

`POST /v1/organizations/{org_id}/applications/{application_id}/assignments` · permission `organizations:write`

Assigns the application to a membership or a directory group of the organization. For an application in `assigned_only` mode, organization sign-in additionally requires the user's membership, or one of the user's directory groups, to be assigned. The application must be enabled in the organization first. Directory groups come from SCIM; deleting a group deletes its assignments. `Idempotency-Key` is optional.

## Request

| Field | Type | Required | Description |
|---|---|---|---|
| `org_id` | path | yes | Organization ID (`org_…`). |
| `application_id` | path | yes | Application ID (`app_…`). |
| `target_type` | string | yes | `membership` or `directory_group`. |
| `target_id` | string | yes | Target ID; its prefix must match `target_type` (`mem_…` or `dsg_…`). |

## Response

`201 Created` with the assignment.

```json
{
  "id": "aas_01j9xq6r0t1v5w7x9y1z3a5b7d",
  "organization_id": "org_01j9xk3m7q8r2s4t6v8w0y2z4a",
  "application_id": "app_01j9xm4n8r9s3t5v7w9x1y3z5b",
  "target_type": "membership",
  "target_id": "mem_01j9xn5p9s0t4v6w8x0y2z4a6c",
  "created_at": "2026-10-12T09:31:00.123456Z"
}
```

## Errors

| HTTP | code | When |
|---|---|---|
| 404 | `not_found` | The organization, application or target does not exist in this organization. |
| 409 | `application_not_enabled` | The application is not enabled in the organization. |
| 409 | `conflict` | The target is already assigned. |
| 409 | `organization_pending_deletion` | The organization is pending deletion. |
| 422 | `validation_failed` | `target_type` or `target_id` is missing or invalid. |
| 401 | `unauthenticated` | The credential is missing, invalid or revoked. |
| 403 | `insufficient_permissions` | The credential lacks the required permission. |
| 429 | `rate_limited` | The rate limit was exceeded; retry after the `Retry-After` period. |
| 503 | `service_unavailable` | A dependency is temporarily unavailable; retry after the `Retry-After` period. |

## Example

```bash
curl -i -X POST "https://api.eu.keenauth.com/v1/organizations/org_01j9xk3m7q8r2s4t6v8w0y2z4a/applications/app_01j9xm4n8r9s3t5v7w9x1y3z5b/assignments" \
  -H "Authorization: Bearer $KEENAUTH_SECRET_KEY" \
  -H "Content-Type: application/json" \
  -d '{"target_type":"membership","target_id":"mem_01j9xn5p9s0t4v6w8x0y2z4a6c"}'
```
