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

# Save a script to the script library

> Add a script to your company's script library and return it with its `scriptId`. Nothing runs on a device: run it afterwards with `runScript` or `runDeviceScript`, whose runs then carry the script's name and `scriptId` in `getScriptRuns`.

The name must be unique in the library and end with the extension that decides the interpreter and the platforms: `.sh` (macOS + Linux), `.py` (macOS + Linux), `.ps1` (Windows). The name cannot be changed later. The source is limited to 90 KB. Refused with 409 when the name is taken.

To change the source of a saved script, use `updateScript`; to remove it, `deleteScript`. To add the scripts Primo maintains for a known issue, use `addRemediationKit`.

Key: WriteScope: Company


## OpenAPI

````yaml https://api.getprimo.com/openapi.json post /scripts
openapi: 3.1.1
info:
  title: Public API - BETA
  description: Read docs on https://docs.getprimo.com/
  version: '1.0'
  contact: {}
servers:
  - url: https://api.getprimo.com
security:
  - apikey: []
tags: []
paths:
  /scripts:
    post:
      tags:
        - Scripts
      summary: Save a script to the script library
      description: >-
        Add a script to your company's script library and return it with its
        `scriptId`. Nothing runs on a device: run it afterwards with `runScript`
        or `runDeviceScript`, whose runs then carry the script's name and
        `scriptId` in `getScriptRuns`.


        The name must be unique in the library and end with the extension that
        decides the interpreter and the platforms: `.sh` (macOS + Linux), `.py`
        (macOS + Linux), `.ps1` (Windows). The name cannot be changed later. The
        source is limited to 90 KB. Refused with 409 when the name is taken.


        To change the source of a saved script, use `updateScript`; to remove
        it, `deleteScript`. To add the scripts Primo maintains for a known
        issue, use `addRemediationKit`.
      operationId: createScript
      parameters: []
      requestBody:
        required: true
        content:
          application/json:
            schema:
              $ref: '#/components/schemas/CreateScriptBody'
      responses:
        '201':
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/CreateScript_Output'
components:
  schemas:
    CreateScriptBody:
      type: object
      properties:
        name:
          description: >-
            File name of the script, unique in the company. Its extension
            decides the interpreter and the platforms, and cannot be changed
            later: `.sh` (shell, macOS + Linux), `.py` (Python, macOS + Linux),
            `.ps1` (PowerShell, Windows).
          type: string
          minLength: 4
          maxLength: 255
          pattern: \.(sh|py|ps1)$
        contents:
          description: >-
            Full source of the script, at most 90 KB. It runs with elevated
            privileges on the devices it targets.
          type: string
          minLength: 1
      required:
        - name
        - contents
      additionalProperties: false
    CreateScript_Output:
      type: object
      properties:
        id:
          description: Identifier of the saved script, used as `scriptId` when running it.
          type: number
        name:
          description: >-
            File name of the script. Its extension decides the interpreter and
            therefore the platforms: `.sh` (shell, macOS + Linux), `.py`
            (Python, macOS + Linux), `.ps1` (PowerShell, Windows).
          type: string
        platforms:
          description: Platforms this script can run on, derived from its name.
          type: array
          items:
            type: string
            enum:
              - macos
              - windows
              - linux
        createdAt:
          type: string
          format: date-time
          pattern: >-
            ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?:Z))$
        updatedAt:
          type: string
          format: date-time
          pattern: >-
            ^(?:(?:\d\d[2468][048]|\d\d[13579][26]|\d\d0[48]|[02468][048]00|[13579][26]00)-02-29|\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\d|30)|(?:02)-(?:0[1-9]|1\d|2[0-8])))T(?:(?:[01]\d|2[0-3]):[0-5]\d(?::[0-5]\d(?:\.\d+)?)?(?:Z))$
      required:
        - id
        - name
        - platforms
        - createdAt
        - updatedAt
      additionalProperties: false
  securitySchemes:
    apikey:
      scheme: bearer
      bearerFormat: API key
      type: http
      description: >-
        Use your Primo API key in the Authorization header as `Bearer
        <API_KEY>`.

````

This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.