Skip to Content
GraphQL API

Query Spaces and Assets with the Mondoo API

List the spaces in an organization, list and filter the assets in a space, read one asset's risk, and delete assets with the Mondoo GraphQL API.

These recipes read your organization's structure and inventory. Each one is a complete curl command. To run them, set MONDOO_API_TOKEN and install jq as described in Make your first request. If your organization is in the EU region, replace us.api.mondoo.com with eu.api.mondoo.com.

List the spaces in an organization

Use this query to find the MRN of every space in an organization, for example to run another recipe across all of them.

QUERY='
query ListSpaces($orgMrn: String!, $after: String) {
  organization(mrn: $orgMrn) {
    name
    spacesList(first: 50, after: $after) {
      totalCount
      edges {
        node {
          mrn
          name
        }
      }
      pageInfo {
        endCursor
        hasNextPage
      }
    }
  }
}'
VARIABLES='{"orgMrn": "//captain.api.mondoo.app/organizations/YOUR_ORG_ID"}'

curl -s https://us.api.mondoo.com/query \
  -H "Authorization: Bearer $MONDOO_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d "$(jq -n --arg query "$QUERY" --argjson variables "$VARIABLES" '{query: $query, variables: $variables}')" | jq
  • Scope: an organization MRN. Use an organization token.
  • Access: any role that can view the organization, such as Viewer.
  • Pagination: while hasNextPage is true, add "after": "END_CURSOR" to the variables, using the previous page's endCursor. To learn more, read Pagination.

To narrow the list by space name, add query: "TERM" to the spacesList arguments.

List the assets in a space

Use this query to export your inventory or to find the MRNs of the assets you want to work with. This example returns the riskiest assets first, with each asset's platform, risk score, and last update time.

QUERY='
query ListAssets($scopeMrn: String!, $after: String) {
  assets(
    scopeMrn: $scopeMrn
    first: 50
    after: $after
    orderBy: { field: RISK_VALUE, direction: DESC }
  ) {
    totalCount
    edges {
      node {
        mrn
        name
        platform {
          name
          version
        }
        score {
          riskValue
          riskRating
        }
        updatedAt
      }
    }
    pageInfo {
      endCursor
      hasNextPage
    }
  }
}'
VARIABLES='{"scopeMrn": "//captain.api.mondoo.app/spaces/YOUR_SPACE_ID"}'

curl -s https://us.api.mondoo.com/query \
  -H "Authorization: Bearer $MONDOO_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d "$(jq -n --arg query "$QUERY" --argjson variables "$VARIABLES" '{query: $query, variables: $variables}')" | jq
  • Scope: a space MRN.
  • Access: any role that can view the space, such as Viewer.
  • Pagination: while hasNextPage is true, add "after": "END_CURSOR" to the variables, using the previous page's endCursor.

riskValue is the asset's risk score, from 0 (no risk) to 100 (highest risk). riskRating is the matching rating, such as CRITICAL or HIGH.

To narrow the results, add arguments to assets:

  • queryTerms: ["TERM"] matches assets by name, URL, platform name, and labels.
  • platformName: ["ubuntu"] returns only assets on the platforms you list.
  • rating: [CRITICAL, HIGH] returns only assets with the risk ratings you list.

Get one asset's details

Use this query to read the current state of one asset, such as its platform, risk, labels, and annotations. Get the asset's MRN from the assets list.

QUERY='
query GetAsset($mrn: String!) {
  asset(mrn: $mrn) {
    mrn
    name
    asset_type
    platform {
      title
      version
      arch
    }
    score {
      riskValue
      riskRating
    }
    labels {
      key
      value
    }
    annotations {
      key
      value
    }
    createdAt
    updatedAt
  }
}'
VARIABLES='{"mrn": "//assets.api.mondoo.app/spaces/YOUR_SPACE_ID/assets/YOUR_ASSET_ID"}'

curl -s https://us.api.mondoo.com/query \
  -H "Authorization: Bearer $MONDOO_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d "$(jq -n --arg query "$QUERY" --argjson variables "$VARIABLES" '{query: $query, variables: $variables}')" | jq
  • Access: any role that can view the asset's space, such as Viewer.

To list the vulnerabilities and failed checks on the asset, read List the findings on one asset.

Delete assets

Use this mutation to remove assets you no longer need, for example decommissioned machines, as part of an automated cleanup. Get the asset MRNs from the assets list. To remove stale assets on a schedule without calling the API, read Remove Obsolete Assets.

QUERY='
mutation DeleteAssets($input: DeleteAssetsInput!) {
  deleteAssets(input: $input) {
    scopeMrn
    errors
  }
}'
VARIABLES='{
  "input": {
    "scopeMrn": "//captain.api.mondoo.app/spaces/YOUR_SPACE_ID",
    "assetMrns": ["//assets.api.mondoo.app/spaces/YOUR_SPACE_ID/assets/YOUR_ASSET_ID"]
  }
}'

curl -s https://us.api.mondoo.com/query \
  -H "Authorization: Bearer $MONDOO_API_TOKEN" \
  -H "Content-Type: application/json" \
  -d "$(jq -n --arg query "$QUERY" --argjson variables "$VARIABLES" '{query: $query, variables: $variables}')" | jq

If you leave assetMrns empty or omit it, the mutation deletes every asset in the space. Always pass the list of assets you mean to delete.

  • Scope: a space MRN.
  • Access: the Editor or Owner role, or another role with the Asset Manager permission. To see every role, read Roles and permissions.

The errors field in the response lists any asset that Mondoo couldn't delete, with the reason.

Next steps

Last updated on

On this page