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

# Create ResourceAccessRule

> Create a new ResourceAccessRule record.

A **ResourceAccessRule** defines additional booking policies and restrictions for one or more `Resource`(s) or for all resources in a location (`Business`), scoped by date/time, customer, team, plan, or other criteria. Rules are evaluated in `EvaluationOrder` and can optionally stop further evaluation when matched (`StopEvaluationIfRuleIsMet`).

The booking-policy fields (`BookInAdvanceLimit`, `LateBookingLimit`, `LateCancellationLimit`, `IntervalLimit`, `MaxBookingLength`, `MinBookingLength`, `NoReturnPolicy*`, cancellation-fee fields, and repeat-booking limits) mirror those on `Resource` and carry the same semantics — they override the resource-level defaults when the rule matches.

When `BusinessId` is set and `Resources` is empty, the rule applies to all resources in the business and its children (if any). When specific `Resources` are listed, the rule applies only to those resources.

### Scope: who the rule applies to

* `OnlyForMembers` / `OnlyForContacts` — quick toggles to limit the rule to members or contacts.
* `Tariffs` — pricing plans this rule applies to. When set, the rule only fires for customers on one of these plans.
* `Teams` — teams this rule applies to. When set, the rule only fires for members of one of these teams.
* `Courses` — the rule applies only to customers who have completed one of these courses.
* `EventCategories` — the rule applies only to customers who have attended (checked in to) an event in one of these categories.

### Scope: who is allowed to book when the rule fires

* `AllowedTariffs` — only customers on one of these plans are allowed to book when the rule applies to them.
* `AllowedTeams` — only members of one of these teams are allowed to book when the rule applies to them.

### List mutation helpers

For each list field (`Tariffs`, `AllowedTariffs`, `Teams`, `AllowedTeams`, `Members`, `EventCategories`, `Courses`) there are `Added*` and `Removed*` variants that append or remove entries on update without replacing the full list.

## Authentication

<Note>
  This endpoint requires OAuth2 authentication. Include a valid bearer token in the `Authorization` header.
  The authenticated user must be a full unrestricted administrator or have the **`ResourceAccessRule-Create`** role.
</Note>

## Request Body

### Required Fields

<ParamField body="BusinessId" type="integer" required>
  Business Id.
</ParamField>

<ParamField body="Name" type="string" required>
  Rule name.
</ParamField>

<ParamField body="AppliedResourcesCount" type="integer" required>
  Applied Resources Count.
</ParamField>

<ParamField body="EvaluationOrder" type="integer" required>
  Order in which this rule is evaluated relative to other rules on the same resource. Lower values are evaluated first..
</ParamField>

<ParamField body="CancellationFeeType" type="integer" required>
  How the cancellation fee is calculated: Absolute (fixed amount) or Percentage (of booking cost).. Defaults to `eCancellationFeeType.Absolute`.
</ParamField>

### Optional Fields

<ParamField body="Resources" type="integer[]">
  Resources.
</ParamField>

<ParamField body="Active" type="boolean">
  Whether this rule is currently active and evaluated during booking..
</ParamField>

<ParamField body="OnlyForContacts" type="boolean">
  When true, this rule applies only to contacts (non-member customers)..
</ParamField>

<ParamField body="ApplyRuleFrom" type="string">
  Date from which this rule starts being evaluated. Null means no start-date restriction..
</ParamField>

<ParamField body="ApplyRuleTo" type="string">
  Date after which this rule stops being evaluated. Null means no end-date restriction..
</ParamField>

<ParamField body="BookInAdvanceLimit" type="number">
  Maximum number of days in advance a booking can be made. Null means no limit..
</ParamField>

<ParamField body="LateBookingLimit" type="number">
  Minimum lead time (in minutes) required before a booking can start. Prevents last-minute bookings..
</ParamField>

<ParamField body="LateCancellationLimit" type="integer">
  Cut-off in minutes before the booking start time. Cancellations after this point are considered late and may incur a fee..
</ParamField>

<ParamField body="IntervalLimit" type="integer">
  Minimum interval (in minutes) between consecutive bookings on this resource, used as a buffer for setup or cleaning..
</ParamField>

<ParamField body="MaxBookingLength" type="integer">
  Maximum allowed duration for a single booking, in minutes..
</ParamField>

<ParamField body="MinBookingLength" type="integer">
  Minimum allowed duration for a single booking, in minutes..
</ParamField>

<ParamField body="NoReturnPolicy" type="integer">
  Cooldown in minutes: prevents the same user from booking this specific resource again within this window after their last booking ends..
</ParamField>

<ParamField body="NoReturnPolicyAllResources" type="integer">
  Cooldown in minutes: prevents the same user from booking any resource after booking this one, for the specified window\..
</ParamField>

<ParamField body="NoReturnPolicyAllUsers" type="integer">
  Cooldown in minutes: prevents any user from booking this resource within the specified window after the previous booking ends..
</ParamField>

<ParamField body="RejectWithMessage" type="string">
  Message shown to the user when their booking is rejected by this rule..
</ParamField>

<ParamField body="OnlyForMembers" type="boolean">
  When true, this rule applies only to active members (coworkers with a plan)..
</ParamField>

<ParamField body="Tariffs" type="integer[]">
  Tariffs.
</ParamField>

<ParamField body="AllowedTariffs" type="integer[]">
  Allowed Tariffs.
</ParamField>

<ParamField body="Members" type="integer[]">
  Members.
</ParamField>

<ParamField body="Teams" type="integer[]">
  Teams.
</ParamField>

<ParamField body="AllowedTeams" type="integer[]">
  Allowed Teams.
</ParamField>

<ParamField body="EventCategories" type="integer[]">
  Event Categories.
</ParamField>

<ParamField body="Courses" type="integer[]">
  Courses.
</ParamField>

<ParamField body="StopEvaluationIfRuleIsMet" type="boolean">
  When true, no further rules are evaluated after this one matches..
</ParamField>

<ParamField body="CancellationFeeProductId" type="integer">
  Cancellation Fee Product Id.
</ParamField>

<ParamField body="ChargeCancellationFee" type="boolean">
  When true, a fee is charged for late cancellations (past the LateCancellationLimit)..
</ParamField>

<ParamField body="CancellationFeeAmount" type="number">
  Fixed cancellation fee amount. Used when CancellationFeeType is Absolute..
</ParamField>

<ParamField body="CancellationFeePercentage" type="number">
  Cancellation fee as a percentage of the booking cost. Used when CancellationFeeType is Percentage..
</ParamField>

<ParamField body="RepeatBookingQuantityLimit" type="integer">
  Maximum number of occurrences allowed when creating a recurring booking under this rule..
</ParamField>

<ParamField body="RepeatBookingPeriodLimitInMonths" type="integer">
  Maximum time span (in months) over which a recurring booking series can extend under this rule..
</ParamField>

### Children

<ParamField body="EligibleTimeSlots" type="object[]">
  Time slots defining when this rule applies (eligibility windows). The year, month and day component of FromTime/ToTime is always 1976-01-01.

  <Expandable>
    <ParamField body="DayOfWeek" type="integer" required>
      Day Of Week.
    </ParamField>

    <ParamField body="FromTime" type="string" required>
      Start time.
    </ParamField>

    <ParamField body="ToTime" type="string" required>
      End time.
    </ParamField>
  </Expandable>
</ParamField>

<ParamField body="TimeSlots" type="object[]">
  The days and times the resources can be booked when this rule applies. The year, month and day component of FromTime/ToTime is always 1976-01-01.

  <Expandable>
    <ParamField body="DayOfWeek" type="integer" required>
      Day Of Week.
    </ParamField>

    <ParamField body="FromTime" type="string" required>
      Start time.
    </ParamField>

    <ParamField body="ToTime" type="string" required>
      End time.
    </ParamField>
  </Expandable>
</ParamField>

## Code Examples

<CodeGroup>
  ```bash cURL theme={null}
  curl -X POST \
    "https://spaces.nexudus.com/api/spaces/resourceaccessrules" \
    -H "Authorization: Bearer YOUR_TOKEN" \
    -H "Content-Type: application/json" \
    -d '{
      "BusinessId": 0,
      "Name": "",
      "AppliedResourcesCount": 0,
      "EvaluationOrder": 0,
      "CancellationFeeType": 0,
      "EligibleTimeSlots": [
          {
              "DayOfWeek": 0,
              "FromTime": "2025-01-15T10:30:00Z",
              "ToTime": "2025-01-15T10:30:00Z"
          }
      ],
      "TimeSlots": [
          {
              "DayOfWeek": 0,
              "FromTime": "2025-01-15T10:30:00Z",
              "ToTime": "2025-01-15T10:30:00Z"
          }
      ]
  }'
  ```

  ```javascript JavaScript theme={null}
  const response = await fetch(
    'https://spaces.nexudus.com/api/spaces/resourceaccessrules',
    {
      method: 'POST',
      headers: {
        'Authorization': 'Bearer YOUR_TOKEN',
        'Content-Type': 'application/json'
      },
      body: JSON.stringify({
        BusinessId: 0,
        Name: '',
        AppliedResourcesCount: 0,
        EvaluationOrder: 0,
        CancellationFeeType: 0,
        EligibleTimeSlots: [object Object],
        TimeSlots: [object Object]
      })
    }
  );

  const data = await response.json();
  ```

  ```python Python theme={null}
  import requests

  response = requests.post(
      'https://spaces.nexudus.com/api/spaces/resourceaccessrules',
      headers={
          'Authorization': 'Bearer YOUR_TOKEN',
          'Content-Type': 'application/json'
      },
      json={
          'BusinessId': 0,
          'Name': '',
          'AppliedResourcesCount': 0,
          'EvaluationOrder': 0,
          'CancellationFeeType': 0,
          'EligibleTimeSlots': [object Object],
          'TimeSlots': [object Object]
      }
  )

  data = response.json()
  ```
</CodeGroup>

## Response

### 200

<ResponseField name="Status" type="integer">
  HTTP status code. `200` on success.
</ResponseField>

<ResponseField name="Message" type="string">
  A human-readable message confirming the creation.
</ResponseField>

<ResponseField name="Value" type="object">
  Contains the `Id` of the newly created record.
</ResponseField>

<ResponseField name="WasSuccessful" type="boolean">
  `true` if the resourceaccessrule was created successfully.
</ResponseField>

<ResponseField name="Errors" type="array">
  `null` on success.
</ResponseField>

```json Example Response theme={null}
{
  "Status": 200,
  "Message": "ResourceAccessRule was successfully created.",
  "Value": {
    "Id": 87654321
  },
  "OpenInDialog": false,
  "OpenInWindow": false,
  "RedirectURL": null,
  "JavaScript": null,
  "UpdatedOn": "2025-01-15T10:30:00Z",
  "UpdatedBy": "admin@example.com",
  "Errors": null,
  "WasSuccessful": true
}
```

### 400

<ResponseField name="Message" type="string">
  A summary of the validation error(s), in the format `PropertyName: error message`.
</ResponseField>

<ResponseField name="Value" type="any">
  `null` on validation failure.
</ResponseField>

<ResponseField name="Errors" type="object[]">
  Array of validation errors.

  <Expandable>
    <ResponseField name="AttemptedValue" type="any">
      The value that was submitted for the field, or `null` if missing.
    </ResponseField>

    <ResponseField name="Message" type="string">
      The validation error message.
    </ResponseField>

    <ResponseField name="PropertyName" type="string">
      The name of the property that failed validation.
    </ResponseField>
  </Expandable>
</ResponseField>

<ResponseField name="WasSuccessful" type="boolean">
  `false` when the request fails validation.
</ResponseField>

```json Example Response theme={null}
{
  "Message": "Name: is a required field",
  "Value": null,
  "Errors": [
    {
      "AttemptedValue": null,
      "Message": "is a required field",
      "PropertyName": "Name"
    }
  ],
  "WasSuccessful": false
}
```
