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

# Retrieve workspace compliance statistics

> Get compliance statistics for a workspace.



## OpenAPI

````yaml get /workspaces/{workspaceId}/rule-stats
openapi: 3.0.3
info:
  contact:
    email: support@openlayer.com
    name: Openlayer
    url: https://openlayer.com/
  description: API for interacting with the Openlayer server.
  title: Openlayer API
  version: '1.0'
  x-logo:
    url: https://logo.clearbit.com/openlayer.com
servers:
  - url: https://api.openlayer.com/v1
    description: Our prod backend
security:
  - bearerAuth: []
paths:
  /workspaces/{workspaceId}/rule-stats:
    get:
      tags:
        - Governance
      summary: Retrieve workspace compliance statistics
      description: Get compliance statistics for a workspace.
      operationId: getWorkspaceRuleStats
      parameters:
        - $ref: '#/components/parameters/workspaceId'
        - $ref: '#/components/parameters/frameworkIdFilter'
        - $ref: '#/components/parameters/projectIdFilter'
      responses:
        '200':
          description: Status OK.
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/RuleStatistic'
        default:
          $ref: '#/components/responses/UnexpectedError'
      x-codeSamples:
        - lang: python
          source: |
            from openlayer import Openlayer

            client = Openlayer()

            stats = client.governance.rule_stats.retrieve(
                "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
                framework_id="5e6f7a8b-9c0d-4e1f-8a2b-3c4d5e6f7a8b",
            )
            print(stats.rule_results)
        - lang: typescript
          source: >
            import Openlayer from 'openlayer';


            const client = new Openlayer();


            const ruleStats = await
            client.governance.ruleStats.retrieve('182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e',
            {
              frameworkId: '5e6f7a8b-9c0d-4e1f-8a2b-3c4d5e6f7a8b',
            });


            console.log(ruleStats);
        - lang: go
          source: "package main\n\nimport (\n\t\"context\"\n\t\"fmt\"\n\n\t\"github.com/openlayer-ai/openlayer-go\"\n)\n\nclient := openlayer.NewClient()\nstats, err := client.Governance.RuleStats.Get(\n\tcontext.TODO(),\n\t\"182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e\",\n\topenlayer.GovernanceRuleStatGetParams{\n\t\tFrameworkID: openlayer.F(\"5e6f7a8b-9c0d-4e1f-8a2b-3c4d5e6f7a8b\"),\n\t},\n)\nif err != nil {\n\tpanic(err.Error())\n}\nfmt.Printf(\"%+v\\n\", stats.Rules)\n"
        - lang: java
          source: >
            import com.openlayer.api.client.OpenlayerClient;

            import com.openlayer.api.client.okhttp.OpenlayerOkHttpClient;

            import
            com.openlayer.api.models.governance.rulestats.RuleStatRetrieveParams;

            import
            com.openlayer.api.models.governance.rulestats.RuleStatRetrieveResponse;


            OpenlayerClient client = OpenlayerOkHttpClient.fromEnv();


            RuleStatRetrieveParams params = RuleStatRetrieveParams.builder()
                .workspaceId("182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e")
                .frameworkId("5e6f7a8b-9c0d-4e1f-8a2b-3c4d5e6f7a8b")
                .build();
            RuleStatRetrieveResponse stats =
            client.governance().ruleStats().retrieve(params);
        - lang: ruby
          source: |
            require "openlayer"

            openlayer = Openlayer::Client.new(api_key: ENV["OPENLAYER_API_KEY"])

            rule_stats = openlayer.governance.rule_stats.retrieve(
              "182bd5e5-6e1a-4fe4-a799-aa6d9a6ab26e",
              framework_id: "5e6f7a8b-9c0d-4e1f-8a2b-3c4d5e6f7a8b"
            )

            puts(rule_stats)
        - lang: curl
          source: |
            curl --request GET \
              --url 'https://api.openlayer.com/v1/workspaces/3fa85f64-5717-4562-b3fc-2c963f66afa6/rule-stats?frameworkId=9f1b3c2d-4e5a-4f60-8a71-2b3c4d5e6f70' \
              --header 'Authorization: Bearer <token>'
components:
  parameters:
    workspaceId:
      name: workspaceId
      in: path
      description: The workspace id.
      required: true
      schema:
        type: string
        format: uuid
    frameworkIdFilter:
      name: frameworkId
      in: query
      description: Only include items belonging to this framework.
      required: false
      schema:
        type: string
        format: uuid
    projectIdFilter:
      name: projectId
      in: query
      description: Only include items that apply to this project.
      required: false
      schema:
        type: string
        format: uuid
  schemas:
    RuleStatistic:
      type: object
      description: >
        Counts of rules and their results by status. Narrowed by the request's
        filters, so `frameworkId` gives one framework's compliance and
        `projectId` gives one project's.
      properties:
        rules:
          type: object
          description: Counts of the rules themselves, after any filters in the request.
          properties:
            total:
              type: integer
              minimum: 0
              description: The total number of rules.
            byType:
              type: object
              description: Rule counts by type.
              properties:
                platform:
                  type: integer
                  minimum: 0
                evidence:
                  type: integer
                  minimum: 0
            byScope:
              type: object
              description: Rule counts by scope.
              properties:
                project:
                  type: integer
                  minimum: 0
                workspace:
                  type: integer
                  minimum: 0
        ruleResults:
          description: >
            Counts of rule results, after any filters in the request, with
            breakdowns by the type and scope of the rule each result belongs to.
          allOf:
            - $ref: '#/components/schemas/RuleResultStatusCounts'
            - type: object
              properties:
                byRuleType:
                  type: object
                  properties:
                    platform:
                      $ref: '#/components/schemas/RuleResultStatusCounts'
                    evidence:
                      $ref: '#/components/schemas/RuleResultStatusCounts'
                byRuleScope:
                  type: object
                  properties:
                    project:
                      $ref: '#/components/schemas/RuleResultStatusCounts'
                    workspace:
                      $ref: '#/components/schemas/RuleResultStatusCounts'
      required:
        - rules
        - ruleResults
    RuleResultStatusCounts:
      type: object
      properties:
        total:
          type: integer
          minimum: 0
          description: The total number of rule results.
        totalPassing:
          type: integer
          minimum: 0
          description: The number of passing rule results.
        totalFailing:
          type: integer
          minimum: 0
          description: The number of failing rule results.
        totalSkipped:
          type: integer
          minimum: 0
          description: The number of skipped rule results.
        totalRunning:
          type: integer
          minimum: 0
          description: The number of rule results currently being evaluated.
        totalError:
          type: integer
          minimum: 0
          description: The number of rule results that errored during evaluation.
        totalPending:
          type: integer
          minimum: 0
          description: The number of rule results that have not been satisfied yet.
        totalDueSoon:
          type: integer
          minimum: 0
          description: The number of rule results whose evidence is about to expire.
      required:
        - total
        - totalPassing
        - totalFailing
        - totalSkipped
        - totalRunning
        - totalError
        - totalPending
        - totalDueSoon
  responses:
    UnexpectedError:
      description: Unexpected error.
      content:
        application/json:
          schema:
            type: object
            required:
              - code
              - error
            properties:
              code:
                type: integer
                format: int32
              error:
                type: string
  securitySchemes:
    bearerAuth:
      type: http
      scheme: bearer
      description: >
        Bearer authentication header of the form `Bearer <token>`, where
        `<token>` is your workspace API key. See [Find your API
        key](https://www.openlayer.com/docs/workspace-and-projects/find-your-api-key)
        for more information.

````

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