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

# Create Rule

> Create an access rule with conditions for a resource in a hub.

NOTE: require_team_owner returns the Team ORM row (not a JWT).
The admin user ID comes from get_current_user (CX-3).



## OpenAPI

````yaml /openapi/mio-openapi.json post /api/v1/teams/{team_id}/hubs/{hub_id}/access-rules
openapi: 3.1.0
info:
  description: >-
    Production API reference for Membership.io. Use the authored guides for
    workflows and the generated endpoint pages for exact parameters and schemas.
  title: Membership.io API
  version: 0.1.0
servers:
  - description: Production
    url: https://api.member.dev
security:
  - bearerAuth: []
paths:
  /api/v1/teams/{team_id}/hubs/{hub_id}/access-rules:
    post:
      tags:
        - access-rules-admin
      summary: Create Rule
      description: |-
        Create an access rule with conditions for a resource in a hub.

        NOTE: require_team_owner returns the Team ORM row (not a JWT).
        The admin user ID comes from get_current_user (CX-3).
      operationId: >-
        access_rules_admin.post_access_rules_admin_post_teams_by_team_id_hubs_by_hub_id_access_rules
      parameters:
        - in: path
          name: team_id
          required: true
          schema:
            title: Team Id
            type: string
        - in: path
          name: hub_id
          required: true
          schema:
            title: Hub Id
            type: string
      requestBody:
        content:
          application/vnd.api+json:
            schema:
              $ref: '#/components/schemas/AccessRuleCreateEnvelope'
        required: true
      responses:
        '201':
          content:
            application/vnd.api+json:
              schema:
                $ref: '#/components/schemas/AccessRuleResponse'
          description: Successful Response
        '400':
          content:
            application/vnd.api+json:
              schema:
                $ref: '#/components/schemas/JsonApiErrorResponse'
          description: Validation error
        '401':
          content:
            application/vnd.api+json:
              schema:
                $ref: '#/components/schemas/JsonApiErrorResponse'
          description: Not authenticated
        '403':
          content:
            application/vnd.api+json:
              schema:
                $ref: '#/components/schemas/JsonApiErrorResponse'
          description: Forbidden
        '404':
          content:
            application/vnd.api+json:
              schema:
                $ref: '#/components/schemas/JsonApiErrorResponse'
          description: Resource not found
        '409':
          content:
            application/vnd.api+json:
              schema:
                $ref: '#/components/schemas/JsonApiErrorResponse'
          description: Conflict (duplicate rule for target)
        '422':
          content:
            application/vnd.api+json:
              schema:
                $ref: '#/components/schemas/JsonApiErrorResponse'
          description: Unprocessable entity
      security:
        - HTTPBearer: []
components:
  schemas:
    AccessRuleCreateEnvelope:
      additionalProperties: false
      properties:
        data:
          $ref: '#/components/schemas/AccessRuleCreateResource'
      required:
        - data
      title: AccessRuleCreateEnvelope
      type: object
    AccessRuleResponse:
      additionalProperties: false
      properties:
        data:
          $ref: '#/components/schemas/AccessRuleResource'
      required:
        - data
      title: AccessRuleResponse
      type: object
    JsonApiErrorResponse:
      description: Error JSON:API response.
      properties:
        errors:
          items:
            $ref: '#/components/schemas/JsonApiError'
          title: Errors
          type: array
        meta:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Meta
      required:
        - errors
      title: JsonApiErrorResponse
      type: object
    AccessRuleCreateResource:
      additionalProperties: false
      properties:
        attributes:
          $ref: '#/components/schemas/AccessRuleCreateAttributes'
        type:
          const: access_rules
          title: Type
          type: string
      required:
        - type
        - attributes
      title: AccessRuleCreateResource
      type: object
    AccessRuleResource:
      additionalProperties: false
      properties:
        attributes:
          $ref: '#/components/schemas/AccessRuleAttributes'
        id:
          title: Id
          type: string
        type:
          const: access_rules
          default: access_rules
          title: Type
          type: string
      required:
        - id
        - attributes
      title: AccessRuleResource
      type: object
    JsonApiError:
      properties:
        code:
          anyOf:
            - type: string
            - type: 'null'
          title: Code
        detail:
          anyOf:
            - type: string
            - type: 'null'
          title: Detail
        id:
          anyOf:
            - type: string
            - type: 'null'
          title: Id
        meta:
          anyOf:
            - additionalProperties: true
              type: object
            - type: 'null'
          title: Meta
        source:
          anyOf:
            - additionalProperties:
                type: string
              type: object
            - type: 'null'
          title: Source
        status:
          title: Status
          type: string
        title:
          title: Title
          type: string
      required:
        - status
        - title
      title: JsonApiError
      type: object
    AccessRuleCreateAttributes:
      additionalProperties: false
      properties:
        conditions:
          items:
            $ref: '#/components/schemas/ConditionInput'
          title: Conditions
          type: array
        logic_operator:
          default: any
          title: Logic Operator
          type: string
        target_id:
          title: Target Id
          type: string
        target_type:
          title: Target Type
          type: string
      required:
        - target_type
        - target_id
      title: AccessRuleCreateAttributes
      type: object
    AccessRuleAttributes:
      additionalProperties: false
      properties:
        conditions:
          items:
            $ref: '#/components/schemas/ConditionAttributes'
          title: Conditions
          type: array
        created_at:
          format: date-time
          title: Created At
          type: string
        hub_id:
          title: Hub Id
          type: string
        logic_operator:
          title: Logic Operator
          type: string
        target_id:
          title: Target Id
          type: string
        target_type:
          title: Target Type
          type: string
        team_id:
          title: Team Id
          type: string
        updated_at:
          format: date-time
          title: Updated At
          type: string
      required:
        - hub_id
        - target_type
        - target_id
        - logic_operator
        - team_id
        - conditions
        - created_at
        - updated_at
      title: AccessRuleAttributes
      type: object
    ConditionInput:
      additionalProperties: false
      description: A single condition within a rule create/update request.
      properties:
        condition_data:
          additionalProperties: true
          title: Condition Data
          type: object
        condition_type:
          enum:
            - has_entitlement
            - in_segment
            - past_drip_date
          title: Condition Type
          type: string
        position:
          default: 0
          maximum: 2147483647
          minimum: 0
          title: Position
          type: integer
      required:
        - condition_type
        - condition_data
      title: ConditionInput
      type: object
    ConditionAttributes:
      additionalProperties: false
      properties:
        condition_data:
          additionalProperties: true
          title: Condition Data
          type: object
        condition_type:
          title: Condition Type
          type: string
        position:
          title: Position
          type: integer
      required:
        - condition_type
        - condition_data
        - position
      title: ConditionAttributes
      type: object
  securitySchemes:
    bearerAuth:
      bearerFormat: JWT or mio_sk API key
      description: >-
        Send platform JWTs, contact JWTs, or team API keys as `Authorization:
        Bearer <token>`.
      scheme: bearer
      type: http
    HTTPBearer:
      scheme: bearer
      type: http

````