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

# Create a new script



## OpenAPI

````yaml https://portal.unicontrol.me/v1/openapi post /v1/scripts
openapi: 3.1.0
info:
  title: Unicontrol API
  description: Welcome
  version: 1.0.0
servers:
  - url: http://0.0.0.0:3000
    description: Local Server
  - url: https://portal.test.flexhome.casa
    description: Development
  - url: https://portal.unicontrol.me
    description: Production
security:
  - bearerAuth: []
paths:
  /v1/scripts:
    post:
      tags:
        - Scripts
      summary: Create a new script
      operationId: postV1Scripts
      parameters:
        - in: header
          name: X-Organization-Id
          required: false
          schema:
            type: string
          description: >-
            ID da organização para contexto (opcional). Quando presente, filtra
            recursos da org.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - name
              properties:
                name:
                  type: string
                  description: Nome do script
                icon:
                  type: string
                  description: Ícone Material
                  example: mdi:play
                color:
                  type: string
                  description: Cor hex
                  example: '#4CAF50'
                actions:
                  type: array
                  items:
                    type: object
                  description: Lista de ações a executar
            example:
              name: Acender luzes da sala
              icon: mdi:lightbulb
              color: '#FFC107'
              actions:
                - type: call_service
                  entity_id: light.sala
                  service: turn_on
      responses:
        '201':
          description: Script created
          content:
            application/json:
              schema:
                type: object
                properties:
                  id:
                    type: integer
                  name:
                    type: string
                  icon:
                    type: string
                  color:
                    type: string
                  enabled:
                    type: boolean
                  actions:
                    type: array
                    items:
                      type: object
                  user_id:
                    type: string
                  org_id:
                    type: string
                    nullable: true
                  created_at:
                    type: string
                    format: date-time
              example:
                id: 1
                name: Acender luzes da sala
                icon: mdi:lightbulb
                color: '#FFC107'
                enabled: true
                actions:
                  - type: call_service
                    entity_id: light.sala
                    service: turn_on
                user_id: user_abc123
                org_id: null
                created_at: '2026-03-17T10:00:00Z'
        '400':
          description: Dados inválidos
          content:
            application/json:
              schema:
                type: object
                properties:
                  message:
                    type: string
              example:
                message: validation error
        '401':
          description: Não autenticado
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
              example:
                error: unauthorized
        '403':
          description: Acesso negado
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
              example:
                error: forbidden
        '429':
          description: Limite do plano atingido
          content:
            application/json:
              schema:
                type: object
                properties:
                  error:
                    type: string
                  message:
                    type: string
                  limit:
                    type: integer
                  current:
                    type: integer
              example:
                error: limit_reached
                message: Limite atingido (10)
                limit: 10
                current: 10
components:
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer

````