> ## 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.

# List script runs

> Return the paginated history of script runs, newest first — what was run, on which target, by whom, and how many devices are in each execution status. Use this to answer "what scripts have been run recently?".

For the per-device outcomes of one run, use `getScriptRunExecutions`. For everything that ran on one device, use `getDeviceScriptExecutions`. To list the scripts available to run rather than past runs, use `getScripts`.

Executions are reconciled with FleetDM by a background sweep that runs every 15 minutes, so a freshly created run reads back as `pending` until the next sweep. Poll no more often than that.

<span className="badge-read">Key: Read</span><span className="badge-company">Scope: Company</span>


## OpenAPI

````yaml https://api.getprimo.com/openapi.json get /script-runs
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:
  /script-runs:
    get:
      tags:
        - Scripts
      summary: List script runs
      description: >-
        Return the paginated history of script runs, newest first — what was
        run, on which target, by whom, and how many devices are in each
        execution status. Use this to answer "what scripts have been run
        recently?".


        For the per-device outcomes of one run, use `getScriptRunExecutions`.
        For everything that ran on one device, use `getDeviceScriptExecutions`.
        To list the scripts available to run rather than past runs, use
        `getScripts`.


        Executions are reconciled with FleetDM by a background sweep that runs
        every 15 minutes, so a freshly created run reads back as `pending` until
        the next sweep. Poll no more often than that.
      operationId: getScriptRuns
      parameters:
        - name: page
          required: false
          in: query
          description: Page number
          schema:
            minimum: 1
            maximum: 9007199254740991
            default: 1
            type: number
        - name: perPage
          required: false
          in: query
          description: Number of items per page (max 100)
          schema:
            minimum: 1
            maximum: 100
            default: 50
            type: number
      responses:
        default:
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetScriptRuns_Output'
components:
  schemas:
    GetScriptRuns_Output:
      type: object
      properties:
        data:
          type: array
          items:
            type: object
            properties:
              id:
                type: string
              script:
                type: object
                properties:
                  scriptId:
                    description: >-
                      Saved script that was run, or null when the contents were
                      sent inline.
                    anyOf:
                      - type: number
                      - type: 'null'
                  name:
                    description: >-
                      Script name at the time of the run. Null for an inline
                      run.
                    anyOf:
                      - type: string
                      - type: 'null'
                required:
                  - scriptId
                  - name
                additionalProperties: false
              target:
                description: The target as recorded, with group and device names resolved.
                anyOf:
                  - type: object
                    properties:
                      type:
                        type: string
                        const: all
                    required:
                      - type
                    additionalProperties: false
                  - type: object
                    properties:
                      type:
                        type: string
                        const: deviceGroups
                      deviceGroups:
                        type: array
                        items:
                          type: object
                          properties:
                            id:
                              type: string
                            name:
                              anyOf:
                                - type: string
                                - type: 'null'
                          required:
                            - id
                            - name
                          additionalProperties: false
                    required:
                      - type
                      - deviceGroups
                    additionalProperties: false
                  - type: object
                    properties:
                      type:
                        type: string
                        const: devices
                      devices:
                        type: array
                        items:
                          type: object
                          properties:
                            id:
                              type: string
                            name:
                              anyOf:
                                - type: string
                                - type: 'null'
                            platform:
                              type: string
                          required:
                            - id
                            - name
                            - platform
                          additionalProperties: false
                    required:
                      - type
                      - devices
                    additionalProperties: false
              platforms:
                type: array
                items:
                  type: string
                  enum:
                    - macos
                    - windows
                    - linux
              initiator:
                description: >-
                  Who triggered the run — a user name, or the name of the API
                  key that called this endpoint.
                anyOf:
                  - type: string
                  - type: 'null'
              statusCounts:
                description: Number of executions in each status.
                type: object
                properties:
                  pending:
                    type: number
                  success:
                    type: number
                  failed:
                    type: number
                  timeout:
                    type: number
                  cancelled:
                    type: number
                required:
                  - pending
                  - success
                  - failed
                  - timeout
                  - cancelled
                additionalProperties: false
              totalExecutions:
                type: number
                description: Number of devices the run resolved to.
              status:
                description: >-
                  Overall state, derived from the executions: `running` while
                  any is still pending.
                type: string
                enum:
                  - running
                  - success
                  - failed
                  - cancelled
              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))$
            required:
              - id
              - script
              - target
              - platforms
              - initiator
              - statusCounts
              - totalExecutions
              - status
              - createdAt
            additionalProperties: false
        pagination:
          type: object
          properties:
            totalElements:
              type: integer
              minimum: 0
              maximum: 9007199254740991
            totalPages:
              type: integer
              minimum: 0
              maximum: 9007199254740991
            page:
              type: integer
              minimum: 1
              maximum: 9007199254740991
            perPage:
              type: integer
              minimum: 1
              maximum: 100
          required:
            - totalElements
            - totalPages
            - page
            - perPage
          additionalProperties: false
      required:
        - data
        - pagination
      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>`.

````