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

# Schedule a New Script

> Creates a new scheduled script entry. This involves defining the script content, selecting target devices (sites), specifying a launch time, and configuring notification recipients. The script will be in an 'unauthorized' state until an authorization workflow is completed.



## OpenAPI

````yaml /api/en/scripts.yaml post /scripts/scheduled
openapi: 3.0.3
info:
  title: Altostrat Scripts API
  version: 1.0.0
  description: >-
    The Altostrat Scripts API is the microservice responsible for creating,
    managing, and executing MikroTik RouterOS scripts across your network
    infrastructure.


    It serves as the core automation engine within the Altostrat SDX platform,
    empowering developers to programmatically deploy configuration changes,
    perform operational tasks, and leverage AI for script generation. This API
    is the foundation for network automation and agentic AI capabilities.


    This API allows you to programmatically manage:

    - **Scheduled Scripts:** The primary resource for defining a script, its
    target devices, and a future execution time, complete with authorization
    workflows and progress tracking.

    - **Script Templates:** Reusable, version-controlled script blueprints that
    can be either private to an organization or shared globally to enforce
    standardization and best practices.

    - **Community Scripts:** A curated and searchable library of publicly
    available RouterOS scripts sourced from GitHub, providing ready-to-use
    solutions for common networking tasks.

    - **AI Script Generation:** An agentic AI endpoint that translates natural
    language prompts into functional and safe MikroTik RouterOS scripts.


    Developers use this API to build powerful, scalable, and intelligent network
    automation workflows for their fleet of MikroTik devices.
servers:
  - url: https://v1.api.altostrat.io
security:
  - BearerAuth:
      - script:view
      - script:create
      - script:update
      - script:delete
      - script:run
      - script:authorize
tags:
  - name: Scheduled Scripts
    description: >-
      Manage the lifecycle of scripts scheduled for execution on network
      devices.
  - name: Script Templates
    description: Create and manage reusable script templates for standardization.
  - name: Community Scripts
    description: Discover and utilize scripts from the public community repository.
  - name: AI Script Generation
    description: Generate MikroTik scripts from natural language prompts.
paths:
  /scripts/scheduled:
    post:
      tags:
        - Scheduled Scripts
      summary: Schedule a New Script
      description: >-
        Creates a new scheduled script entry. This involves defining the script
        content, selecting target devices (sites), specifying a launch time, and
        configuring notification recipients. The script will be in an
        'unauthorized' state until an authorization workflow is completed.
      operationId: createScheduledScript
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/ScheduledScriptCreate'
      responses:
        '201':
          description: The scheduled script was created successfully.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/ScheduledScript'
        '400':
          $ref: '#/components/responses/BadRequest'
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  schemas:
    ScheduledScriptCreate:
      type: object
      required:
        - make_backup
        - abort_if_offline
        - description
        - script
        - launch_at
        - sites
        - notify
      properties:
        test_site_id:
          type: string
          format: uuid
          nullable: true
          description: The unique identifier of the site designated for test runs.
          example: site_2Al5z3gXyY5f6Z7h8j9k0l1m
        make_backup:
          type: boolean
          description: If true, create a configuration backup before executing the script.
          example: true
        abort_if_offline:
          type: boolean
          description: If true, do not attempt to run the script on sites that are offline.
          example: true
        description:
          type: string
          description: A human-readable name for the scheduled script.
          example: Nightly BGP peer maintenance
        script:
          type: string
          description: The full content of the MikroTik RouterOS script.
          example: /routing bgp peer disable [find name=peer1]
        launch_at:
          type: string
          format: date-time
          description: >-
            The scheduled UTC date and time for execution. Must be in the
            future.
          example: '2025-12-01T04:00:00Z'
        sites:
          type: array
          description: An array of site IDs to target.
          items:
            type: string
            format: uuid
          example:
            - site_1AbCdEfGhIjKlMnOpQrStUv
            - site_2BcDeFgHiJkLmNoPqRsTuVw
        notify:
          type: array
          description: An array of user IDs to receive notifications.
          items:
            type: string
            format: uuid
          example:
            - auth0|5f9d4b3c2e1a0b006f8b4c5d
    ScheduledScript:
      type: object
      properties:
        id:
          type: string
          format: uuid
          description: The unique identifier for the scheduled script.
          example: 018f5bda-4690-4432-8472-358b2734f19b
        created_by:
          type: string
          format: uuid
          description: The user ID of the person who created the script schedule.
          example: auth0|642b7f3b8b3b3e3e3e3e3e3e
        test_site_id:
          type: string
          format: uuid
          nullable: true
          description: The unique identifier of the site designated for test runs.
          example: site_2Al5z3gXyY5f6Z7h8j9k0l1m
        make_backup:
          type: boolean
          description: >-
            If true, a configuration backup will be created on each target
            device before the script is executed.
          example: true
        abort_if_offline:
          type: boolean
          description: >-
            If true, the script execution will be aborted for a site if it is
            offline at launch time.
          example: false
        description:
          type: string
          description: A human-readable name or description for the script schedule.
          example: Weekly firewall rule update
        summary:
          type: string
          nullable: true
          description: An AI-generated summary of the script's purpose.
          example: >-
            This script adds a firewall filter rule to drop input from a
            specific address list named "blacklist".
        script:
          type: string
          description: The full content of the MikroTik RouterOS script to be executed.
          example: >-
            /ip firewall filter add action=drop chain=input
            src-address-list=blacklist
        status:
          type: string
          description: The current status of the scheduled script.
          enum:
            - unauthorized
            - scheduled
            - launched
            - cancelled
          example: scheduled
        authorized_at:
          type: string
          format: date-time
          nullable: true
          description: >-
            The timestamp when the script execution was authorized. Null if not
            yet authorized.
          example: '2025-10-30T10:00:00.000000Z'
        cancelled_at:
          type: string
          format: date-time
          nullable: true
          description: The timestamp when the script was cancelled.
          example: null
        launch_at:
          type: string
          format: date-time
          description: The scheduled UTC date and time for the script to be executed.
          example: '2025-11-01T02:00:00.000000Z'
        t_minus:
          type: string
          nullable: true
          description: A human-readable countdown to the launch time.
          example: in 2 days
        started_at:
          type: string
          format: date-time
          nullable: true
          description: The timestamp when the script execution actually began.
          example: '2025-11-01T02:00:05.000000Z'
        sites:
          type: array
          description: A list of site IDs where the script will be executed.
          items:
            type: string
            format: uuid
            example: site_1AbCdEfGhIjKlMnOpQrStUv
        notify:
          type: array
          description: >-
            A list of user IDs to notify about the script's progress and
            authorization requests.
          items:
            type: string
            format: uuid
            example: auth0|5f9d4b3c2e1a0b006f8b4c5d
        progress:
          $ref: '#/components/schemas/ScriptProgress'
        created_at:
          type: string
          format: date-time
          description: The timestamp when the scheduled script was created.
          example: '2025-10-29T12:44:27.000000Z'
        updated_at:
          type: string
          format: date-time
          description: The timestamp when the scheduled script was last updated.
          example: '2025-10-29T13:05:00.000000Z'
    ScriptProgress:
      type: object
      description: >-
        Represents the execution progress of a launched script across its target
        sites.
      properties:
        completed:
          type: array
          description: A list of site IDs where the script has completed successfully.
          items:
            type: string
            format: uuid
            example: site_1AbCdEfGhIjKlMnOpQrStUv
        failed:
          type: array
          description: A list of site IDs where the script execution has failed.
          items:
            type: string
            format: uuid
            example: site_2BcDeFgHiJkLmNoPqRsTuVw
        pending:
          type: array
          description: A list of site IDs where the script is still pending or in progress.
          items:
            type: string
            format: uuid
            example: site_3CdEfGhIjKlMnOpQrStUvWx
    ErrorResponse:
      type: object
      properties:
        type:
          type: string
          description: A broad category for the error (e.g., 'invalid_request_error').
          example: invalid_request_error
        code:
          type: string
          description: A short, unique string identifying the specific error.
          example: parameter_missing
        message:
          type: string
          description: A human-readable description of what went wrong.
          example: The 'name' parameter is required for this request.
        doc_url:
          type: string
          description: >-
            A direct link to the documentation page for this specific error
            code.
          example: https://docs.altostrat.io/errors/parameter_missing
  responses:
    BadRequest:
      description: Bad Request - The request was malformed or invalid.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Unauthorized:
      description: >-
        Unauthorized - The request requires authentication and a valid Bearer
        token was not provided.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    Forbidden:
      description: >-
        Forbidden - The authenticated user does not have the required
        permissions (scopes) to perform this action.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    UnprocessableEntity:
      description: >-
        Unprocessable Entity - The request was well-formed but was unable to be
        followed due to semantic errors (e.g., validation failure).
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
    InternalServerError:
      description: Internal Server Error - An unexpected error occurred on the server.
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ErrorResponse'
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >-
        Altostrat SDX API uses JWT Bearer tokens for authentication. Obtain a
        token via the Authentication API and include it in the Authorization
        header as 'Bearer {token}'.

````