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

# Create an access rule

> Adds an access rule to a network — either including a specific list of locations or excluding one. Rules can be scheduled: they start today unless you set a future start date, and can be given an end date after which they expire automatically. Important: adding the first rule to a network switches it from showing everything to showing only what the rules allow.



## OpenAPI

````yaml /openapi/emsp-network/openapi.yaml post /emsp/v1/networks/{network_id}/rules
openapi: 3.0.0
info:
  title: Spirii EMSP - Network & Access Control API
  description: >-
    Manages network access and location visibility for secure multi-tenant
    operation.
  version: v1
  contact: {}
servers:
  - url: https://api.spirii.com
    description: Production
security:
  - OAuth2ClientCredentials: []
tags:
  - name: Networks
    description: Network lifecycle management
paths:
  /emsp/v1/networks/{network_id}/rules:
    post:
      tags:
        - Networks
      summary: Create an access rule
      description: >-
        Adds an access rule to a network — either including a specific list of
        locations or excluding one. Rules can be scheduled: they start today
        unless you set a future start date, and can be given an end date after
        which they expire automatically. Important: adding the first rule to a
        network switches it from showing everything to showing only what the
        rules allow.
      operationId: NetworkController_createRule_v1
      parameters:
        - name: Idempotency-Key
          in: header
          description: >-
            Client-generated unique key per operation intent (UUID). Same key +
            identical body replays the original response; same key + different
            body returns 409.
          required: true
          schema:
            type: string
            format: uuid
        - name: network_id
          required: true
          in: path
          description: The unique ID of the network to add the rule to.
          schema:
            type: string
            format: uuid
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateAccessRuleDto'
      responses:
        '201':
          description: The created access rule.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/AccessRuleResponse'
components:
  schemas:
    CreateAccessRuleDto:
      type: object
      properties:
        rule_type:
          type: string
          enum:
            - EXCLUDE_LOCATIONS
            - INCLUDE_LOCATIONS
          description: Whether the rule includes or excludes the listed locations
        location_ids:
          description: UUIDs of locations the rule applies to
          type: array
          items:
            type: string
        priority:
          type: number
          description: Rule precedence; lower number = higher precedence
          minimum: 0
        effective_from:
          type: string
          format: date-time
          description: >-
            When the rule becomes active (ISO 8601). Must not be more than a
            minute in the past if set; defaults to now when omitted.
        effective_until:
          type: string
          format: date-time
          nullable: true
          description: >-
            When the rule stops being active (ISO 8601). Null/omitted means
            open-ended.
      required:
        - rule_type
        - location_ids
        - priority
    AccessRuleResponse:
      type: object
      properties:
        rule_id:
          type: string
          format: uuid
          description: Access rule identifier.
        emp_identity_id:
          type: string
          format: uuid
          description: emp_identity the rule belongs to.
        tenant_id:
          type: string
          format: uuid
          description: Owning tenant identifier.
        rule_type:
          description: Whether the rule includes or excludes.
          allOf:
            - $ref: '#/components/schemas/AccessRuleType'
        network_id:
          type: string
          format: uuid
          description: Network the rule applies to.
        location_ids:
          nullable: true
          description: >-
            Locations the rule targets; null when the rule is not
            location-scoped.
          type: array
          items:
            type: string
            format: uuid
        priority:
          type: number
          description: Evaluation priority (lower wins).
        effective_from:
          type: string
          format: date
          description: Date from which the rule is effective (UTC).
        effective_until:
          type: string
          format: date
          nullable: true
          description: Date the rule stops being effective (UTC); null means open-ended.
        created_at:
          type: string
          format: date-time
          description: Creation timestamp (UTC).
        updated_at:
          type: string
          format: date-time
          description: Last-update timestamp (UTC).
      required:
        - rule_id
        - emp_identity_id
        - tenant_id
        - rule_type
        - network_id
        - location_ids
        - priority
        - effective_from
        - effective_until
        - created_at
        - updated_at
    AccessRuleType:
      type: string
      enum:
        - EXCLUDE_LOCATIONS
        - INCLUDE_LOCATIONS
      description: Whether the rule includes or excludes.
  securitySchemes:
    OAuth2ClientCredentials:
      type: oauth2
      flows:
        clientCredentials:
          tokenUrl: /oauth/token
          scopes:
            emsp:networks:read: View network and access control configuration
            emsp:networks:write: Create/update/delete SUB networks, manage access rules
            emsp:networks:publish: Publish/drain networks (PATCH /networks/:id/publish-state)

````