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

# Get a script run

> Return one script run: the script as executed (including its source), the resolved target, and the count of executions in each status. This is the endpoint to poll after `runScript` to follow progress.

For the per-device outcomes, use `getScriptRunExecutions`.

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/{runId}
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/{runId}:
    get:
      tags:
        - Scripts
      summary: Get a script run
      description: >-
        Return one script run: the script as executed (including its source),
        the resolved target, and the count of executions in each status. This is
        the endpoint to poll after `runScript` to follow progress.


        For the per-device outcomes, use `getScriptRunExecutions`.


        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: getScriptRun
      parameters:
        - name: runId
          required: true
          in: path
          schema:
            type: string
      responses:
        default:
          description: ''
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/GetScriptRun_Output'
components:
  schemas:
    GetScriptRun_Output:
      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))$
        contents:
          type: string
          description: >-
            Full source of the script as executed, kept even if the script later
            changes.
      required:
        - id
        - script
        - target
        - platforms
        - initiator
        - statusCounts
        - totalExecutions
        - status
        - createdAt
        - contents
      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>`.

````