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

# Create Record

> Create a new record in a collection.

Validates the request data against the collection schema, auto-generates
a record ID, and sets system fields (account_id, created_at, created_by).

Args:
    collection: The collection name (from URL path).
    data: The record data (request body). May include 'account_id' for superadmins.
    current_user: The authenticated user, or None for anonymous.
    auth_context: Authorization context for permission checking.
    session: Database session.

Returns:
    The created record with all fields including system fields.



## OpenAPI

````yaml post /api/v1/records/{collection}
openapi: 3.1.0
info:
  title: SnackBase
  description: Open-source Backend-as-a-Service (BaaS)
  version: 0.1.0
servers: []
security: []
paths:
  /api/v1/records/{collection}:
    post:
      tags:
        - records
      summary: Create Record
      description: >-
        Create a new record in a collection.


        Validates the request data against the collection schema, auto-generates

        a record ID, and sets system fields (account_id, created_at,
        created_by).


        Args:
            collection: The collection name (from URL path).
            data: The record data (request body). May include 'account_id' for superadmins.
            current_user: The authenticated user, or None for anonymous.
            auth_context: Authorization context for permission checking.
            session: Database session.

        Returns:
            The created record with all fields including system fields.
      operationId: create_record_api_v1_records__collection__post
      parameters:
        - name: collection
          in: path
          required: true
          schema:
            type: string
            title: Collection
      requestBody:
        content:
          application/json:
            schema:
              additionalProperties: true
              type: object
              title: Data
        required: true
      responses:
        '201':
          description: Successful Response
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RecordResponse'
        '400':
          description: Validation error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RecordValidationErrorResponse'
        '401':
          description: Authentication required
        '403':
          description: Permission denied
        '404':
          description: Collection not found
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
components:
  schemas:
    RecordResponse:
      properties:
        id:
          type: string
          title: Id
          description: Record ID (UUID)
        account_id:
          type: string
          title: Account Id
          description: Account ID the record belongs to
        created_at:
          type: string
          title: Created At
          description: ISO 8601 timestamp when record was created
        created_by:
          type: string
          title: Created By
          description: User ID who created the record
        updated_at:
          type: string
          title: Updated At
          description: ISO 8601 timestamp when record was last updated
        updated_by:
          type: string
          title: Updated By
          description: User ID who last updated the record
        account_name:
          anyOf:
            - type: string
            - type: 'null'
          title: Account Name
          description: Display name for the account (optional)
      additionalProperties: true
      type: object
      required:
        - id
        - account_id
        - created_at
        - created_by
        - updated_at
        - updated_by
      title: RecordResponse
      description: |-
        Response for a created or retrieved record.

        Contains all system fields plus user-defined fields.
    RecordValidationErrorResponse:
      properties:
        error:
          type: string
          title: Error
          description: Error type
          default: Validation error
        details:
          items:
            $ref: '#/components/schemas/RecordValidationErrorDetail'
          type: array
          title: Details
          description: List of validation errors
      type: object
      required:
        - details
      title: RecordValidationErrorResponse
      description: Response for record validation errors.
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    RecordValidationErrorDetail:
      properties:
        field:
          type: string
          title: Field
          description: Field that failed validation
        message:
          type: string
          title: Message
          description: Human-readable error message
        code:
          type: string
          title: Code
          description: Machine-readable error code
      type: object
      required:
        - field
        - message
        - code
      title: RecordValidationErrorDetail
      description: A single record validation error.
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError

````