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

# Create Resource Policy

> Create a new resource policy

## Request Body

<ParamField body="id" type="string">
  Optional client-provided ID. Format: `policy_{uuidv7}`
</ParamField>

<ParamField body="scopeId" type="string" required>
  ID of the scope where policy is defined
</ParamField>

<ParamField body="name" type="string" required>
  Display name for the policy
</ParamField>

<ParamField body="description" type="string">
  Description of what this policy does
</ParamField>

<ParamField body="target" type="object" required>
  Resource or collection to target
</ParamField>

<ParamField body="target.kind" type="string" required>
  Target type: `resource` or `collection`
</ParamField>

<ParamField body="target.resourceId" type="string">
  Resource ID (when kind is `resource`)
</ParamField>

<ParamField body="target.collectionId" type="string">
  Collection ID (when kind is `collection`)
</ParamField>

<ParamField body="actions" type="array" required>
  Actions this policy applies to. Use `["*"]` for all actions.
</ParamField>

<ParamField body="effect" type="string" required>
  Policy effect: `allow` or `deny`
</ParamField>

<ParamField body="priority" type="number" default="0">
  Higher priority policies are evaluated first
</ParamField>

<ParamField body="subjectCondition" type="object">
  JSON Logic condition to match the actor
</ParamField>

<ParamField body="contextCondition" type="object">
  JSON Logic condition to match request context
</ParamField>

## Response

Returns the created resource policy object.

<RequestExample>
  ```bash cURL theme={null}
  curl -X POST 'https://api.example.com/resource-policies' \
    -H 'Authorization: Bearer YOUR_TOKEN' \
    -H 'Content-Type: application/json' \
    -d '{
      "scopeId": "scope_org",
      "name": "Finance Team Access",
      "description": "Allow finance team to read finance documents",
      "target": {
        "kind": "collection",
        "collectionId": "collection_finance_docs"
      },
      "actions": ["read", "update"],
      "effect": "allow",
      "priority": 50,
      "subjectCondition": {
        "==": [{"var": "subject.meta.department"}, "finance"]
      }
    }'
  ```
</RequestExample>

<ResponseExample>
  ```json Response theme={null}
  {
    "id": "policy_0190a1b2-c3d4-7e5f-8a9b-0c1d2e3f4a5b",
    "scopeId": "scope_org",
    "name": "Finance Team Access",
    "description": "Allow finance team to read finance documents",
    "target": {
      "kind": "collection",
      "collectionId": "collection_finance_docs"
    },
    "actions": ["read", "update"],
    "effect": "allow",
    "priority": 50,
    "subjectCondition": {
      "==": [{"var": "subject.meta.department"}, "finance"]
    },
    "createdAt": "2024-01-15T10:30:00Z"
  }
  ```
</ResponseExample>
